Skip to content

Commit

Permalink
Merge pull request bit-country#299 from justinphamnz/feature/enable-w…
Browse files Browse the repository at this point in the history
…allet-on-nft

Proxy NFT feature
  • Loading branch information
justinphamnz authored Dec 27, 2023
2 parents 114b332 + fdea11e commit 2a321ca
Show file tree
Hide file tree
Showing 20 changed files with 636 additions and 313 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pallets/auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ frame-executive = { workspace = true }
sp-core = { workspace = true }
sp-version = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
pallet-proxy = { workspace = true }

# Used for the node's RPCs
frame-system-rpc-runtime-api = { workspace = true }
Expand Down Expand Up @@ -76,4 +77,5 @@ std = [
'core-primitives/std',
'frame-benchmarking/std',
'pallet-scheduler/std',
'pallet-proxy/std',
]
56 changes: 53 additions & 3 deletions pallets/auction/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![cfg(test)]

use frame_support::traits::{EqualPrivilegeOnly, Nothing};
use frame_support::traits::{Contains, EqualPrivilegeOnly, InstanceFilter, Nothing};
use frame_support::{construct_runtime, pallet_prelude::Hooks, parameter_types, PalletId};
use frame_system::Call as SystemCall;
use frame_system::EnsureRoot;
use orml_traits::parameter_type_with_key;
use sp_core::crypto::AccountId32;
use sp_core::H256;
use sp_runtime::traits::{AccountIdConversion, IdentifyAccount, Verify};
use sp_core::{ConstU128, H256};
use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, Verify};
use sp_runtime::{testing::Header, traits::IdentityLookup, MultiSignature, Perbill};

use auction_manager::{CheckAuctionItemHandler, ListingLevel};
Expand Down Expand Up @@ -409,6 +410,54 @@ impl orml_nft::Config for Runtime {
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub enum ProxyType {
Any,
JustTransfer,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::JustTransfer => matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. })),
}
}
fn is_superset(&self, o: &Self) -> bool {
self == &ProxyType::Any || self == o
}
}
pub struct BaseFilter;
impl Contains<RuntimeCall> for BaseFilter {
fn contains(c: &RuntimeCall) -> bool {
match *c {
// Remark is used as a no-op call in the benchmarking
RuntimeCall::System(SystemCall::remark { .. }) => true,
RuntimeCall::System(_) => false,
_ => true,
}
}
}

impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyDepositBase = ConstU128<1>;
type ProxyDepositFactor = ConstU128<1>;
type MaxProxies = ConstU32<4>;
type WeightInfo = ();
type CallHasher = BlakeTwo256;
type MaxPending = ConstU32<2>;
type AnnouncementDepositBase = ConstU128<1>;
type AnnouncementDepositFactor = ConstU128<1>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand All @@ -423,6 +472,7 @@ construct_runtime!(
NFTModule: pallet_nft::{Pallet, Storage ,Call, Event<T>},
OrmlNft: orml_nft::{Pallet, Storage, Config<T>},
AuctionModule: auction::{Pallet, Call, Storage, Event<T>},
Proxy: pallet_proxy
}
);
pub struct ExtBuilder;
Expand Down
4 changes: 3 additions & 1 deletion pallets/economy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pallet-randomness-collective-flip = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-proxy = { workspace = true }
sp-io = { workspace = true }
sp-core = { workspace = true }
sp-session = { workspace = true }
Expand Down Expand Up @@ -69,5 +70,6 @@ std = [
"frame-benchmarking/std",
"currencies/std",
"auction-manager/std",
"pallet-mining/std"
"pallet-mining/std",
"pallet-proxy/std"
]
57 changes: 53 additions & 4 deletions pallets/economy/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![cfg(test)]

use frame_support::traits::Nothing;
use frame_support::traits::{Contains, InstanceFilter, Nothing};
use frame_support::{construct_runtime, ord_parameter_types, parameter_types, PalletId};
use frame_system::Call as SystemCall;
use frame_system::EnsureSignedBy;

use orml_traits::parameter_type_with_key;
use sp_core::crypto::AccountId32;
use sp_core::H256;
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_core::{ConstU128, H256};
use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, Verify};
use sp_runtime::{testing::Header, traits::IdentityLookup, MultiSignature, Perbill};

use auction_manager::*;
Expand Down Expand Up @@ -398,6 +398,54 @@ impl orml_nft::Config for Runtime {
type MaxTokenMetadata = MaxTokenMetadata;
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub enum ProxyType {
Any,
JustTransfer,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::JustTransfer => matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. })),
}
}
fn is_superset(&self, o: &Self) -> bool {
self == &ProxyType::Any || self == o
}
}
pub struct BaseFilter;
impl Contains<RuntimeCall> for BaseFilter {
fn contains(c: &RuntimeCall) -> bool {
match *c {
// Remark is used as a no-op call in the benchmarking
RuntimeCall::System(SystemCall::remark { .. }) => true,
RuntimeCall::System(_) => false,
_ => true,
}
}
}

impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyDepositBase = ConstU128<1>;
type ProxyDepositFactor = ConstU128<1>;
type MaxProxies = ConstU32<4>;
type WeightInfo = ();
type CallHasher = BlakeTwo256;
type MaxPending = ConstU32<2>;
type AnnouncementDepositBase = ConstU128<1>;
type AnnouncementDepositFactor = ConstU128<1>;
}

pub type EconomyModule = Pallet<Runtime>;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
Expand All @@ -417,6 +465,7 @@ construct_runtime!(
Economy: economy::{Pallet, Call ,Storage, Event<T>},
OrmlNft: orml_nft::{Pallet, Storage, Config<T>},
NFTModule: pallet_nft::{Pallet, Storage ,Call, Event<T>},
Proxy: pallet_proxy
}
);

Expand Down
2 changes: 2 additions & 0 deletions pallets/nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ orml-nft = { workspace = true }
orml-tokens = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-scheduler = { workspace = true, optional = true }
pallet-proxy = { workspace = true }

sp-core = { workspace = true }
pallet-balances = { workspace = true }
Expand Down Expand Up @@ -57,6 +58,7 @@ std = [
'orml-nft/std',
'pallet-balances/std',
'pallet-timestamp/std',
'pallet-proxy/std',
'auction-manager/std',
'currencies/std',
'scale-info/std',
Expand Down
Loading

0 comments on commit 2a321ca

Please sign in to comment.