Skip to content

Commit

Permalink
Finish refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Oct 24, 2024
1 parent 3df89da commit a3925b4
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 360 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions templates/parachain/pallets/xcnft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -59,7 +58,6 @@ runtime-benchmarks = [
std = [
"codec/std",
"scale-info/std",
"pallet-uniques/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
Expand Down
45 changes: 24 additions & 21 deletions templates/parachain/pallets/xcnft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -116,7 +116,8 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T, I = ()>(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 {
Expand Down Expand Up @@ -1141,7 +1142,9 @@ pub mod pallet {
origin_para: parachain_info::Pallet::<T>::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()
Expand Down Expand Up @@ -1961,7 +1964,7 @@ pub mod pallet {
pub fn parse_collection_empty(
origin: OriginFor<T>,
origin_collection: T::CollectionId,
destination_collection: Option<T::CollectionId>,
_destination_collection: Option<T::CollectionId>,
collection_metadata: BoundedVec<u8, T::StringLimit>,
config: Option<CollectionConfigFor<T, I>>,
) -> DispatchResultWithPostInfo {
Expand All @@ -1978,7 +1981,8 @@ pub mod pallet {
// Create default configfor collection
let def_config = CollectionConfigFor::<T, I> {
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
};

Expand All @@ -1993,8 +1997,7 @@ pub mod pallet {
Self::deposit_event(Event::CollectionMintFailed { error: e });
},
}
}
else{
} else {
match pallet_nfts::Pallet::<T, I>::create(
origin.clone(),
signed_origin_lookup.clone(),
Expand All @@ -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::<T, I>::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::<T, I>::get()
Expand All @@ -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::<T, I>::collection_owner(next_collection_id).unwrap() ==
signed_origin.clone()
signed_origin.clone()
{
// We have users collection
user_collection = next_collection_id.clone();
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -2456,7 +2459,7 @@ pub mod pallet {
nfts: Vec<(T::ItemId, BoundedVec<u8, T::StringLimit>)>,
origin_para: ParaId,
origin_collection_id: T::CollectionId,
dest_collection_id: Option<T::CollectionId>
_dest_collection_id: Option<T::CollectionId>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin.clone())?;
let signed_origin_lookup = T::Lookup::unlookup(who.clone());
Expand All @@ -2471,7 +2474,8 @@ pub mod pallet {
// Create default configfor collection
let def_config = CollectionConfigFor::<T, I> {
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
};

Expand All @@ -2486,8 +2490,7 @@ pub mod pallet {
Self::deposit_event(Event::CollectionMintFailed { error: e });
},
}
}
else{
} else {
match pallet_nfts::Pallet::<T, I>::create(
origin.clone(),
signed_origin_lookup.clone(),
Expand All @@ -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();
Expand Down Expand Up @@ -2631,7 +2634,7 @@ pub mod pallet {
nfts: Vec<(T::ItemId, AccountIdLookupOf<T>, BoundedVec<u8, T::StringLimit>)>,
origin_para: ParaId,
origin_collection_id: T::CollectionId,
dest_collection_id: Option<T::CollectionId>,
_dest_collection_id: Option<T::CollectionId>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin.clone())?;
let signed_origin_lookup = T::Lookup::unlookup(who.clone());
Expand All @@ -2646,7 +2649,8 @@ pub mod pallet {
// Create default configfor collection
let def_config = CollectionConfigFor::<T, I> {
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
};

Expand All @@ -2661,8 +2665,7 @@ pub mod pallet {
Self::deposit_event(Event::CollectionMintFailed { error: e });
},
}
}
else{
} else {
match pallet_nfts::Pallet::<T, I>::create(
origin.clone(),
signed_origin_lookup.clone(),
Expand All @@ -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();
Expand Down
31 changes: 13 additions & 18 deletions templates/parachain/pallets/xcnft/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -81,31 +81,26 @@ pub fn para_teleport_ext(para_id: u32) -> TestExternalities {

let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

let parachain_info_config = parachain_info::GenesisConfig::<Test> {
_config: Default::default(),
parachain_id: para_id.into(),
};
parachain_info_config.assimilate_storage(&mut t).unwrap();
let parachain_info_config = parachain_info::GenesisConfig::<Test> {
_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::<Test>::default()
.build_storage()
.unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
balances: vec![(ALICE, 1_000)],
}
.assimilate_storage(&mut t)
.unwrap();
pallet_balances::GenesisConfig::<Test> { 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
}
}
5 changes: 2 additions & 3 deletions templates/parachain/pallets/xcnft/src/mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Test as frame_system::Config>::RuntimeOrigin;
Expand Down Expand Up @@ -290,7 +290,6 @@ impl xcm_executor::Config for XcmConfig {
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = ();

}

pub struct ChannelInfo;
Expand Down Expand Up @@ -408,4 +407,4 @@ impl ExtBuilder {
let storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
storage.into()
}
}
}
Loading

0 comments on commit a3925b4

Please sign in to comment.