From 9c7fc18e6abea897d0b9cb6260cf60503085aef2 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 12 Oct 2021 16:56:21 +0000 Subject: [PATCH] feat: connect split pallets via runtime --- --- 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::("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 { --- 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' } --- 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 = <::Signer as IdentifyAccount>::AccountId; +pub type CrossAccountId = pallet_common::account::BasicCrossAccountId; + /// 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; - - type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated; + type EvmBackwardsAddressMapping = pallet_common::account::MapBackwardsAddressTruncated; type EvmAddressMapping = HashedAddressMapping; - type CrossAccountId = pallet_nft::BasicCrossAccountId; + type CrossAccountId = pallet_common::account::BasicCrossAccountId; type Currency = Balances; type CollectionCreationPrice = CollectionCreationPrice; type TreasuryAccountId = TreasuryAccountId; } +impl pallet_fungible::Config for Runtime { + type WeightInfo = pallet_fungible::weights::SubstrateWeight; +} +impl pallet_refungible::Config for Runtime { + type WeightInfo = pallet_refungible::weights::SubstrateWeight; +} +impl pallet_nonfungible::Config for Runtime { + type WeightInfo = pallet_nonfungible::weights::SubstrateWeight; +} + +/// Used for the pallet nft in `./nft.rs` +impl pallet_nft::Config for Runtime { + type WeightInfo = pallet_nft::weights::SubstrateWeight; +} + 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, Storage, Event} = 61, + Nft: pallet_nft::{Pallet, Call, Storage} = 61, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 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} = 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} = 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(>::new($collection).unwrap()); + let dispatch = collection.as_dyn(); + + dispatch.$method($($name),*) + }}; +} + impl_runtime_apis! { - impl pallet_nft::NftApi + impl up_rpc::NftApi for Runtime { + fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec { + 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 { + dispatch_nft_runtime!(collection.const_metadata(token)) + } + fn variable_metadata(collection: CollectionId, token: TokenId) -> Vec { + 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> { >::get_code(&account) } -- gitstuff