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
55
6use cumulus_primitives_core::ParaId;6use cumulus_primitives_core::ParaId;
7use nft_runtime::*;7use nft_runtime::*;
8use nft_data_structs::*;
9use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};8use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
10use sc_service::ChainType;9use sc_service::ChainType;
11use sp_core::{sr25519, Pair, Public};10use sp_core::{sr25519, Pair, Public};
176 .map(|k| (k, 1000, 100, 1 << 98))175 .map(|k| (k, 1000, 100, 1 << 98))
177 .collect(),176 .collect(),
178 },177 },
179 nft: NftConfig {
180 collection_id: vec![(
181 1,
182 Collection {
183 owner: get_account_id_from_seed::<sr25519::Public>("Alice"),
184 mode: CollectionMode::NFT,
185 access: AccessMode::Normal,
186 decimal_points: 0,
187 name: vec![],
188 description: vec![],
189 token_prefix: vec![],
190 mint_mode: false,
191 offchain_schema: vec![],
192 schema_version: SchemaVersion::default(),
193 sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<
194 sr25519::Public,
195 >("Alice")),
196 const_on_chain_schema: vec![],
197 variable_on_chain_schema: vec![],
198 limits: CollectionLimits::default(),
199 meta_update_permission: MetaUpdatePermission::ItemOwner,
200 transfers_enabled: true,
201 },
202 )],
203 nft_item_id: vec![],
204 fungible_item_id: vec![],
205 refungible_item_id: vec![],
206 },
207 parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },178 parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },
208 aura: nft_runtime::AuraConfig {179 aura: nft_runtime::AuraConfig {
209 authorities: initial_authorities,180 authorities: initial_authorities,
modifiedruntime/Cargo.tomldiffbeforeafterboth
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -26,6 +26,10 @@
     'pallet-evm-migration/runtime-benchmarks',
     'pallet-balances/runtime-benchmarks',
     'pallet-timestamp/runtime-benchmarks',
+    'pallet-common/runtime-benchmarks',
+    'pallet-fungible/runtime-benchmarks',
+    'pallet-refungible/runtime-benchmarks',
+    'pallet-nonfungible/runtime-benchmarks',
     'pallet-nft/runtime-benchmarks',
     'pallet-inflation/runtime-benchmarks',
     'pallet-xcm/runtime-benchmarks',
@@ -67,6 +71,10 @@
     'parachain-info/std',
     'serde',
     'pallet-inflation/std',
+    'pallet-common/std',
+    'pallet-fungible/std',
+    'pallet-refungible/std',
+    'pallet-nonfungible/std',
     'pallet-nft/std',
     'pallet-scheduler/std',
     'pallet-nft-charge-transaction/std',
@@ -163,19 +171,19 @@
 # [dependencies.pallet-contracts]
 # git = 'https://github.com/paritytech/substrate.git'
 # default-features = false
-# branch = 'polkadot-v0.9.9'
+# branch = 'polkadot-v0.9.10'
 # version = '4.0.0-dev'
 
 # [dependencies.pallet-contracts-primitives]
 # git = 'https://github.com/paritytech/substrate.git'
 # default-features = false
-# branch = 'polkadot-v0.9.9'
+# branch = 'polkadot-v0.9.10'
 # version = '4.0.0-dev'
 
 # [dependencies.pallet-contracts-rpc-runtime-api]
 # git = 'https://github.com/paritytech/substrate.git'
 # default-features = false
-# branch = 'polkadot-v0.9.9'
+# branch = 'polkadot-v0.9.10'
 # version = '4.0.0-dev'
 
 [dependencies.pallet-randomness-collective-flip]
@@ -385,9 +393,14 @@
 [dependencies]
 derivative = "2.2.0"
 pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }
+up-rpc = { path = "../primitives/rpc", default-features = false }
 pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }
 nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }
 pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }
+pallet-common = { default-features = false, path = "../pallets/common" }
+pallet-fungible = { default-features = false, path = "../pallets/fungible" }
+pallet-refungible = { default-features = false, path = "../pallets/refungible" }
+pallet-nonfungible = { default-features = false, path = "../pallets/nonfungible" }
 # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
 pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }
 pallet-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)
 		}