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
before · runtime/Cargo.toml
1################################################################################2# Package 34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6build = 'build.rs'7description = 'Substrate node nft'8edition = '2018'9homepage = 'https://unique.network'10license = 'All Rights Reserved'11name = 'nft-runtime'12repository = 'https://github.com/usetech-llc/nft_private/'13version = '3.0.0'1415[package.metadata.docs.rs]16targets = ['x86_64-unknown-linux-gnu']1718[features]19default = ['std']20runtime-benchmarks = [21    'hex-literal',22    'frame-benchmarking',23    'frame-support/runtime-benchmarks',24    'frame-system-benchmarking',25    'frame-system/runtime-benchmarks',26    'pallet-evm-migration/runtime-benchmarks',27    'pallet-balances/runtime-benchmarks',28    'pallet-timestamp/runtime-benchmarks',29    'pallet-nft/runtime-benchmarks',30    'pallet-inflation/runtime-benchmarks',31    'pallet-xcm/runtime-benchmarks',32    'sp-runtime/runtime-benchmarks',33    'xcm-builder/runtime-benchmarks',34]35std = [36    'codec/std',37    'cumulus-pallet-aura-ext/std',38    'cumulus-pallet-parachain-system/std',39    'cumulus-pallet-xcm/std',40    'cumulus-pallet-xcmp-queue/std',41    'cumulus-primitives-core/std',42    'cumulus-primitives-utility/std',43    'frame-executive/std',44    'frame-support/std',45    'frame-system/std',46    'frame-system-rpc-runtime-api/std',47    'pallet-aura/std',48    'pallet-balances/std',49    # 'pallet-contracts/std',50    # 'pallet-contracts-primitives/std',51    # 'pallet-contracts-rpc-runtime-api/std',52    # 'pallet-contract-helpers/std',53    'pallet-randomness-collective-flip/std',54    'pallet-sudo/std',55    'pallet-timestamp/std',56    'pallet-transaction-payment/std',57    'pallet-transaction-payment-rpc-runtime-api/std',58    'pallet-treasury/std',59    'pallet-vesting/std',60    'pallet-evm/std',61    'pallet-evm-migration/std',62    'pallet-evm-contract-helpers/std',63    'pallet-evm-transaction-payment/std',64    'pallet-evm-coder-substrate/std',65    'pallet-ethereum/std',66    'fp-rpc/std',67    'parachain-info/std',68    'serde',69    'pallet-inflation/std',70    'pallet-nft/std',71    'pallet-scheduler/std',72    'pallet-nft-charge-transaction/std',73    'pallet-nft-transaction-payment/std',74    'nft-data-structs/std',75    'sp-api/std',76    'sp-block-builder/std',77    "sp-consensus-aura/std",78    'sp-core/std',79    'sp-inherents/std',80    'sp-io/std',81    'sp-offchain/std',82    'sp-runtime/std',83    'sp-session/std',84    'sp-std/std',85    'sp-transaction-pool/std',86    'sp-version/std',87    'xcm/std',88    'xcm-builder/std',89    'xcm-executor/std',90]91limit-testing = ['pallet-nft/limit-testing', 'nft-data-structs/limit-testing']9293################################################################################94# Substrate Dependencies9596[dependencies.codec]97default-features = false98features = ['derive']99package = 'parity-scale-codec'100version = '2.3.0'101102[dependencies.frame-benchmarking]103default-features = false104git = 'https://github.com/paritytech/substrate.git'105optional = true106branch = 'polkadot-v0.9.10'107version = '4.0.0-dev'108109[dependencies.frame-executive]110default-features = false111git = 'https://github.com/paritytech/substrate.git'112branch = 'polkadot-v0.9.10'113version = '4.0.0-dev'114115[dependencies.frame-support]116default-features = false117git = 'https://github.com/paritytech/substrate.git'118branch = 'polkadot-v0.9.10'119version = '4.0.0-dev'120121[dependencies.frame-system]122default-features = false123git = 'https://github.com/paritytech/substrate.git'124branch = 'polkadot-v0.9.10'125version = '4.0.0-dev'126127[dependencies.frame-system-benchmarking]128default-features = false129git = 'https://github.com/paritytech/substrate.git'130optional = true131branch = 'polkadot-v0.9.10'132version = '4.0.0-dev'133134[dependencies.frame-system-rpc-runtime-api]135default-features = false136git = 'https://github.com/paritytech/substrate.git'137branch = 'polkadot-v0.9.10'138version = '4.0.0-dev'139140[dependencies.hex-literal]141optional = true142version = '0.3.3'143144[dependencies.serde]145default-features = false146features = ['derive']147optional = true148version = '1.0.130'149150[dependencies.pallet-aura]151default-features = false152git = 'https://github.com/paritytech/substrate.git'153branch = 'polkadot-v0.9.10'154version = '4.0.0-dev'155156[dependencies.pallet-balances]157default-features = false158git = 'https://github.com/paritytech/substrate.git'159branch = 'polkadot-v0.9.10'160version = '4.0.0-dev'161162# Contracts specific packages163# [dependencies.pallet-contracts]164# git = 'https://github.com/paritytech/substrate.git'165# default-features = false166# branch = 'polkadot-v0.9.9'167# version = '4.0.0-dev'168169# [dependencies.pallet-contracts-primitives]170# git = 'https://github.com/paritytech/substrate.git'171# default-features = false172# branch = 'polkadot-v0.9.9'173# version = '4.0.0-dev'174175# [dependencies.pallet-contracts-rpc-runtime-api]176# git = 'https://github.com/paritytech/substrate.git'177# default-features = false178# branch = 'polkadot-v0.9.9'179# version = '4.0.0-dev'180181[dependencies.pallet-randomness-collective-flip]182default-features = false183git = 'https://github.com/paritytech/substrate.git'184branch = 'polkadot-v0.9.10'185version = '4.0.0-dev'186187[dependencies.pallet-sudo]188default-features = false189git = 'https://github.com/paritytech/substrate.git'190branch = 'polkadot-v0.9.10'191version = '4.0.0-dev'192193[dependencies.pallet-timestamp]194default-features = false195git = 'https://github.com/paritytech/substrate.git'196branch = 'polkadot-v0.9.10'197version = '4.0.0-dev'198199[dependencies.pallet-transaction-payment]200default-features = false201git = 'https://github.com/paritytech/substrate.git'202branch = 'polkadot-v0.9.10'203version = '4.0.0-dev'204205[dependencies.pallet-transaction-payment-rpc-runtime-api]206default-features = false207git = 'https://github.com/paritytech/substrate.git'208branch = 'polkadot-v0.9.10'209version = '4.0.0-dev'210211[dependencies.pallet-treasury]212default-features = false213git = 'https://github.com/paritytech/substrate.git'214branch = 'polkadot-v0.9.10'215version = '4.0.0-dev'216217[dependencies.pallet-vesting]218default-features = false219git = 'https://github.com/paritytech/substrate.git'220branch = 'polkadot-v0.9.10'221version = '4.0.0-dev'222223[dependencies.sp-arithmetic]224default-features = false225git = 'https://github.com/paritytech/substrate.git'226branch = 'polkadot-v0.9.10'227version = '4.0.0-dev'228229[dependencies.sp-api]230default-features = false231git = 'https://github.com/paritytech/substrate.git'232branch = 'polkadot-v0.9.10'233version = '4.0.0-dev'234235[dependencies.sp-block-builder]236default-features = false237git = 'https://github.com/paritytech/substrate.git'238branch = 'polkadot-v0.9.10'239version = '4.0.0-dev'240241[dependencies.sp-core]242default-features = false243git = 'https://github.com/paritytech/substrate.git'244branch = 'polkadot-v0.9.10'245version = '4.0.0-dev'246247[dependencies.sp-consensus-aura]248default-features = false249git = 'https://github.com/paritytech/substrate.git'250branch = 'polkadot-v0.9.10'251version = '0.10.0-dev'252253[dependencies.sp-inherents]254default-features = false255git = 'https://github.com/paritytech/substrate.git'256branch = 'polkadot-v0.9.10'257version = '4.0.0-dev'258259[dependencies.sp-io]260default-features = false261git = 'https://github.com/paritytech/substrate.git'262branch = 'polkadot-v0.9.10'263version = '4.0.0-dev'264265[dependencies.sp-offchain]266default-features = false267git = 'https://github.com/paritytech/substrate.git'268branch = 'polkadot-v0.9.10'269version = '4.0.0-dev'270271[dependencies.sp-runtime]272default-features = false273git = 'https://github.com/paritytech/substrate.git'274branch = 'polkadot-v0.9.10'275version = '4.0.0-dev'276277[dependencies.sp-session]278default-features = false279git = 'https://github.com/paritytech/substrate.git'280branch = 'polkadot-v0.9.10'281version = '4.0.0-dev'282283[dependencies.sp-std]284default-features = false285git = 'https://github.com/paritytech/substrate.git'286branch = 'polkadot-v0.9.10'287version = '4.0.0-dev'288289[dependencies.sp-transaction-pool]290default-features = false291git = 'https://github.com/paritytech/substrate.git'292branch = 'polkadot-v0.9.10'293version = '4.0.0-dev'294295[dependencies.sp-version]296default-features = false297git = 'https://github.com/paritytech/substrate.git'298branch = 'polkadot-v0.9.10'299version = '4.0.0-dev'300301[dependencies.smallvec]302version = '1.6.1'303304################################################################################305# Cumulus dependencies306307[dependencies.parachain-info]308default-features = false309git = 'https://github.com/paritytech/cumulus.git'310branch = 'polkadot-v0.9.10'311version = '0.1.0'312313[dependencies.cumulus-pallet-aura-ext]314git = 'https://github.com/paritytech/cumulus.git'315branch = 'polkadot-v0.9.10'316default-features = false317318[dependencies.cumulus-pallet-parachain-system]319git = 'https://github.com/paritytech/cumulus.git'320branch = 'polkadot-v0.9.10'321default-features = false322323[dependencies.cumulus-primitives-core]324git = 'https://github.com/paritytech/cumulus.git'325branch = 'polkadot-v0.9.10'326default-features = false327328[dependencies.cumulus-pallet-xcm]329git = 'https://github.com/paritytech/cumulus.git'330branch = 'polkadot-v0.9.10'331default-features = false332333[dependencies.cumulus-pallet-dmp-queue]334git = 'https://github.com/paritytech/cumulus.git'335branch = 'polkadot-v0.9.10'336default-features = false337338[dependencies.cumulus-pallet-xcmp-queue]339git = 'https://github.com/paritytech/cumulus.git'340branch = 'polkadot-v0.9.10'341default-features = false342343[dependencies.cumulus-primitives-utility]344git = 'https://github.com/paritytech/cumulus.git'345branch = 'polkadot-v0.9.10'346default-features = false347348[dependencies.cumulus-primitives-timestamp]349git = 'https://github.com/paritytech/cumulus.git'350branch = 'polkadot-v0.9.10'351default-features = false352353################################################################################354# Polkadot dependencies355356[dependencies.polkadot-parachain]357git = 'https://github.com/paritytech/polkadot'358branch = 'release-v0.9.10'359default-features = false360361[dependencies.xcm]362git = 'https://github.com/paritytech/polkadot'363branch = 'release-v0.9.10'364default-features = false365366[dependencies.xcm-builder]367git = 'https://github.com/paritytech/polkadot'368branch = 'release-v0.9.10'369default-features = false370371[dependencies.xcm-executor]372git = 'https://github.com/paritytech/polkadot'373branch = 'release-v0.9.10'374default-features = false375376[dependencies.pallet-xcm]377git = 'https://github.com/paritytech/polkadot'378branch = 'release-v0.9.10'379default-features = false380381382################################################################################383# local dependencies384385[dependencies]386derivative = "2.2.0"387pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }388pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }389nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }390pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }391# 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' }393pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }394pallet-evm-migration = { path = '../pallets/evm-migration', default-features = false }395pallet-evm-contract-helpers = { path = '../pallets/evm-contract-helpers', default-features = false }396pallet-evm-transaction-payment = { path = '../pallets/evm-transaction-payment', default-features = false }397pallet-evm-coder-substrate = { default-features = false, path = "../pallets/evm-coder-substrate" }398399pallet-evm = { default-features = false, version = "6.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }400pallet-ethereum = { default-features = false, version = "4.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }401fp-rpc = { default-features = false, version = "3.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }402403################################################################################404# Build Dependencies405406[build-dependencies.substrate-wasm-builder]407git = 'https://github.com/paritytech/substrate.git'408branch = 'polkadot-v0.9.10'409version = '5.0.0-dev'
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)
 		}