From a3925b4c1f8ff4d30bc89924a848977300ea53e1 Mon Sep 17 00:00:00 2001 From: Dusan Morhac <55763425+dudo50@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:33:27 +0200 Subject: [PATCH] Finish refactoring --- Cargo.lock | 4 - templates/parachain/pallets/xcnft/Cargo.toml | 2 - templates/parachain/pallets/xcnft/src/lib.rs | 45 ++-- .../parachain/pallets/xcnft/src/mock/mod.rs | 31 ++- .../pallets/xcnft/src/mock/parachain.rs | 5 +- .../pallets/xcnft/src/mock/relaychain.rs | 45 ++-- .../parachain/pallets/xcnft/src/tests.rs | 22 -- templates/parachain/runtime/Cargo.toml | 2 - .../parachain/runtime/src/configs/mod.rs | 19 -- templates/parachain/runtime/src/lib.rs | 3 - .../parachain_two/pallets/xcnft/Cargo.toml | 2 - .../parachain_two/pallets/xcnft/README.md | 61 +---- .../parachain_two/pallets/xcnft/src/lib.rs | 217 ++++++++++-------- .../pallets/xcnft/src/mock/mod.rs | 31 ++- .../pallets/xcnft/src/mock/parachain.rs | 5 +- .../pallets/xcnft/src/mock/relaychain.rs | 45 ++-- .../parachain_two/pallets/xcnft/src/tests.rs | 1 + .../pallets/xcnft/src/xmacros.rs | 2 +- templates/parachain_two/runtime/Cargo.toml | 3 - .../parachain_two/runtime/src/configs/mod.rs | 30 --- templates/parachain_two/runtime/src/lib.rs | 5 +- 21 files changed, 220 insertions(+), 360 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7aad09b1fa3e..c2e64fb9daab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11396,7 +11396,6 @@ dependencies = [ "frame-system", "pallet-balances", "pallet-nfts", - "pallet-uniques", "parity-scale-codec", "scale-info", "serde", @@ -11419,7 +11418,6 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", - "pallet-nfts", "pallet-uniques", "parity-scale-codec", "scale-info", @@ -12438,7 +12436,6 @@ dependencies = [ "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pallet-uniques", "pallet-xcm", "parachains-common", "parity-scale-codec", @@ -12494,7 +12491,6 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-message-queue", - "pallet-nfts", "pallet-parachain-template-two", "pallet-parachain-xcnft-two", "pallet-session", diff --git a/templates/parachain/pallets/xcnft/Cargo.toml b/templates/parachain/pallets/xcnft/Cargo.toml index 9d89ce2adf7e..b01d374ddae7 100644 --- a/templates/parachain/pallets/xcnft/Cargo.toml +++ b/templates/parachain/pallets/xcnft/Cargo.toml @@ -36,7 +36,6 @@ parachain-info = { workspace = true } sp-runtime = { workspace = true } sp-std = {workspace = true} -pallet-uniques = { workspace = true, default-features = false } pallet-nfts = {workspace=true, default-features = false} [dev-dependencies] @@ -59,7 +58,6 @@ runtime-benchmarks = [ std = [ "codec/std", "scale-info/std", - "pallet-uniques/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", diff --git a/templates/parachain/pallets/xcnft/src/lib.rs b/templates/parachain/pallets/xcnft/src/lib.rs index 8d234b47f25c..8f600f4eaf5c 100644 --- a/templates/parachain/pallets/xcnft/src/lib.rs +++ b/templates/parachain/pallets/xcnft/src/lib.rs @@ -81,7 +81,7 @@ pub mod pallet { traits::Incrementable, }; use frame_system::pallet_prelude::*; - use pallet_nfts::{CollectionConfigFor, CollectionSettings, MintSettings, DestroyWitness}; + use pallet_nfts::{CollectionConfigFor, CollectionSettings, DestroyWitness, MintSettings}; use scale_info::prelude::vec; use sp_runtime::{traits::StaticLookup, DispatchError, DispatchErrorWithPostInfo}; use sp_std::prelude::*; @@ -116,7 +116,8 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData<(T, I)>); - /// Add description!!!! + /// Following structure provides generalized version of DestroyWitness parameter that has + /// different composition in each nft pallet (pallet_uniques || pallet_nfts) #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Default, Debug)] #[scale_info(skip_type_params(T, I))] pub struct GeneralizedDestroyWitness { @@ -1141,7 +1142,9 @@ pub mod pallet { origin_para: parachain_info::Pallet::::parachain_id(), collection_metadata: collection_metadata.unwrap(), nfts: nft_metadata.clone(), - dest_collection_id: proposal.proposed_dest_collection_id.clone(), + dest_collection_id: proposal + .proposed_dest_collection_id + .clone(), }, ) .encode() @@ -1961,7 +1964,7 @@ pub mod pallet { pub fn parse_collection_empty( origin: OriginFor, origin_collection: T::CollectionId, - destination_collection: Option, + _destination_collection: Option, collection_metadata: BoundedVec, config: Option>, ) -> DispatchResultWithPostInfo { @@ -1978,7 +1981,8 @@ pub mod pallet { // Create default configfor collection let def_config = CollectionConfigFor:: { settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, // No maximum supply defined initially + max_supply: None, /* No maximum supply defined + * initially */ mint_settings: MintSettings::default(), // Use default mint settings }; @@ -1993,8 +1997,7 @@ pub mod pallet { Self::deposit_event(Event::CollectionMintFailed { error: e }); }, } - } - else{ + } else { match pallet_nfts::Pallet::::create( origin.clone(), signed_origin_lookup.clone(), @@ -2005,14 +2008,14 @@ pub mod pallet { // Deposit event indicating failure to create collection Self::deposit_event(Event::CollectionMintFailed { error: e }); }, - } + } } let mut user_collection = next_collection_id.clone(); // just to be sure, check if user is collection owner if pallet_nfts::Pallet::::collection_owner(next_collection_id.clone()).unwrap() != - signed_origin.clone() + signed_origin.clone() { //Get current next_collection_id let current_next_collection_id = pallet_nfts::NextCollectionId::::get() @@ -2022,7 +2025,7 @@ pub mod pallet { // collection that is owned by the user while next_collection_id != current_next_collection_id { if pallet_nfts::Pallet::::collection_owner(next_collection_id).unwrap() == - signed_origin.clone() + signed_origin.clone() { // We have users collection user_collection = next_collection_id.clone(); @@ -2077,7 +2080,7 @@ pub mod pallet { let signed_origin = ensure_signed(origin.clone())?; let signed_origin_lookup = T::Lookup::unlookup(signed_origin.clone()); - let destroy_witness = DestroyWitness{ + let destroy_witness = DestroyWitness { item_metadatas: witness_data.item_meta.clone(), item_configs: witness_data.item_configs.clone(), attributes: witness_data.attributes.clone(), @@ -2456,7 +2459,7 @@ pub mod pallet { nfts: Vec<(T::ItemId, BoundedVec)>, origin_para: ParaId, origin_collection_id: T::CollectionId, - dest_collection_id: Option + _dest_collection_id: Option, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin.clone())?; let signed_origin_lookup = T::Lookup::unlookup(who.clone()); @@ -2471,7 +2474,8 @@ pub mod pallet { // Create default configfor collection let def_config = CollectionConfigFor:: { settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, // No maximum supply defined initially + max_supply: None, /* No maximum supply defined + * initially */ mint_settings: MintSettings::default(), // Use default mint settings }; @@ -2486,8 +2490,7 @@ pub mod pallet { Self::deposit_event(Event::CollectionMintFailed { error: e }); }, } - } - else{ + } else { match pallet_nfts::Pallet::::create( origin.clone(), signed_origin_lookup.clone(), @@ -2498,7 +2501,7 @@ pub mod pallet { // Deposit event indicating failure to create collection Self::deposit_event(Event::CollectionMintFailed { error: e }); }, - } + } } let mut user_collection = next_collection_id.clone(); @@ -2631,7 +2634,7 @@ pub mod pallet { nfts: Vec<(T::ItemId, AccountIdLookupOf, BoundedVec)>, origin_para: ParaId, origin_collection_id: T::CollectionId, - dest_collection_id: Option, + _dest_collection_id: Option, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin.clone())?; let signed_origin_lookup = T::Lookup::unlookup(who.clone()); @@ -2646,7 +2649,8 @@ pub mod pallet { // Create default configfor collection let def_config = CollectionConfigFor:: { settings: CollectionSettings::all_enabled(), // Default settings (all enabled) - max_supply: None, // No maximum supply defined initially + max_supply: None, /* No maximum supply defined + * initially */ mint_settings: MintSettings::default(), // Use default mint settings }; @@ -2661,8 +2665,7 @@ pub mod pallet { Self::deposit_event(Event::CollectionMintFailed { error: e }); }, } - } - else{ + } else { match pallet_nfts::Pallet::::create( origin.clone(), signed_origin_lookup.clone(), @@ -2673,7 +2676,7 @@ pub mod pallet { // Deposit event indicating failure to create collection Self::deposit_event(Event::CollectionMintFailed { error: e }); }, - } + } } let mut user_collection = next_collection_id.clone(); diff --git a/templates/parachain/pallets/xcnft/src/mock/mod.rs b/templates/parachain/pallets/xcnft/src/mock/mod.rs index 8de6345403b9..e25e77b394e1 100644 --- a/templates/parachain/pallets/xcnft/src/mock/mod.rs +++ b/templates/parachain/pallets/xcnft/src/mock/mod.rs @@ -2,12 +2,12 @@ use super::*; use sp_io::TestExternalities; -use sp_runtime::{AccountId32}; +use sp_runtime::AccountId32; mod parachain; mod relaychain; use crate as xnft; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; use sp_runtime::BuildStorage; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); @@ -81,31 +81,26 @@ pub fn para_teleport_ext(para_id: u32) -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let parachain_info_config = parachain_info::GenesisConfig:: { - _config: Default::default(), - parachain_id: para_id.into(), - }; - parachain_info_config.assimilate_storage(&mut t).unwrap(); + let parachain_info_config = parachain_info::GenesisConfig:: { + _config: Default::default(), + parachain_id: para_id.into(), + }; + parachain_info_config.assimilate_storage(&mut t).unwrap(); let mut ext = TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext } - pub fn relay_ext() -> sp_io::TestExternalities { - use relaychain::{Test, System}; + use relaychain::{System, Test}; - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, 1_000)], - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, 1_000)] } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/mock/parachain.rs b/templates/parachain/pallets/xcnft/src/mock/parachain.rs index c235317f6686..92cf0c836157 100644 --- a/templates/parachain/pallets/xcnft/src/mock/parachain.rs +++ b/templates/parachain/pallets/xcnft/src/mock/parachain.rs @@ -23,8 +23,8 @@ pub use sp_runtime::{ }; use crate::test::parachain::currency::DOLLARS; -use sp_runtime::BuildStorage; use sp_core::{H256, U256}; +use sp_runtime::BuildStorage; pub type CollectionId = u64; type Origin = ::RuntimeOrigin; @@ -290,7 +290,6 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); - } pub struct ChannelInfo; @@ -408,4 +407,4 @@ impl ExtBuilder { let storage = frame_system::GenesisConfig::::default().build_storage().unwrap(); storage.into() } -} \ No newline at end of file +} diff --git a/templates/parachain/pallets/xcnft/src/mock/relaychain.rs b/templates/parachain/pallets/xcnft/src/mock/relaychain.rs index a6ef38deb467..24f70dace738 100644 --- a/templates/parachain/pallets/xcnft/src/mock/relaychain.rs +++ b/templates/parachain/pallets/xcnft/src/mock/relaychain.rs @@ -1,41 +1,38 @@ - #![cfg(test)] use crate::{ self as pallet_parachain_xcnft, - test::relay::currency::{CENTS, MILLICENTS}, + test::{ + relay::currency::{CENTS, MILLICENTS}, + *, + }, }; use cumulus_primitives_core::relay_chain::CandidateHash; -use frame_support::{assert_ok, traits::AsEnsureOriginWithArg}; -use polkadot_runtime_common::{ - paras_sudo_wrapper, - xcm_sender::{ChildParachainRouter, ExponentialPrice}, -}; -use sp_runtime::BuildStorage; -use crate::test::*; use frame_support::{ - construct_runtime, + assert_ok, construct_runtime, dispatch::DispatchClass, pallet_prelude::{DispatchResult, Get}, parameter_types, traits::{ - ConstU128, ConstU16, ConstU32, ConstU64, Currency, Everything, GenesisBuild, Nothing, - ProcessMessage, ProcessMessageError, + AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Currency, Everything, + GenesisBuild, KeyOwnerProofSystem, Nothing, ProcessMessage, ProcessMessageError, }, weights::{constants::RocksDbWeight, IdentityFee, Weight, WeightMeter}, - }; -use frame_support::traits::KeyOwnerProofSystem; use polkadot_parachain::primitives::ValidationCode; -use sp_runtime::traits::AccountIdConversion; +use polkadot_runtime_common::{ + paras_sudo_wrapper, + xcm_sender::{ChildParachainRouter, ExponentialPrice}, +}; +use sp_runtime::{traits::AccountIdConversion, BuildStorage}; use crate::test::relay::currency::DOLLARS; use cumulus_primitives_core::{ relay_chain::{AuthorityDiscoveryId, SessionIndex, ValidatorIndex}, ChannelStatus, GetChannelInfo, ParaId, }; -use polkadot_runtime_parachains::disputes::SlashingHandler; use frame_support::traits::ValidatorSetWithIdentification; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; +use polkadot_runtime_parachains::disputes::SlashingHandler; use sp_runtime::{transaction_validity::TransactionPriority, Permill}; use std::{cell::RefCell, collections::HashMap}; pub mod currency { @@ -66,15 +63,18 @@ use xcm_builder::{EnsureXcmOrigin, NativeAsset}; use pallet_nfts::PalletFeatures; pub use polkadot_runtime_parachains::{ - configuration, - inclusion::{AggregateMessageOrigin, UmpQueueId}, - origin, shared,disputes, inclusion, paras, scheduler, session_info, assigner, assigner_parachains, assigner_on_demand,hrmp, - dmp as parachains_dmp, paras::ParaGenesisArgs, schedule_para_initialize, + assigner, assigner_on_demand, assigner_parachains, configuration, disputes, disputes::slashing as parachains_slashing, + dmp as parachains_dmp, hrmp, inclusion, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, paras, + paras::ParaGenesisArgs, + schedule_para_initialize, scheduler, session_info, shared, }; use primitives::ValidatorId; pub type BlockNumber = u64; pub type Index = u32; +use sp_runtime::KeyTypeId; use xcm::v3::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, @@ -83,7 +83,6 @@ use xcm_builder::{ TakeWeightCredit, UsingComponents, }; use xcm_executor::XcmExecutor; -use sp_runtime::KeyTypeId; type Origin = ::RuntimeOrigin; use crate::Config; @@ -397,7 +396,6 @@ impl SlashingHandler for Test { fn initializer_on_new_session(_: SessionIndex) {} } - impl disputes::Config for Test { type RuntimeEvent = RuntimeEvent; type RewardValidators = Self; @@ -437,7 +435,6 @@ impl disputes::RewardValidators for Test { } } - thread_local! { pub static DISCOVERY_AUTHORITIES: RefCell> = RefCell::new(Vec::new()); } @@ -565,7 +562,6 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); - } pub type LocalOriginToLocation = SignedToAccountId32; @@ -669,7 +665,6 @@ pub fn new_test_ext(state: MockGenesisConfig) -> sp_io::TestExternalities { state.configuration.assimilate_storage(&mut t).unwrap(); state.paras.assimilate_storage(&mut t).unwrap(); - let mut ext: sp_io::TestExternalities = t.into(); ext.register_extension(KeystoreExt(Arc::new(MemoryKeystore::new()) as KeystorePtr)); diff --git a/templates/parachain/pallets/xcnft/src/tests.rs b/templates/parachain/pallets/xcnft/src/tests.rs index 79f1aeef1cd0..8b137891791f 100644 --- a/templates/parachain/pallets/xcnft/src/tests.rs +++ b/templates/parachain/pallets/xcnft/src/tests.rs @@ -1,23 +1 @@ -use crate::{mock::*, Error, Something}; -use frame_support::{assert_noop, assert_ok}; -#[test] -fn it_works_for_default_value() { - new_test_ext().execute_with(|| { - // Dispatch a signed extrinsic. - assert_ok!(XcnftModule::do_something(RuntimeOrigin::signed(1), 42)); - // Read pallet storage and assert an expected result. - assert_eq!(Something::::get().map(|v| v.block_number), Some(42)); - }); -} - -#[test] -fn correct_error_for_none_value() { - new_test_ext().execute_with(|| { - // Ensure the expected error is thrown when no value is present. - assert_noop!( - XcnftModule::cause_error(RuntimeOrigin::signed(1)), - Error::::NoneValue - ); - }); -} diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index 80ddd68f24ac..f5df789d48c8 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -32,7 +32,6 @@ serde_json = { workspace = true, default-features = false } # Local pallet-parachain-template = { workspace = true } pallet-parachain-xcnft = { workspace = true } -pallet-uniques = { workspace = true } pallet-nfts = { workspace = true } @@ -122,7 +121,6 @@ std = [ "pallet-parachain-template/std", "pallet-parachain-xcnft/std", "pallet-session/std", - "pallet-uniques/std", "pallet-nfts/std", "pallet-sudo/std", "pallet-timestamp/std", diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index f472f7629389..6f221eb4108e 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -25,7 +25,6 @@ mod xcm_config; pub use pallet_parachain_xcnft; -pub use pallet_uniques; use pallet_nfts::{AttributeNamespace, Call as NftsCall}; @@ -352,24 +351,6 @@ parameter_types! { pub const max_votes: u32 = 1000000; } -impl pallet_uniques::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type CollectionId = u128; - type ItemId = u128; - type Currency = Balances; - type ForceOrigin = EnsureRoot; - type CreateOrigin = EnsureSigned; - type Locker = (); - type CollectionDeposit = CollectionDeposit; - type ItemDeposit = ItemDeposit; - type MetadataDepositBase = UniquesMetadataDepositBase; - type AttributeDepositBase = AttributeDepositBase; - type DepositPerByte = DepositPerByte; - type StringLimit = UniquesStringLimit; - type KeyLimit = KeyLimit; - type ValueLimit = ValueLimit; - type WeightInfo = (); -} pub type AccountPublic = ::Signer; impl pallet_nfts::Config for Runtime { diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index eb376aee5827..0d8374eee957 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -314,9 +314,6 @@ mod runtime { #[runtime::pallet_index(51)] pub type TemplatePallet = pallet_parachain_template; - #[runtime::pallet_index(52)] - pub type UniquesModule = pallet_uniques; - #[runtime::pallet_index(53)] pub type NftModule = pallet_nfts; diff --git a/templates/parachain_two/pallets/xcnft/Cargo.toml b/templates/parachain_two/pallets/xcnft/Cargo.toml index bb667f1c1264..5243c592e487 100644 --- a/templates/parachain_two/pallets/xcnft/Cargo.toml +++ b/templates/parachain_two/pallets/xcnft/Cargo.toml @@ -38,7 +38,6 @@ sp-runtime = { workspace = true } sp-std = {workspace = true} pallet-uniques = { workspace = true, default-features = false } -pallet-nfts = {workspace=true, default-features = false} [dev-dependencies] serde = { version = "1.0.210", default-features = false } @@ -64,7 +63,6 @@ std = [ "frame-benchmarking?/std", "frame-support/std", "frame-system/std", - "pallet-nfts/std", "sp-runtime/std", "cumulus-pallet-xcm/std", "cumulus-primitives-core/std", diff --git a/templates/parachain_two/pallets/xcnft/README.md b/templates/parachain_two/pallets/xcnft/README.md index 8c9fe173b249..5424ac973d7f 100644 --- a/templates/parachain_two/pallets/xcnft/README.md +++ b/templates/parachain_two/pallets/xcnft/README.md @@ -1,60 +1 @@ -# This repository holds xcNFT Pallet for cross-chain non-fungible asset sharing - -## Proof of concept implementation only! -### License MIT - -# Compile -```cargo build``` - -# Add to runtime -``` -/// Configure the pallet xcnft in pallets/xcnft. -impl pallet_parachain_xcnft::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - type StringLimit = ConstU32<255>; - type JsonLimit = ConstU32<255>; - type CollectionLimit = ConstU32<255>; - type ParaIDLimit = ConstU32<9999>; - type CollectionsPerParachainLimit = ConstU32<9999>; - type NFTsPerParachainLimit = ConstU32<9999>; - type XcmSender = XcmRouter; - type RuntimeCall = RuntimeCall; -} -``` - -and to construct_runtime! macro: - -``` -XCNFTPallet: pallet_parachain_xcnft = 51, -``` - -also import it - -``` -/// Import pallet xcnft -pub use pallet_parachain_xcnft; -``` - -To make XCM work update XCM config: -``` -AllowExplicitUnpaidExecutionFrom, -``` - -Change type Call Dispatcher: -``` -use xcm_executor::traits::WithOriginFilter; -``` -``` -type CallDispatcher = WithOriginFilter; -``` - - -Testing benchmarks (Needs to be implemented in runtime already) -``` -cargo test --package pallet-parachain-xcnft --features runtime-benchmarks -``` -Unit tests (Needs to be implemented in runtime already) -``` -cargo test --package pallet-parachain-xcnft --lib -- tests --nocapture -``` \ No newline at end of file +# xcNFT in Parachain with pallet_uniques \ No newline at end of file diff --git a/templates/parachain_two/pallets/xcnft/src/lib.rs b/templates/parachain_two/pallets/xcnft/src/lib.rs index d1d7e94b1096..dd33ecbd81b9 100644 --- a/templates/parachain_two/pallets/xcnft/src/lib.rs +++ b/templates/parachain_two/pallets/xcnft/src/lib.rs @@ -54,7 +54,10 @@ //! - `pallet-uniques` //! - `pallet-balances` //! - `parachain-info` - +//! +//! Other pallets: +//! - `enumflags2`` +//! #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; @@ -75,23 +78,24 @@ pub mod xmacros; #[frame_support::pallet] pub mod pallet { + use codec::EncodeLike; use core::marker::PhantomData; use cumulus_primitives_core::ParaId; use frame_support::{ dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, pallet_prelude::*, + traits::Currency, }; use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter}; - use codec::EncodeLike; use crate::xmacros::impl_codec_bitflags; + use enumflags2::{bitflags, BitFlags}; use frame_system::pallet_prelude::*; use pallet_uniques::DestroyWitness; use scale_info::prelude::vec; use sp_runtime::{traits::StaticLookup, DispatchError, DispatchErrorWithPostInfo}; use sp_std::prelude::*; use xcm::latest::prelude::*; - use enumflags2::{bitflags, BitFlags}; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; @@ -122,7 +126,8 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData<(T, I)>); - /// Add description!!!! + /// Following structure provides generalized version of DestroyWitness parameter that has + /// different composition in each nft pallet (pallet_uniques || pallet_nfts) #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Default, Debug)] #[scale_info(skip_type_params(T, I))] pub struct GeneralizedDestroyWitness { @@ -131,38 +136,38 @@ pub mod pallet { attributes: u32, } - /// Create struct for collection config, in case, that the message comes from nfts chain + /// Following struct is abstracted from pallet_nfts and is meant to replicate CollectionConfig + /// in case, that the user wishes to provide collection config compatible with pallet_nfts #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Default, Debug)] #[scale_info(skip_type_params(T))] pub struct CollectionConfig { - /// Collection's settings. pub settings: CollectionSettings, - /// Collection's max supply. pub max_supply: Option, - /// Default settings each item will get during the mint. - pub mint_settings: MintSettings, + pub mint_settings: MintSettings, } - /// Mimic collection config for of nfts pallet + /// Following type is abstracted from pallet_nfts and is meant to replicate CollectionConfigFor + /// in case, that the user wishes to provide collection config compatible with pallet_nfts pub type CollectionConfigFor = - CollectionConfig, BlockNumberFor, CollectionId>; + CollectionConfig, BlockNumberFor, CollectionId>; + /// Following enum is abstracted from pallet_nfts and is meant to replicate MintType in case, + /// that the user wishes to provide collection config compatible with pallet_nfts #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum MintType { - /// Only an `Issuer` could mint items. Issuer, - /// Anyone could mint items. Public, - /// Only holders of items in specified collection could mint new items. HolderOf(CollectionId), } - use frame_support::traits::Currency; - - pub type BalanceOf = - <>::Currency as Currency<::AccountId>>::Balance; + /// Following type is abstracted from pallet_nfts and is meant to replicate BalanceOf in case, + /// that the user wishes to provide collection config compatible with pallet_nfts + pub type BalanceOf = <>::Currency as Currency< + ::AccountId, + >>::Balance; - /// Mimic collection settings of nfts pallet + /// Following struct is abstracted from pallet_nfts and is meant to replicate CollectionSettings + /// in case, that the user wishes to provide collection config compatible with pallet_nfts #[derive(Clone, Copy, PartialEq, Eq, Default, RuntimeDebug)] pub struct CollectionSettings(pub BitFlags); @@ -181,27 +186,26 @@ pub mod pallet { } } + /// Following enum is abstracted from pallet_nfts and is meant to replicate CollectionSetting in + /// case, that the user wishes to provide collection config compatible with pallet_nfts #[bitflags] #[repr(u64)] #[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)] pub enum CollectionSetting { - /// Items in this collection are transferable. TransferableItems, - /// The metadata of this collection can be modified. UnlockedMetadata, - /// Attributes of this collection can be modified. UnlockedAttributes, - /// The supply of this collection can be modified. UnlockedMaxSupply, - /// When this isn't set then the deposit is required to hold the items of this collection. DepositRequired, } - + impl_codec_bitflags!(CollectionSettings, u64, CollectionSetting); + /// Following struct is abstracted from pallet_nfts and is meant to replicate ItemSettings in + /// case, that the user wishes to provide collection config compatible with pallet_nfts #[derive(Clone, Copy, PartialEq, Eq, Default, RuntimeDebug)] pub struct ItemSettings(pub BitFlags); - + impl ItemSettings { pub fn all_enabled() -> Self { Self(BitFlags::EMPTY) @@ -217,33 +221,27 @@ pub mod pallet { } } + /// Following enum is abstracted from pallet_nfts and is meant to replicate ItemSetting in case, + /// that the user wishes to provide collection config compatible with pallet_nfts #[bitflags] #[repr(u64)] #[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)] pub enum ItemSetting { - /// This item is transferable. Transferable, - /// The metadata of this item can be modified. UnlockedMetadata, - /// Attributes of this item can be modified. UnlockedAttributes, } - + impl_codec_bitflags!(ItemSettings, u64, ItemSetting); - - /// Holds the information about minting. + /// Following struct is abstracted from pallet_nfts and is meant to replicate MintSettings in + /// case, that the user wishes to provide collection config compatible with pallet_nfts #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct MintSettings { - /// Whether anyone can mint or if minters are restricted to some subset. pub mint_type: MintType, - /// An optional price per mint. pub price: Option, - /// When the mint starts. pub start_block: Option, - /// When the mint ends. pub end_block: Option, - /// Default settings each item will get during the mint. pub default_item_settings: ItemSettings, } @@ -357,7 +355,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn cross_chain_proposals)] pub type CrossChainProposals, I: 'static = ()> = - StorageMap<_, Blake2_128Concat, u64, Proposal>; + StorageMap<_, Blake2_128Concat, u64, Proposal>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -638,6 +636,8 @@ pub mod pallet { /// Event emitted when collection fails to mint on destination chain CollectionMintFailed { error: DispatchError }, + /// Event emitted when receiving collection cannot be created due to collection storage + /// being full. CollectionListFull { owner: AccountIdLookupOf }, } @@ -692,8 +692,6 @@ pub mod pallet { /// Error returned when user enters wrong origin collection id. WrongOriginCollectionAtOrigin, - - CollectionIdNotProvided, } #[pallet::call] @@ -740,16 +738,20 @@ pub mod pallet { let mut items = Vec::new(); for (item_id, _item_details) in - pallet_uniques::Item::::iter_prefix(&origin_collection.clone()) + pallet_uniques::Item::::iter_prefix(&origin_collection.clone()) { items.push(item_id); } // First check if collection contains any metadata if it does, then save it let mut collection_metadata = None; - if pallet_uniques::CollectionMetadataOf::::contains_key(&origin_collection.clone()) { + if pallet_uniques::CollectionMetadataOf::::contains_key( + &origin_collection.clone(), + ) { collection_metadata = Some( - pallet_uniques::CollectionMetadataOf::::get(origin_collection.clone()).unwrap().data, + pallet_uniques::CollectionMetadataOf::::get(origin_collection.clone()) + .unwrap() + .data, ); } @@ -783,7 +785,7 @@ pub mod pallet { origin_collection: origin_collection.clone(), destination_collection: dest_collection_id.clone(), collection_metadata: collection_metadata.clone().unwrap(), - config, + config, }, ) .encode() @@ -799,7 +801,8 @@ pub mod pallet { // Get collection from the storage let collection = - pallet_uniques::Collection::::get(origin_collection.clone()).unwrap(); + pallet_uniques::Collection::::get(origin_collection.clone()) + .unwrap(); // Create destroy witness type let destroy_witness = DestroyWitness { @@ -835,7 +838,7 @@ pub mod pallet { for item_id in items.clone() { if let Some(nft_owner) = - pallet_uniques::Pallet::::owner(origin_collection.clone(), item_id) + pallet_uniques::Pallet::::owner(origin_collection.clone(), item_id) { if nft_owner != collection_owner { for (_data, proposal) in CrossChainProposals::::iter() { @@ -848,9 +851,10 @@ pub mod pallet { let mut different_owners = BoundedVec::new(); for item_id in items.clone() { - if let Some(nft_owner) = - pallet_uniques::Pallet::::owner(origin_collection.clone(), item_id) - { + if let Some(nft_owner) = pallet_uniques::Pallet::::owner( + origin_collection.clone(), + item_id, + ) { if nft_owner != collection_owner { // Check if owner is not present in different owners if !different_owners.contains(&nft_owner) { @@ -908,11 +912,15 @@ pub mod pallet { // We get there, because collection owner is the same as NFT owners let mut collection_metadata = None; - if pallet_uniques::CollectionMetadataOf::::contains_key(&origin_collection.clone()) { + if pallet_uniques::CollectionMetadataOf::::contains_key( + &origin_collection.clone(), + ) { collection_metadata = Some( - pallet_uniques::CollectionMetadataOf::::get(origin_collection.clone()) - .unwrap() - .data, + pallet_uniques::CollectionMetadataOf::::get( + origin_collection.clone(), + ) + .unwrap() + .data, ); } @@ -927,10 +935,12 @@ pub mod pallet { &origin_collection.clone(), item_id, ) { - let item_details = - pallet_uniques::ItemMetadataOf::::get(origin_collection.clone(), item_id) - .unwrap() - .data; + let item_details = pallet_uniques::ItemMetadataOf::::get( + origin_collection.clone(), + item_id, + ) + .unwrap() + .data; nft_metadata.push((item_id, item_details)); } else { // Add empty metadata @@ -984,7 +994,8 @@ pub mod pallet { // Get collection from the storage let collection = - pallet_uniques::Collection::::get(origin_collection.clone()).unwrap(); + pallet_uniques::Collection::::get(origin_collection.clone()) + .unwrap(); // Create destroy witness type let destroy_witness = DestroyWitness { @@ -1208,7 +1219,7 @@ pub mod pallet { let mut items = Vec::new(); for (item_id, _item_details) in - pallet_uniques::Item::::iter_prefix(proposal.collection_id.clone()) + pallet_uniques::Item::::iter_prefix(proposal.collection_id.clone()) { items.push(item_id); } @@ -1229,9 +1240,11 @@ pub mod pallet { } for item_id in items.clone() { - let nft_owner = - pallet_uniques::Pallet::::owner(proposal.collection_id.clone(), item_id) - .unwrap(); + let nft_owner = pallet_uniques::Pallet::::owner( + proposal.collection_id.clone(), + item_id, + ) + .unwrap(); let unlooked_recipient = T::Lookup::unlookup(nft_owner.clone()); if pallet_uniques::ItemMetadataOf::::contains_key( @@ -1279,7 +1292,9 @@ pub mod pallet { origin_para: parachain_info::Pallet::::parachain_id(), collection_metadata: collection_metadata.unwrap(), nfts: nft_metadata.clone(), - dest_collection_id: proposal.proposed_dest_collection_id.clone(), + dest_collection_id: proposal + .proposed_dest_collection_id + .clone(), }, ) .encode() @@ -1316,10 +1331,9 @@ pub mod pallet { //Burning the collection let collection = - pallet_uniques::Collection::::get(proposal.collection_id.clone()) + pallet_uniques::Collection::::get(proposal.collection_id.clone()) .unwrap(); - // Create destroy witness type let destroy_witness = DestroyWitness { items: collection.clone().items, @@ -1355,7 +1369,7 @@ pub mod pallet { Ok(().into()) } - + /// Transfer an asset along with associated metadata to another parachain. /// /// Origin must be Signed and the signing account must be : @@ -1396,8 +1410,11 @@ pub mod pallet { // See if user owns the item ensure!( - pallet_uniques::Pallet::::owner(origin_collection.clone(), origin_asset.clone()) - .ok_or(Error::::NFTDoesNotExist)? == + pallet_uniques::Pallet::::owner( + origin_collection.clone(), + origin_asset.clone() + ) + .ok_or(Error::::NFTDoesNotExist)? == who.clone(), Error::::NotNFTOwner ); @@ -1405,8 +1422,10 @@ pub mod pallet { // Get Item data let mut metadata = Some(BoundedVec::new()); - if pallet_uniques::ItemMetadataOf::::contains_key(&origin_collection, &origin_asset) - { + if pallet_uniques::ItemMetadataOf::::contains_key( + &origin_collection, + &origin_asset, + ) { metadata = pallet_uniques::ItemMetadataOf::::get( origin_collection.clone(), origin_asset.clone(), @@ -2107,7 +2126,7 @@ pub mod pallet { origin_collection: T::CollectionId, destination_collection: Option, collection_metadata: BoundedVec, - config: Option>, + _config: Option>, ) -> DispatchResultWithPostInfo { let signed_origin = ensure_signed(origin.clone())?; let signed_origin_lookup = T::Lookup::unlookup(signed_origin.clone()); @@ -2124,13 +2143,14 @@ pub mod pallet { // Try with origin collection id, maybe that is empty match pallet_uniques::Collection::::contains_key(&origin_collection) { true => { + // Future work - CollectionId is not incrementable in pallet_uniques // Use for cycle to find empty collection // let mut i = 0; // loop { - // let new_collection: T::CollectionId = T::CollectionId::from(i as u32); - // if !pallet_uniques::Collection::::contains_key(&new_collection) { - // destination_collection = new_collection; - // break; + // let new_collection: T::CollectionId = T::CollectionId::from(i as + // u32); if !pallet_uniques::Collection::::contains_key(&new_collection) { destination_collection = + // new_collection; break; // } // if i == u32::MAX { // // Deposit event indicating failure to create collection @@ -2142,11 +2162,13 @@ pub mod pallet { // i += 1; //} }, - false => { destination_collection = origin_collection.clone(); }, + false => { + destination_collection = origin_collection.clone(); + }, } }, false => {}, - } + } // Create the collection match pallet_uniques::Pallet::::create( @@ -2208,8 +2230,8 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let signed_origin = ensure_signed(origin.clone())?; let signed_origin_lookup = T::Lookup::unlookup(signed_origin.clone()); - - let destroy_witness = DestroyWitness{ + + let destroy_witness = DestroyWitness { items: witness_data.item_configs.clone(), item_metadatas: witness_data.item_meta.clone(), attributes: witness_data.attributes.clone(), @@ -2447,7 +2469,7 @@ pub mod pallet { if SentAssets::::contains_key(&(collection.clone(), item.clone())) { // User returns nft to origin collection, use collection owner to add metadata let col_owner = - pallet_uniques::Pallet::::collection_owner(collection.clone()).unwrap(); + pallet_uniques::Pallet::::collection_owner(collection.clone()).unwrap(); let signed_col: OriginFor = frame_system::RawOrigin::Signed(col_owner.clone()).into(); let sent_asset = @@ -2587,7 +2609,7 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn parse_collection_same_owner( origin: OriginFor, - config: Option>, + _config: Option>, collection_metadata: BoundedVec, nfts: Vec<(T::ItemId, BoundedVec)>, origin_para: ParaId, @@ -2608,13 +2630,14 @@ pub mod pallet { // Try with origin collection id, maybe that is empty match pallet_uniques::Collection::::contains_key(&origin_collection_id) { true => { + // Future work - CollectionId is not incrementable in pallet_uniques // Use for cycle to find empty collection // let mut i = 0; // loop { - // let new_collection: T::CollectionId = T::CollectionId::from(i as u32); - // if !pallet_uniques::Collection::::contains_key(&new_collection) { - // destination_collection = new_collection; - // break; + // let new_collection: T::CollectionId = T::CollectionId::from(i as + // u32); if !pallet_uniques::Collection::::contains_key(&new_collection) { destination_collection = + // new_collection; break; // } // if i == u32::MAX { // // Deposit event indicating failure to create collection @@ -2626,11 +2649,13 @@ pub mod pallet { // i += 1; //} }, - false => { col_id = origin_collection_id.clone(); }, + false => { + col_id = origin_collection_id.clone(); + }, } }, false => {}, - } + } match pallet_uniques::Pallet::::create( origin.clone(), @@ -2745,7 +2770,7 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] pub fn parse_collection_diff_owners( origin: OriginFor, - config: Option>, + _config: Option>, collection_metadata: BoundedVec, nfts: Vec<(T::ItemId, AccountIdLookupOf, BoundedVec)>, origin_para: ParaId, @@ -2766,13 +2791,14 @@ pub mod pallet { // Try with origin collection id, maybe that is empty match pallet_uniques::Collection::::contains_key(&origin_collection_id) { true => { + // Future work - CollectionId is not incrementable in pallet_uniques // Use for cycle to find empty collection // let mut i = 0; // loop { - // let new_collection: T::CollectionId = T::CollectionId::from(i as u32); - // if !pallet_uniques::Collection::::contains_key(&new_collection) { - // destination_collection = new_collection; - // break; + // let new_collection: T::CollectionId = T::CollectionId::from(i as + // u32); if !pallet_uniques::Collection::::contains_key(&new_collection) { destination_collection = + // new_collection; break; // } // if i == u32::MAX { // // Deposit event indicating failure to create collection @@ -2784,12 +2810,13 @@ pub mod pallet { // i += 1; //} }, - false => { col_id = origin_collection_id.clone(); }, + false => { + col_id = origin_collection_id.clone(); + }, } }, false => {}, - } - + } match pallet_uniques::Pallet::::create( origin.clone(), diff --git a/templates/parachain_two/pallets/xcnft/src/mock/mod.rs b/templates/parachain_two/pallets/xcnft/src/mock/mod.rs index 8de6345403b9..e25e77b394e1 100644 --- a/templates/parachain_two/pallets/xcnft/src/mock/mod.rs +++ b/templates/parachain_two/pallets/xcnft/src/mock/mod.rs @@ -2,12 +2,12 @@ use super::*; use sp_io::TestExternalities; -use sp_runtime::{AccountId32}; +use sp_runtime::AccountId32; mod parachain; mod relaychain; use crate as xnft; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; use sp_runtime::BuildStorage; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); @@ -81,31 +81,26 @@ pub fn para_teleport_ext(para_id: u32) -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let parachain_info_config = parachain_info::GenesisConfig:: { - _config: Default::default(), - parachain_id: para_id.into(), - }; - parachain_info_config.assimilate_storage(&mut t).unwrap(); + let parachain_info_config = parachain_info::GenesisConfig:: { + _config: Default::default(), + parachain_id: para_id.into(), + }; + parachain_info_config.assimilate_storage(&mut t).unwrap(); let mut ext = TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext } - pub fn relay_ext() -> sp_io::TestExternalities { - use relaychain::{Test, System}; + use relaychain::{System, Test}; - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, 1_000)], - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, 1_000)] } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/mock/parachain.rs b/templates/parachain_two/pallets/xcnft/src/mock/parachain.rs index c235317f6686..92cf0c836157 100644 --- a/templates/parachain_two/pallets/xcnft/src/mock/parachain.rs +++ b/templates/parachain_two/pallets/xcnft/src/mock/parachain.rs @@ -23,8 +23,8 @@ pub use sp_runtime::{ }; use crate::test::parachain::currency::DOLLARS; -use sp_runtime::BuildStorage; use sp_core::{H256, U256}; +use sp_runtime::BuildStorage; pub type CollectionId = u64; type Origin = ::RuntimeOrigin; @@ -290,7 +290,6 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); - } pub struct ChannelInfo; @@ -408,4 +407,4 @@ impl ExtBuilder { let storage = frame_system::GenesisConfig::::default().build_storage().unwrap(); storage.into() } -} \ No newline at end of file +} diff --git a/templates/parachain_two/pallets/xcnft/src/mock/relaychain.rs b/templates/parachain_two/pallets/xcnft/src/mock/relaychain.rs index a6ef38deb467..24f70dace738 100644 --- a/templates/parachain_two/pallets/xcnft/src/mock/relaychain.rs +++ b/templates/parachain_two/pallets/xcnft/src/mock/relaychain.rs @@ -1,41 +1,38 @@ - #![cfg(test)] use crate::{ self as pallet_parachain_xcnft, - test::relay::currency::{CENTS, MILLICENTS}, + test::{ + relay::currency::{CENTS, MILLICENTS}, + *, + }, }; use cumulus_primitives_core::relay_chain::CandidateHash; -use frame_support::{assert_ok, traits::AsEnsureOriginWithArg}; -use polkadot_runtime_common::{ - paras_sudo_wrapper, - xcm_sender::{ChildParachainRouter, ExponentialPrice}, -}; -use sp_runtime::BuildStorage; -use crate::test::*; use frame_support::{ - construct_runtime, + assert_ok, construct_runtime, dispatch::DispatchClass, pallet_prelude::{DispatchResult, Get}, parameter_types, traits::{ - ConstU128, ConstU16, ConstU32, ConstU64, Currency, Everything, GenesisBuild, Nothing, - ProcessMessage, ProcessMessageError, + AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, Currency, Everything, + GenesisBuild, KeyOwnerProofSystem, Nothing, ProcessMessage, ProcessMessageError, }, weights::{constants::RocksDbWeight, IdentityFee, Weight, WeightMeter}, - }; -use frame_support::traits::KeyOwnerProofSystem; use polkadot_parachain::primitives::ValidationCode; -use sp_runtime::traits::AccountIdConversion; +use polkadot_runtime_common::{ + paras_sudo_wrapper, + xcm_sender::{ChildParachainRouter, ExponentialPrice}, +}; +use sp_runtime::{traits::AccountIdConversion, BuildStorage}; use crate::test::relay::currency::DOLLARS; use cumulus_primitives_core::{ relay_chain::{AuthorityDiscoveryId, SessionIndex, ValidatorIndex}, ChannelStatus, GetChannelInfo, ParaId, }; -use polkadot_runtime_parachains::disputes::SlashingHandler; use frame_support::traits::ValidatorSetWithIdentification; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; +use polkadot_runtime_parachains::disputes::SlashingHandler; use sp_runtime::{transaction_validity::TransactionPriority, Permill}; use std::{cell::RefCell, collections::HashMap}; pub mod currency { @@ -66,15 +63,18 @@ use xcm_builder::{EnsureXcmOrigin, NativeAsset}; use pallet_nfts::PalletFeatures; pub use polkadot_runtime_parachains::{ - configuration, - inclusion::{AggregateMessageOrigin, UmpQueueId}, - origin, shared,disputes, inclusion, paras, scheduler, session_info, assigner, assigner_parachains, assigner_on_demand,hrmp, - dmp as parachains_dmp, paras::ParaGenesisArgs, schedule_para_initialize, + assigner, assigner_on_demand, assigner_parachains, configuration, disputes, disputes::slashing as parachains_slashing, + dmp as parachains_dmp, hrmp, inclusion, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, paras, + paras::ParaGenesisArgs, + schedule_para_initialize, scheduler, session_info, shared, }; use primitives::ValidatorId; pub type BlockNumber = u64; pub type Index = u32; +use sp_runtime::KeyTypeId; use xcm::v3::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, @@ -83,7 +83,6 @@ use xcm_builder::{ TakeWeightCredit, UsingComponents, }; use xcm_executor::XcmExecutor; -use sp_runtime::KeyTypeId; type Origin = ::RuntimeOrigin; use crate::Config; @@ -397,7 +396,6 @@ impl SlashingHandler for Test { fn initializer_on_new_session(_: SessionIndex) {} } - impl disputes::Config for Test { type RuntimeEvent = RuntimeEvent; type RewardValidators = Self; @@ -437,7 +435,6 @@ impl disputes::RewardValidators for Test { } } - thread_local! { pub static DISCOVERY_AUTHORITIES: RefCell> = RefCell::new(Vec::new()); } @@ -565,7 +562,6 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); - } pub type LocalOriginToLocation = SignedToAccountId32; @@ -669,7 +665,6 @@ pub fn new_test_ext(state: MockGenesisConfig) -> sp_io::TestExternalities { state.configuration.assimilate_storage(&mut t).unwrap(); state.paras.assimilate_storage(&mut t).unwrap(); - let mut ext: sp_io::TestExternalities = t.into(); ext.register_extension(KeystoreExt(Arc::new(MemoryKeystore::new()) as KeystorePtr)); diff --git a/templates/parachain_two/pallets/xcnft/src/tests.rs b/templates/parachain_two/pallets/xcnft/src/tests.rs index e69de29bb2d1..8b137891791f 100644 --- a/templates/parachain_two/pallets/xcnft/src/tests.rs +++ b/templates/parachain_two/pallets/xcnft/src/tests.rs @@ -0,0 +1 @@ + diff --git a/templates/parachain_two/pallets/xcnft/src/xmacros.rs b/templates/parachain_two/pallets/xcnft/src/xmacros.rs index a75c6ea973db..2333646a5d13 100644 --- a/templates/parachain_two/pallets/xcnft/src/xmacros.rs +++ b/templates/parachain_two/pallets/xcnft/src/xmacros.rs @@ -1,6 +1,6 @@ /// Code originates from pallet_nfts /// -/// Used to mimic collectionconfigfor parameter +/// Used to mimic CollectionConfigFor parameter from NFTs pallet /// /// macro_rules! impl_codec_bitflags { diff --git a/templates/parachain_two/runtime/Cargo.toml b/templates/parachain_two/runtime/Cargo.toml index 654414ac6c36..0d19f942ca96 100644 --- a/templates/parachain_two/runtime/Cargo.toml +++ b/templates/parachain_two/runtime/Cargo.toml @@ -33,8 +33,6 @@ serde_json = { workspace = true, default-features = false } pallet-parachain-template-two = { workspace = true } pallet-parachain-xcnft-two = { workspace = true } pallet-uniques = { workspace = true } -pallet-nfts = { workspace = true } - # Substrate / FRAME frame-benchmarking = { optional = true, workspace = true } @@ -123,7 +121,6 @@ std = [ "pallet-parachain-xcnft-two/std", "pallet-session/std", "pallet-uniques/std", - "pallet-nfts/std", "pallet-sudo/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", diff --git a/templates/parachain_two/runtime/src/configs/mod.rs b/templates/parachain_two/runtime/src/configs/mod.rs index 24d4ffbb4706..b4d79037361b 100644 --- a/templates/parachain_two/runtime/src/configs/mod.rs +++ b/templates/parachain_two/runtime/src/configs/mod.rs @@ -27,8 +27,6 @@ mod xcm_config; pub use pallet_parachain_xcnft_two; pub use pallet_uniques; -use pallet_nfts::{AttributeNamespace, Call as NftsCall}; - // Substrate and Polkadot dependencies use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; @@ -346,7 +344,6 @@ parameter_types! { pub const MaxTips: u32 = 1; pub const MaxDeadlineDuration: u32 = 1; pub const MaxAttributesPerCall: u32 = 10; - pub NftFeatures: pallet_nfts::PalletFeatures = pallet_nfts::PalletFeatures::all_enabled(); pub const proposal_time_in_blocks_parameter: u32 = 10; pub const max_owners_parameter: u32 = 1000000; pub const max_votes: u32 = 1000000; @@ -371,30 +368,3 @@ impl pallet_uniques::Config for Runtime { type WeightInfo = (); } pub type AccountPublic = ::Signer; - -impl pallet_nfts::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type CollectionId = u32; - type ItemId = u32; - type Currency = Balances; - type ForceOrigin = EnsureRoot; - type CreateOrigin = EnsureSigned; - type CollectionDeposit = CollectionDeposit; - type Locker = (); - type ItemDeposit = ItemDeposit; - type MetadataDepositBase = UniquesMetadataDepositBase; - type AttributeDepositBase = AttributeDepositBase; - type DepositPerByte = DepositPerByte; - type StringLimit = UniquesStringLimit; - type KeyLimit = KeyLimit; - type ValueLimit = ValueLimit; - type ApprovalsLimit = ApprovalsLimit; - type ItemAttributesApprovalsLimit = ItemAttributesApprovalsLimit; - type MaxTips = MaxTips; - type MaxDeadlineDuration = MaxDeadlineDuration; - type MaxAttributesPerCall = MaxAttributesPerCall; - type Features = NftFeatures; - type OffchainSignature = MultiSignature; - type OffchainPublic = AccountPublic; - type WeightInfo = (); -} \ No newline at end of file diff --git a/templates/parachain_two/runtime/src/lib.rs b/templates/parachain_two/runtime/src/lib.rs index 5070cc6004e2..a840616f2489 100644 --- a/templates/parachain_two/runtime/src/lib.rs +++ b/templates/parachain_two/runtime/src/lib.rs @@ -316,10 +316,7 @@ mod runtime { #[runtime::pallet_index(52)] pub type UniquesModule = pallet_uniques; - - #[runtime::pallet_index(53)] - pub type NftModule = pallet_nfts; - + } #[docify::export(register_validate_block)]