git.delta.rocks / unique-network / refs/commits / 9c7fc18e6abe

difftreelog

feat connect split pallets via runtime

Yaroslav Bolyukin2021-10-12parent: #b70e369.patch.diff
in: master

3 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -5,7 +5,6 @@
 
 use cumulus_primitives_core::ParaId;
 use nft_runtime::*;
-use nft_data_structs::*;
 use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
 use sc_service::ChainType;
 use sp_core::{sr25519, Pair, Public};
@@ -175,34 +174,6 @@
 				.cloned()
 				.map(|k| (k, 1000, 100, 1 << 98))
 				.collect(),
-		},
-		nft: NftConfig {
-			collection_id: vec![(
-				1,
-				Collection {
-					owner: get_account_id_from_seed::<sr25519::Public>("Alice"),
-					mode: CollectionMode::NFT,
-					access: AccessMode::Normal,
-					decimal_points: 0,
-					name: vec![],
-					description: vec![],
-					token_prefix: vec![],
-					mint_mode: false,
-					offchain_schema: vec![],
-					schema_version: SchemaVersion::default(),
-					sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<
-						sr25519::Public,
-					>("Alice")),
-					const_on_chain_schema: vec![],
-					variable_on_chain_schema: vec![],
-					limits: CollectionLimits::default(),
-					meta_update_permission: MetaUpdatePermission::ItemOwner,
-					transfers_enabled: true,
-				},
-			)],
-			nft_item_id: vec![],
-			fungible_item_id: vec![],
-			refungible_item_id: vec![],
 		},
 		parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },
 		aura: nft_runtime::AuraConfig {
modifiedruntime/Cargo.tomldiffbeforeafterboth
26 'pallet-evm-migration/runtime-benchmarks',26 'pallet-evm-migration/runtime-benchmarks',
27 'pallet-balances/runtime-benchmarks',27 'pallet-balances/runtime-benchmarks',
28 'pallet-timestamp/runtime-benchmarks',28 'pallet-timestamp/runtime-benchmarks',
29 'pallet-common/runtime-benchmarks',
30 'pallet-fungible/runtime-benchmarks',
31 'pallet-refungible/runtime-benchmarks',
32 'pallet-nonfungible/runtime-benchmarks',
29 'pallet-nft/runtime-benchmarks',33 'pallet-nft/runtime-benchmarks',
30 'pallet-inflation/runtime-benchmarks',34 'pallet-inflation/runtime-benchmarks',
31 'pallet-xcm/runtime-benchmarks',35 'pallet-xcm/runtime-benchmarks',
67 'parachain-info/std',71 'parachain-info/std',
68 'serde',72 'serde',
69 'pallet-inflation/std',73 'pallet-inflation/std',
74 'pallet-common/std',
75 'pallet-fungible/std',
76 'pallet-refungible/std',
77 'pallet-nonfungible/std',
70 'pallet-nft/std',78 'pallet-nft/std',
71 'pallet-scheduler/std',79 'pallet-scheduler/std',
72 'pallet-nft-charge-transaction/std',80 'pallet-nft-charge-transaction/std',
163# [dependencies.pallet-contracts]171# [dependencies.pallet-contracts]
164# git = 'https://github.com/paritytech/substrate.git'172# git = 'https://github.com/paritytech/substrate.git'
165# default-features = false173# default-features = false
166# branch = 'polkadot-v0.9.9'174# branch = 'polkadot-v0.9.10'
167# version = '4.0.0-dev'175# version = '4.0.0-dev'
168176
169# [dependencies.pallet-contracts-primitives]177# [dependencies.pallet-contracts-primitives]
170# git = 'https://github.com/paritytech/substrate.git'178# git = 'https://github.com/paritytech/substrate.git'
171# default-features = false179# default-features = false
172# branch = 'polkadot-v0.9.9'180# branch = 'polkadot-v0.9.10'
173# version = '4.0.0-dev'181# version = '4.0.0-dev'
174182
175# [dependencies.pallet-contracts-rpc-runtime-api]183# [dependencies.pallet-contracts-rpc-runtime-api]
176# git = 'https://github.com/paritytech/substrate.git'184# git = 'https://github.com/paritytech/substrate.git'
177# default-features = false185# default-features = false
178# branch = 'polkadot-v0.9.9'186# branch = 'polkadot-v0.9.10'
179# version = '4.0.0-dev'187# version = '4.0.0-dev'
180188
181[dependencies.pallet-randomness-collective-flip]189[dependencies.pallet-randomness-collective-flip]
385[dependencies]393[dependencies]
386derivative = "2.2.0"394derivative = "2.2.0"
387pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }395pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }
396up-rpc = { path = "../primitives/rpc", default-features = false }
388pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }397pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }
389nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }398nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }
390pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }399pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }
400pallet-common = { default-features = false, path = "../pallets/common" }
401pallet-fungible = { default-features = false, path = "../pallets/fungible" }
402pallet-refungible = { default-features = false, path = "../pallets/refungible" }
403pallet-nonfungible = { default-features = false, path = "../pallets/nonfungible" }
391# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }404# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
392pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }405pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }
393pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }406pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -102,6 +102,8 @@
 /// to the public key of our transaction signing scheme.
 pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
 
