difftreelog
NFTPAR-183: Storage Refactoring. Reduced collection id and token id from u64 to u32.
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth48// Structs48// Structs49// #region49// #region5051pub type CollectionId = u32;52pub type TokenId = u32;505351#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]54#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]52#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]55#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]116#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]119#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]117#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]120#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]118pub struct NftItemType<AccountId> {121pub struct NftItemType<AccountId> {119 pub collection: u64,122 pub collection: CollectionId,120 pub owner: AccountId,123 pub owner: AccountId,121 pub const_data: Vec<u8>,124 pub const_data: Vec<u8>,122 pub variable_data: Vec<u8>,125 pub variable_data: Vec<u8>,125#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]128#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]126#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]129#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]127pub struct FungibleItemType<AccountId> {130pub struct FungibleItemType<AccountId> {128 pub collection: u64,131 pub collection: CollectionId,129 pub owner: AccountId,132 pub owner: AccountId,130 pub value: u128,133 pub value: u128,131}134}132135133#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]136#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]134#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]137#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]135pub struct ReFungibleItemType<AccountId> {138pub struct ReFungibleItemType<AccountId> {136 pub collection: u64,139 pub collection: CollectionId,137 pub owner: Vec<Ownership<AccountId>>,140 pub owner: Vec<Ownership<AccountId>>,138 pub const_data: Vec<u8>,141 pub const_data: Vec<u8>,139 pub variable_data: Vec<u8>,142 pub variable_data: Vec<u8>,151pub struct VestingItem<AccountId, Moment> {154pub struct VestingItem<AccountId, Moment> {152 pub sender: AccountId,155 pub sender: AccountId,153 pub recipient: AccountId,156 pub recipient: AccountId,154 pub collection_id: u64,157 pub collection_id: CollectionId,155 pub item_id: u64,158 pub item_id: TokenId,156 pub amount: u64,159 pub amount: u64,157 pub vesting_date: Moment,160 pub vesting_date: Moment,158}161}167#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]170#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]168#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]171#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]169pub struct ChainLimits {172pub struct ChainLimits {170 pub collection_numbers_limit: u64,173 pub collection_numbers_limit: u32,171 pub account_token_ownership_limit: u64,174 pub account_token_ownership_limit: u32,172 pub collections_admins_limit: u64,175 pub collections_admins_limit: u64,173 pub custom_data_limit: u32,176 pub custom_data_limit: u32,174177341 trait Store for Module<T: Trait> as Nft {344 trait Store for Module<T: Trait> as Nft {342345343 // Private members346 // Private members344 NextCollectionID: u64;347 NextCollectionID: CollectionId;345 CreatedCollectionCount: u64;348 CreatedCollectionCount: u32;346 ChainVersion: u64;349 ChainVersion: u64;347 ItemListIndex: map hasher(blake2_128_concat) u64 => u64;350 ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;348351349 // Chain limits struct352 // Chain limits struct350 pub ChainLimit get(fn chain_limit) config(): ChainLimits;353 pub ChainLimit get(fn chain_limit) config(): ChainLimits;351354352 // Bound counters355 // Bound counters353 CollectionCount: u64;356 CollectionCount: u32;354 pub AccountItemCount get(fn account_item_count): map hasher(identity) T::AccountId => u64;357 pub AccountItemCount get(fn account_item_count): map hasher(identity) T::AccountId => u32;355358356 // Basic collections359 // Basic collections357 pub Collection get(fn collection) config(): map hasher(identity) u64 => CollectionType<T::AccountId>;360 pub Collection get(fn collection) config(): map hasher(identity) CollectionId => CollectionType<T::AccountId>;358 pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;361 pub AdminList get(fn admin_list_collection): map hasher(identity) CollectionId => Vec<T::AccountId>;359 pub WhiteList get(fn white_list): map hasher(identity) u64 => Vec<T::AccountId>;362 pub WhiteList get(fn white_list): map hasher(identity) CollectionId => Vec<T::AccountId>;360363361 /// Balance owner per collection map364 /// Balance owner per collection map362 pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => u64;365 pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => u64;363366364 /// second parameter: item id + owner account id367 /// second parameter: item id + owner account id365 pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) (u64, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;368 pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;366369367 /// Item collections370 /// Item collections368 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => NftItemType<T::AccountId>;371 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => NftItemType<T::AccountId>;369 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => FungibleItemType<T::AccountId>;372 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => FungibleItemType<T::AccountId>;370 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => ReFungibleItemType<T::AccountId>;373 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => ReFungibleItemType<T::AccountId>;371374372 /// Index list375 /// Index list373 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;376 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => Vec<TokenId>;374377375 /// Tokens transfer baskets378 /// Tokens transfer baskets376 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;379 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;377 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => Vec<BasketItem<T::AccountId, T::BlockNumber>>;380 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Vec<BasketItem<T::AccountId, T::BlockNumber>>;378 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;381 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;379382380 // Contract Sponsorship and Ownership383 // Contract Sponsorship and Ownership381 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;384 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;419 /// * mode: [CollectionMode] converted into u8.422 /// * mode: [CollectionMode] converted into u8.420 /// 423 /// 421 /// * account_id: Collection owner.424 /// * account_id: Collection owner.422 Created(u64, u8, AccountId),425 Created(CollectionId, u8, AccountId),423426424 /// New item was created.427 /// New item was created.425 /// 428 /// 428 /// * collection_id: Id of the collection where item was created.431 /// * collection_id: Id of the collection where item was created.429 /// 432 /// 430 /// * item_id: Id of an item. Unique within the collection.433 /// * item_id: Id of an item. Unique within the collection.431 ItemCreated(u64, u64),434 ItemCreated(CollectionId, TokenId),432435433 /// Collection item was burned.436 /// Collection item was burned.434 /// 437 /// 437 /// collection_id.440 /// collection_id.438 /// 441 /// 439 /// item_id: Identifier of burned NFT.442 /// item_id: Identifier of burned NFT.440 ItemDestroyed(u64, u64),443 ItemDestroyed(CollectionId, TokenId),441 }444 }442);445);443446558 /// 561 /// 559 /// * collection_id: collection to destroy.562 /// * collection_id: collection to destroy.560 #[weight = T::WeightInfo::destroy_collection()]563 #[weight = T::WeightInfo::destroy_collection()]561 pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {564 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {562565563 let sender = ensure_signed(origin)?;566 let sender = ensure_signed(origin)?;564 Self::check_owner_permissions(collection_id, sender)?;567 Self::check_owner_permissions(collection_id, sender)?;605 /// 608 /// 606 /// * address.609 /// * address.607 #[weight = T::WeightInfo::add_to_white_list()]610 #[weight = T::WeightInfo::add_to_white_list()]608 pub fn add_to_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{611 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{609612610 let sender = ensure_signed(origin)?;613 let sender = ensure_signed(origin)?;611 Self::check_owner_or_admin_permissions(collection_id, sender)?;614 Self::check_owner_or_admin_permissions(collection_id, sender)?;640 /// 643 /// 641 /// * address.644 /// * address.642 #[weight = T::WeightInfo::remove_from_white_list()]645 #[weight = T::WeightInfo::remove_from_white_list()]643 pub fn remove_from_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{646 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{644647645 let sender = ensure_signed(origin)?;648 let sender = ensure_signed(origin)?;646 Self::check_owner_or_admin_permissions(collection_id, sender)?;649 Self::check_owner_or_admin_permissions(collection_id, sender)?;669 /// 672 /// 670 /// * mode: [AccessMode]673 /// * mode: [AccessMode]671 #[weight = T::WeightInfo::set_public_access_mode()]674 #[weight = T::WeightInfo::set_public_access_mode()]672 pub fn set_public_access_mode(origin, collection_id: u64, mode: AccessMode) -> DispatchResult675 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult673 {676 {674 let sender = ensure_signed(origin)?;677 let sender = ensure_signed(origin)?;675678695 /// 698 /// 696 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.699 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.697 #[weight = T::WeightInfo::set_mint_permission()]700 #[weight = T::WeightInfo::set_mint_permission()]698 pub fn set_mint_permission(origin, collection_id: u64, mint_permission: bool) -> DispatchResult701 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult699 {702 {700 let sender = ensure_signed(origin)?;703 let sender = ensure_signed(origin)?;701704719 /// 722 /// 720 /// * new_owner.723 /// * new_owner.721 #[weight = T::WeightInfo::change_collection_owner()]724 #[weight = T::WeightInfo::change_collection_owner()]722 pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {725 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {723726724 let sender = ensure_signed(origin)?;727 let sender = ensure_signed(origin)?;725 Self::check_owner_permissions(collection_id, sender)?;728 Self::check_owner_permissions(collection_id, sender)?;744 /// 747 /// 745 /// * new_admin_id: Address of new admin to add.748 /// * new_admin_id: Address of new admin to add.746 #[weight = T::WeightInfo::add_collection_admin()]749 #[weight = T::WeightInfo::add_collection_admin()]747 pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {750 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::AccountId) -> DispatchResult {748751749 let sender = ensure_signed(origin)?;752 let sender = ensure_signed(origin)?;750 Self::check_owner_or_admin_permissions(collection_id, sender)?;753 Self::check_owner_or_admin_permissions(collection_id, sender)?;778 /// 781 /// 779 /// * account_id: Address of admin to remove.782 /// * account_id: Address of admin to remove.780 #[weight = T::WeightInfo::remove_collection_admin()]783 #[weight = T::WeightInfo::remove_collection_admin()]781 pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {784 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::AccountId) -> DispatchResult {782785783 let sender = ensure_signed(origin)?;786 let sender = ensure_signed(origin)?;784 Self::check_owner_or_admin_permissions(collection_id, sender)?;787 Self::check_owner_or_admin_permissions(collection_id, sender)?;803 /// 806 /// 804 /// * new_sponsor.807 /// * new_sponsor.805 #[weight = T::WeightInfo::set_collection_sponsor()]808 #[weight = T::WeightInfo::set_collection_sponsor()]806 pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {809 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {807810808 let sender = ensure_signed(origin)?;811 let sender = ensure_signed(origin)?;809 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);812 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);825 /// 828 /// 826 /// * collection_id.829 /// * collection_id.827 #[weight = T::WeightInfo::confirm_sponsorship()]830 #[weight = T::WeightInfo::confirm_sponsorship()]828 pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {831 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {829832830 let sender = ensure_signed(origin)?;833 let sender = ensure_signed(origin)?;831 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);834 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);850 /// 853 /// 851 /// * collection_id.854 /// * collection_id.852 #[weight = T::WeightInfo::remove_collection_sponsor()]855 #[weight = T::WeightInfo::remove_collection_sponsor()]853 pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {856 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {854857855 let sender = ensure_signed(origin)?;858 let sender = ensure_signed(origin)?;856 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);859 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);889 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]892 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]890893891 #[weight = T::WeightInfo::create_item(data.len())]894 #[weight = T::WeightInfo::create_item(data.len())]892 pub fn create_item(origin, collection_id: u64, owner: T::AccountId, data: CreateItemData) -> DispatchResult {895 pub fn create_item(origin, collection_id: CollectionId, owner: T::AccountId, data: CreateItemData) -> DispatchResult {893896894 let sender = ensure_signed(origin)?;897 let sender = ensure_signed(origin)?;895898925 #[weight = T::WeightInfo::create_item(items_data.into_iter()928 #[weight = T::WeightInfo::create_item(items_data.into_iter()926 .map(|data| { data.len() })929 .map(|data| { data.len() })927 .sum())]930 .sum())]928 pub fn create_multiple_items(origin, collection_id: u64, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {931 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {929932930 ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);933 ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);931 let sender = ensure_signed(origin)?;934 let sender = ensure_signed(origin)?;959 /// 962 /// 960 /// * item_id: ID of NFT to burn.963 /// * item_id: ID of NFT to burn.961 #[weight = T::WeightInfo::burn_item()]964 #[weight = T::WeightInfo::burn_item()]962 pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {965 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {963966964 let sender = ensure_signed(origin)?;967 let sender = ensure_signed(origin)?;965 Self::collection_exists(collection_id)?;968 Self::collection_exists(collection_id)?;1012 /// * Fungible Mode: Must specify transferred amount1015 /// * Fungible Mode: Must specify transferred amount1013 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)1016 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)1014 #[weight = T::WeightInfo::transfer()]1017 #[weight = T::WeightInfo::transfer()]1015 pub fn transfer(origin, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {1018 pub fn transfer(origin, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u64) -> DispatchResult {101610191017 let sender = ensure_signed(origin)?;1020 let sender = ensure_signed(origin)?;101810211054 /// 1057 /// 1055 /// * item_id: ID of the item.1058 /// * item_id: ID of the item.1056 #[weight = T::WeightInfo::approve()]1059 #[weight = T::WeightInfo::approve()]1057 pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {1060 pub fn approve(origin, approved: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {105810611059 let sender = ensure_signed(origin)?;1062 let sender = ensure_signed(origin)?;106010631112 /// 1115 /// 1113 /// * value: Amount to transfer.1116 /// * value: Amount to transfer.1114 #[weight = T::WeightInfo::transfer_from()]1117 #[weight = T::WeightInfo::transfer_from()]1115 pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64 ) -> DispatchResult {1118 pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u64 ) -> DispatchResult {111611191117 let sender = ensure_signed(origin)?;1120 let sender = ensure_signed(origin)?;1118 let mut appoved_transfer = false;1121 let mut appoved_transfer = false;115711601158 ///1161 ///1159 #[weight = 0]1162 #[weight = 0]1160 pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {1163 pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {116111641162 // let no_perm_mes = "You do not have permissions to modify this collection";1165 // let no_perm_mes = "You do not have permissions to modify this collection";1163 // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);1166 // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);1186 #[weight = T::WeightInfo::set_variable_meta_data()]1189 #[weight = T::WeightInfo::set_variable_meta_data()]1187 pub fn set_variable_meta_data (1190 pub fn set_variable_meta_data (1188 origin,1191 origin,1189 collection_id: u64,1192 collection_id: CollectionId,1190 item_id: u64,1193 item_id: TokenId,1191 data: Vec<u8>1194 data: Vec<u8>1192 ) -> DispatchResult {1195 ) -> DispatchResult {1193 let sender = ensure_signed(origin)?;1196 let sender = ensure_signed(origin)?;1231 #[weight = T::WeightInfo::set_offchain_schema()]1234 #[weight = T::WeightInfo::set_offchain_schema()]1232 pub fn set_offchain_schema(1235 pub fn set_offchain_schema(1233 origin,1236 origin,1234 collection_id: u64,1237 collection_id: CollectionId,1235 schema: Vec<u8>1238 schema: Vec<u8>1236 ) -> DispatchResult {1239 ) -> DispatchResult {1237 let sender = ensure_signed(origin)?;1240 let sender = ensure_signed(origin)?;1259 #[weight = T::WeightInfo::set_const_on_chain_schema()]1262 #[weight = T::WeightInfo::set_const_on_chain_schema()]1260 pub fn set_const_on_chain_schema (1263 pub fn set_const_on_chain_schema (1261 origin,1264 origin,1262 collection_id: u64,1265 collection_id: CollectionId,1263 schema: Vec<u8>1266 schema: Vec<u8>1264 ) -> DispatchResult {1267 ) -> DispatchResult {1265 let sender = ensure_signed(origin)?;1268 let sender = ensure_signed(origin)?;1287 #[weight = T::WeightInfo::set_const_on_chain_schema()]1290 #[weight = T::WeightInfo::set_const_on_chain_schema()]1288 pub fn set_variable_on_chain_schema (1291 pub fn set_variable_on_chain_schema (1289 origin,1292 origin,1290 collection_id: u64,1293 collection_id: CollectionId,1291 schema: Vec<u8>1294 schema: Vec<u8>1292 ) -> DispatchResult {1295 ) -> DispatchResult {1293 let sender = ensure_signed(origin)?;1296 let sender = ensure_signed(origin)?;139613991397impl<T: Trait> Module<T> {1400impl<T: Trait> Module<T> {139814011399 fn can_create_items_in_collection(collection_id: u64, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1402 fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {140014031401 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {1404 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {1402 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1405 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1441 Ok(())1444 Ok(())1442 }1445 }144314461444 fn create_item_no_validation(collection_id: u64, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1447 fn create_item_no_validation(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1445 match data1448 match data1446 {1449 {1447 CreateItemData::NFT(data) => {1450 CreateItemData::NFT(data) => {1565 }1568 }156615691567 fn burn_refungible_item(1570 fn burn_refungible_item(1568 collection_id: u64,1571 collection_id: CollectionId,1569 item_id: u64,1572 item_id: TokenId,1570 owner: T::AccountId,1573 owner: T::AccountId,1571 ) -> DispatchResult {1574 ) -> DispatchResult {1572 ensure!(1575 ensure!(1596 Ok(())1599 Ok(())1597 }1600 }159816011599 fn burn_nft_item(collection_id: u64, item_id: u64) -> DispatchResult {1602 fn burn_nft_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {1600 ensure!(1603 ensure!(1601 <NftItemList<T>>::contains_key(collection_id, item_id),1604 <NftItemList<T>>::contains_key(collection_id, item_id),1602 Error::<T>::TokenNotFound1605 Error::<T>::TokenNotFound1617 Ok(())1620 Ok(())1618 }1621 }161916221620 fn burn_fungible_item(collection_id: u64, item_id: u64) -> DispatchResult {1623 fn burn_fungible_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {1621 ensure!(1624 ensure!(1622 <FungibleItemList<T>>::contains_key(collection_id, item_id),1625 <FungibleItemList<T>>::contains_key(collection_id, item_id),1623 Error::<T>::TokenNotFound1626 Error::<T>::TokenNotFound1639 Ok(())1642 Ok(())1640 }1643 }164116441642 fn collection_exists(collection_id: u64) -> DispatchResult {1645 fn collection_exists(collection_id: CollectionId) -> DispatchResult {1643 ensure!(1646 ensure!(1644 <Collection<T>>::contains_key(collection_id),1647 <Collection<T>>::contains_key(collection_id),1645 Error::<T>::CollectionNotFound1648 Error::<T>::CollectionNotFound1646 );1649 );1647 Ok(())1650 Ok(())1648 }1651 }164916521650 fn check_owner_permissions(collection_id: u64, subject: T::AccountId) -> DispatchResult {1653 fn check_owner_permissions(collection_id: CollectionId, subject: T::AccountId) -> DispatchResult {1651 Self::collection_exists(collection_id)?;1654 Self::collection_exists(collection_id)?;165216551653 let target_collection = <Collection<T>>::get(collection_id);1656 let target_collection = <Collection<T>>::get(collection_id);1659 Ok(())1662 Ok(())1660 }1663 }166116641662 fn is_owner_or_admin_permissions(collection_id: u64, subject: T::AccountId) -> bool {1665 fn is_owner_or_admin_permissions(collection_id: CollectionId, subject: T::AccountId) -> bool {1663 let target_collection = <Collection<T>>::get(collection_id);1666 let target_collection = <Collection<T>>::get(collection_id);1664 let mut result: bool = subject == target_collection.owner;1667 let mut result: bool = subject == target_collection.owner;1665 let exists = <AdminList<T>>::contains_key(collection_id);1668 let exists = <AdminList<T>>::contains_key(collection_id);1674 }1677 }167516781676 fn check_owner_or_admin_permissions(1679 fn check_owner_or_admin_permissions(1677 collection_id: u64,1680 collection_id: CollectionId,1678 subject: T::AccountId,1681 subject: T::AccountId,1679 ) -> DispatchResult {1682 ) -> DispatchResult {1680 Self::collection_exists(collection_id)?;1683 Self::collection_exists(collection_id)?;1687 Ok(())1690 Ok(())1688 }1691 }168916921690 fn is_item_owner(subject: T::AccountId, collection_id: u64, item_id: u64) -> bool {1693 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1691 let target_collection = <Collection<T>>::get(collection_id);1694 let target_collection = <Collection<T>>::get(collection_id);169216951693 match target_collection.mode {1696 match target_collection.mode {1707 }1710 }1708 }1711 }170917121710 fn check_white_list(collection_id: u64, address: &T::AccountId) -> DispatchResult {1713 fn check_white_list(collection_id: CollectionId, address: &T::AccountId) -> DispatchResult {1711 let mes = Error::<T>::AddresNotInWhiteList;1714 let mes = Error::<T>::AddresNotInWhiteList;1712 ensure!(<WhiteList<T>>::contains_key(collection_id), mes);1715 ensure!(<WhiteList<T>>::contains_key(collection_id), mes);1713 let wl = <WhiteList<T>>::get(collection_id);1716 let wl = <WhiteList<T>>::get(collection_id);1717 }1720 }171817211719 fn transfer_fungible(1722 fn transfer_fungible(1720 collection_id: u64,1723 collection_id: CollectionId,1721 item_id: u64,1724 item_id: TokenId,1722 value: u64,1725 value: u64,1723 owner: T::AccountId,1726 owner: T::AccountId,1724 new_owner: T::AccountId,1727 new_owner: T::AccountId,1806 }1809 }180718101808 fn transfer_refungible(1811 fn transfer_refungible(1809 collection_id: u64,1812 collection_id: CollectionId,1810 item_id: u64,1813 item_id: TokenId,1811 value: u64,1814 value: u64,1812 owner: T::AccountId,1815 owner: T::AccountId,1813 new_owner: T::AccountId,1816 new_owner: T::AccountId,1892 }1895 }189318961894 fn transfer_nft(1897 fn transfer_nft(1895 collection_id: u64,1898 collection_id: CollectionId,1896 item_id: u64,1899 item_id: TokenId,1897 sender: T::AccountId,1900 sender: T::AccountId,1898 new_owner: T::AccountId,1901 new_owner: T::AccountId,1899 ) -> DispatchResult {1902 ) -> DispatchResult {1934 }1937 }1935 1938 1936 fn item_exists(1939 fn item_exists(1937 collection_id: u64,1940 collection_id: CollectionId,1938 item_id: u64,1941 item_id: TokenId,1939 mode: &CollectionMode1942 mode: &CollectionMode1940 ) -> DispatchResult {1943 ) -> DispatchResult {1941 match mode {1944 match mode {1949 }1952 }195019531951 fn set_re_fungible_variable_data(1954 fn set_re_fungible_variable_data(1952 collection_id: u64,1955 collection_id: CollectionId,1953 item_id: u64,1956 item_id: TokenId,1954 data: Vec<u8>1957 data: Vec<u8>1955 ) -> DispatchResult {1958 ) -> DispatchResult {1956 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id);1959 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id);1963 }1966 }196419671965 fn set_nft_variable_data(1968 fn set_nft_variable_data(1966 collection_id: u64,1969 collection_id: CollectionId,1967 item_id: u64,1970 item_id: TokenId,1968 data: Vec<u8>1971 data: Vec<u8>1969 ) -> DispatchResult {1972 ) -> DispatchResult {1970 let mut item = <NftItemList<T>>::get(collection_id, item_id);1973 let mut item = <NftItemList<T>>::get(collection_id, item_id);2058 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2061 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2059 }2062 }206020632061 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {2064 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {206220652063 // add to account limit2066 // add to account limit2064 if <AccountItemCount<T>>::contains_key(owner.clone()) {2067 if <AccountItemCount<T>>::contains_key(owner.clone()) {2096 }2099 }209721002098 fn remove_token_index(2101 fn remove_token_index(2099 collection_id: u64,2102 collection_id: CollectionId,2100 item_index: u64,2103 item_index: TokenId,2101 owner: T::AccountId,2104 owner: T::AccountId,2102 ) -> DispatchResult {2105 ) -> DispatchResult {210321062123 }2126 }212421272125 fn move_token_index(2128 fn move_token_index(2126 collection_id: u64,2129 collection_id: CollectionId,2127 item_index: u64,2130 item_index: TokenId,2128 old_owner: T::AccountId,2131 old_owner: T::AccountId,2129 new_owner: T::AccountId,2132 new_owner: T::AccountId,2130 ) -> DispatchResult {2133 ) -> DispatchResult {pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -2,11 +2,12 @@
use super::*;
use crate::mock::*;
use crate::{AccessMode, ApprovePermissions, CollectionMode,
- Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData}; //Err
+ Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,
+ CollectionId, TokenId}; //Err
use frame_support::{assert_noop, assert_ok};
use frame_system::{ RawOrigin };
-fn default_collection_numbers_limit() -> u64 {
+fn default_collection_numbers_limit() -> u32 {
10
}
@@ -34,7 +35,7 @@
CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }
}
-fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: u64) -> u64 {
+fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {
let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
@@ -59,11 +60,11 @@
id
}
-fn create_test_collection(mode: &CollectionMode, id: u64) -> u64 {
+fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {
create_test_collection_for_owner(&mode, 1, id)
}
-fn create_test_item(collection_id: u64, data: &CreateItemData) {
+fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::create_item(
origin1.clone(),
@@ -109,8 +110,8 @@
items_data.clone().into_iter().map(|d| { d.into() }).collect()
));
for (index, data) in items_data.iter().enumerate() {
- assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as u64).const_data.to_vec(), data.const_data);
- assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as u64).variable_data.to_vec(), data.variable_data);
+ assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).const_data.to_vec(), data.const_data);
+ assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).variable_data.to_vec(), data.variable_data);
}
});
}
@@ -160,7 +161,7 @@
));
for (index, data) in items_data.iter().enumerate() {
- let item = TemplateModule::refungible_item_id(1, (index + 1) as u64);
+ let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId);
assert_eq!(item.const_data.to_vec(), data.const_data);
assert_eq!(item.variable_data.to_vec(), data.variable_data);
assert_eq!(
@@ -207,7 +208,7 @@
));
for (index, _) in items_data.iter().enumerate() {
- assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as u64).owner, 1);
+ assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).owner, 1);
}
assert_eq!(TemplateModule::balance_count(1, 1), 3000);
assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);