+pub type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
+
 /// The type for looking up accounts. We don't expect more than 4 billion of them, but you
 /// never know...
 pub type AccountIndex = u32;
@@ -701,20 +703,32 @@
 	pub const CollectionCreationPrice: Balance = 100 * UNIQUE;
 }
 
-/// Used for the pallet nft in `./nft.rs`
-impl pallet_nft::Config for Runtime {
+impl pallet_common::Config for Runtime {
 	type Event = Event;
-	type WeightInfo = pallet_nft::weights::SubstrateWeight<Self>;
-
-	type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;
+	type EvmBackwardsAddressMapping = pallet_common::account::MapBackwardsAddressTruncated;
 	type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
-	type CrossAccountId = pallet_nft::BasicCrossAccountId<Self>;
+	type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;
 
 	type Currency = Balances;
 	type CollectionCreationPrice = CollectionCreationPrice;
 	type TreasuryAccountId = TreasuryAccountId;
 }
 
+impl pallet_fungible::Config for Runtime {
+	type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;
+}
+impl pallet_refungible::Config for Runtime {
+	type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;
+}
+impl pallet_nonfungible::Config for Runtime {
+	type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
+}
+
+/// Used for the pallet nft in `./nft.rs`
+impl pallet_nft::Config for Runtime {
+	type WeightInfo = pallet_nft::weights::SubstrateWeight<Self>;
+}
+
 parameter_types! {
 	pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
 }
@@ -820,11 +834,15 @@
 
 		// Unique Pallets
 		Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
-		Nft: pallet_nft::{Pallet, Call, Config<T>, Storage, Event<T>} = 61,
+		Nft: pallet_nft::{Pallet, Call, Storage} = 61,
 		Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 62,
 		NftPayment: pallet_nft_transaction_payment::{Pallet, Call, Storage} = 63,
 		Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage } = 64,
 		// ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,
+		Common: pallet_common::{Pallet, Storage, Event<T>} = 66,
+		Fungible: pallet_fungible::{Pallet, Storage} = 67,
+		Refungible: pallet_refungible::{Pallet, Storage} = 68,
+		Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
 
 		// Frontier
 		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
@@ -901,10 +919,56 @@
 	}
 }
 
+macro_rules! dispatch_nft_runtime {
+	($collection:ident.$method:ident($($name:ident),*)) => {{
+		use pallet_nft::dispatch::Dispatched;
+
+		let collection = Dispatched::dispatch(<pallet_common::CollectionHandle<Runtime>>::new($collection).unwrap());
+		let dispatch = collection.as_dyn();
+
+		dispatch.$method($($name),*)
+	}};
+}
+
 impl_runtime_apis! {
-	impl pallet_nft::NftApi<Block>
+	impl up_rpc::NftApi<Block, CrossAccountId, AccountId>
 		for Runtime
 	{
+		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId> {
+			dispatch_nft_runtime!(collection.account_tokens(account))
+		}
+		fn token_exists(collection: CollectionId, token: TokenId) -> bool {
+			dispatch_nft_runtime!(collection.token_exists(token))
+		}
+
+		fn token_owner(collection: CollectionId, token: TokenId) -> CrossAccountId {
+			dispatch_nft_runtime!(collection.token_owner(token))
+		}
+		fn const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {
+			dispatch_nft_runtime!(collection.const_metadata(token))
+		}
+		fn variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8> {
+			dispatch_nft_runtime!(collection.variable_metadata(token))
+		}
+
+		fn collection_tokens(collection: CollectionId) -> u32 {
+			dispatch_nft_runtime!(collection.collection_tokens())
+		}
+		fn account_balance(collection: CollectionId, account: CrossAccountId) -> u32 {
+			dispatch_nft_runtime!(collection.account_balance(account))
+		}
+		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> u128 {
+			dispatch_nft_runtime!(collection.balance(account, token))
+		}
+		fn allowance(
+			collection: CollectionId,
+			sender: CrossAccountId,
+			spender: CrossAccountId,
+			token: TokenId,
+		) -> u128 {
+			dispatch_nft_runtime!(collection.allowance(sender, spender, token))
+		}
+
 		fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
 			<pallet_nft::NftErcSupport<Runtime>>::get_code(&account)
 		}