git.delta.rocks / unique-network / refs/commits / e7d3521284b7

difftreelog

NFTPAR-183: Storage Refactoring. Reduced collection id and token id from u64 to u32.

sotmorskiy2020-12-10parent: #68e6834.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -48,6 +48,9 @@
 // Structs
 // #region
 
+pub type CollectionId = u32;
+pub type TokenId = u32;
+
 #[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 pub enum CollectionMode {
@@ -116,7 +119,7 @@
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 pub struct NftItemType<AccountId> {
-    pub collection: u64,
+    pub collection: CollectionId,
     pub owner: AccountId,
     pub const_data: Vec<u8>,
     pub variable_data: Vec<u8>,
@@ -125,7 +128,7 @@
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 pub struct FungibleItemType<AccountId> {
-    pub collection: u64,
+    pub collection: CollectionId,
     pub owner: AccountId,
     pub value: u128,
 }
@@ -133,7 +136,7 @@
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 pub struct ReFungibleItemType<AccountId> {
-    pub collection: u64,
+    pub collection: CollectionId,
     pub owner: Vec<Ownership<AccountId>>,
     pub const_data: Vec<u8>,
     pub variable_data: Vec<u8>,
@@ -151,8 +154,8 @@
 pub struct VestingItem<AccountId, Moment> {
     pub sender: AccountId,
     pub recipient: AccountId,
-    pub collection_id: u64,
-    pub item_id: u64,
+    pub collection_id: CollectionId,
+    pub item_id: TokenId,
     pub amount: u64,
     pub vesting_date: Moment,
 }
@@ -167,8 +170,8 @@
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 pub struct ChainLimits {
-    pub collection_numbers_limit: u64,
-    pub account_token_ownership_limit: u64,
+    pub collection_numbers_limit: u32,
+    pub account_token_ownership_limit: u32,
     pub collections_admins_limit: u64,
     pub custom_data_limit: u32,
 
@@ -341,41 +344,41 @@
     trait Store for Module<T: Trait> as Nft {
 
         // Private members
-        NextCollectionID: u64;
-        CreatedCollectionCount: u64;
+        NextCollectionID: CollectionId;
+        CreatedCollectionCount: u32;
         ChainVersion: u64;
-        ItemListIndex: map hasher(blake2_128_concat) u64 => u64;
+        ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;
 
         // Chain limits struct
         pub ChainLimit get(fn chain_limit) config(): ChainLimits;
 
         // Bound counters
-        CollectionCount: u64;
-        pub AccountItemCount get(fn account_item_count): map hasher(identity) T::AccountId => u64;
+        CollectionCount: u32;
+        pub AccountItemCount get(fn account_item_count): map hasher(identity) T::AccountId => u32;
 
         // Basic collections
-        pub Collection get(fn collection) config(): map hasher(identity) u64 => CollectionType<T::AccountId>;
-        pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;
-        pub WhiteList get(fn white_list): map hasher(identity) u64 => Vec<T::AccountId>;
+        pub Collection get(fn collection) config(): map hasher(identity) CollectionId => CollectionType<T::AccountId>;
+        pub AdminList get(fn admin_list_collection): map hasher(identity) CollectionId => Vec<T::AccountId>;
+        pub WhiteList get(fn white_list): map hasher(identity) CollectionId => Vec<T::AccountId>;
 
         /// Balance owner per collection map
-        pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => u64;
+        pub Balance get(fn balance_count): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => u64;
 
         /// second parameter: item id + owner account id
-        pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) (u64, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;
+        pub ApprovedList get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;
 
         /// Item collections
-        pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => NftItemType<T::AccountId>;
-        pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => FungibleItemType<T::AccountId>;
-        pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => ReFungibleItemType<T::AccountId>;
+        pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => NftItemType<T::AccountId>;
+        pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => FungibleItemType<T::AccountId>;
+        pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => ReFungibleItemType<T::AccountId>;
 
         /// Index list
-        pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;
+        pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => Vec<TokenId>;
 
         /// Tokens transfer baskets
-        pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;
-        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>>;
-        pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;
+        pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;
+        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>>;
+        pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;
 
         // Contract Sponsorship and Ownership
         pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;
@@ -419,7 +422,7 @@
         /// * mode: [CollectionMode] converted into u8.
         /// 
         /// * account_id: Collection owner.
-        Created(u64, u8, AccountId),
+        Created(CollectionId, u8, AccountId),
 
         /// New item was created.
         /// 
@@ -428,7 +431,7 @@
         /// * collection_id: Id of the collection where item was created.
         /// 
         /// * item_id: Id of an item. Unique within the collection.
-        ItemCreated(u64, u64),
+        ItemCreated(CollectionId, TokenId),
 
         /// Collection item was burned.
         /// 
@@ -437,7 +440,7 @@
         /// collection_id.
         /// 
         /// item_id: Identifier of burned NFT.
-        ItemDestroyed(u64, u64),
+        ItemDestroyed(CollectionId, TokenId),
     }
 );
 
@@ -558,7 +561,7 @@
         /// 
         /// * collection_id: collection to destroy.
         #[weight = T::WeightInfo::destroy_collection()]
-        pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {
+        pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_permissions(collection_id, sender)?;
@@ -605,7 +608,7 @@
         /// 
         /// * address.
         #[weight = T::WeightInfo::add_to_white_list()]
-        pub fn add_to_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
+        pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_or_admin_permissions(collection_id, sender)?;
@@ -640,7 +643,7 @@
         /// 
         /// * address.
         #[weight = T::WeightInfo::remove_from_white_list()]
-        pub fn remove_from_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
+        pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_or_admin_permissions(collection_id, sender)?;
@@ -669,7 +672,7 @@
         /// 
         /// * mode: [AccessMode]
         #[weight = T::WeightInfo::set_public_access_mode()]
-        pub fn set_public_access_mode(origin, collection_id: u64, mode: AccessMode) -> DispatchResult
+        pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult
         {
             let sender = ensure_signed(origin)?;
 
@@ -695,7 +698,7 @@
         /// 
         /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.
         #[weight = T::WeightInfo::set_mint_permission()]
-        pub fn set_mint_permission(origin, collection_id: u64, mint_permission: bool) -> DispatchResult
+        pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult
         {
             let sender = ensure_signed(origin)?;
 
@@ -719,7 +722,7 @@
         /// 
         /// * new_owner.
         #[weight = T::WeightInfo::change_collection_owner()]
-        pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {
+        pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_permissions(collection_id, sender)?;
@@ -744,7 +747,7 @@
         /// 
         /// * new_admin_id: Address of new admin to add.
         #[weight = T::WeightInfo::add_collection_admin()]
-        pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {
+        pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_or_admin_permissions(collection_id, sender)?;
@@ -778,7 +781,7 @@
         /// 
         /// * account_id: Address of admin to remove.
         #[weight = T::WeightInfo::remove_collection_admin()]
-        pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {
+        pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             Self::check_owner_or_admin_permissions(collection_id, sender)?;
@@ -803,7 +806,7 @@
         /// 
         /// * new_sponsor.
         #[weight = T::WeightInfo::set_collection_sponsor()]
-        pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {
+        pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
@@ -825,7 +828,7 @@
         /// 
         /// * collection_id.
         #[weight = T::WeightInfo::confirm_sponsorship()]
-        pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {
+        pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
@@ -850,7 +853,7 @@
         /// 
         /// * collection_id.
         #[weight = T::WeightInfo::remove_collection_sponsor()]
-        pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {
+        pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
@@ -889,7 +892,7 @@
         // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
 
         #[weight = T::WeightInfo::create_item(data.len())]
-        pub fn create_item(origin, collection_id: u64, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
+        pub fn create_item(origin, collection_id: CollectionId, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
 
@@ -925,7 +928,7 @@
         #[weight = T::WeightInfo::create_item(items_data.into_iter()
                                .map(|data| { data.len() })
                                .sum())]
-        pub fn create_multiple_items(origin, collection_id: u64, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {
+        pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {
 
             ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);
             let sender = ensure_signed(origin)?;
@@ -959,7 +962,7 @@
         /// 
         /// * item_id: ID of NFT to burn.
         #[weight = T::WeightInfo::burn_item()]
-        pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {
+        pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             Self::collection_exists(collection_id)?;
@@ -1012,7 +1015,7 @@
         ///     * Fungible Mode: Must specify transferred amount
         ///     * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)
         #[weight = T::WeightInfo::transfer()]
-        pub fn transfer(origin, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {
+        pub fn transfer(origin, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u64) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
 
@@ -1054,7 +1057,7 @@
         /// 
         /// * item_id: ID of the item.
         #[weight = T::WeightInfo::approve()]
-        pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {
+        pub fn approve(origin, approved: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
 
@@ -1112,7 +1115,7 @@
         /// 
         /// * value: Amount to transfer.
         #[weight = T::WeightInfo::transfer_from()]
-        pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64 ) -> DispatchResult {
+        pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u64 ) -> DispatchResult {
 
             let sender = ensure_signed(origin)?;
             let mut appoved_transfer = false;
@@ -1157,7 +1160,7 @@
 
         ///
         #[weight = 0]
-        pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {
+        pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {
 
             // let no_perm_mes = "You do not have permissions to modify this collection";
             // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);
@@ -1186,8 +1189,8 @@
         #[weight = T::WeightInfo::set_variable_meta_data()]
         pub fn set_variable_meta_data (
             origin,
-            collection_id: u64,
-            item_id: u64,
+            collection_id: CollectionId,
+            item_id: TokenId,
             data: Vec<u8>
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
@@ -1231,7 +1234,7 @@
         #[weight = T::WeightInfo::set_offchain_schema()]
         pub fn set_offchain_schema(
             origin,
-            collection_id: u64,
+            collection_id: CollectionId,
             schema: Vec<u8>
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
@@ -1259,7 +1262,7 @@
         #[weight = T::WeightInfo::set_const_on_chain_schema()]
         pub fn set_const_on_chain_schema (
             origin,
-            collection_id: u64,
+            collection_id: CollectionId,
             schema: Vec<u8>
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
@@ -1287,7 +1290,7 @@
         #[weight = T::WeightInfo::set_const_on_chain_schema()]
         pub fn set_variable_on_chain_schema (
             origin,
-            collection_id: u64,
+            collection_id: CollectionId,
             schema: Vec<u8>
         ) -> DispatchResult {
             let sender = ensure_signed(origin)?;
@@ -1396,7 +1399,7 @@
 
 impl<T: Trait> Module<T> {
 
-    fn can_create_items_in_collection(collection_id: u64, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {
+    fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {
 
         if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {
             ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);
@@ -1441,7 +1444,7 @@
         Ok(())
     }
 
-    fn create_item_no_validation(collection_id: u64, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
+    fn create_item_no_validation(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
         match data
         {
             CreateItemData::NFT(data) => {
@@ -1565,8 +1568,8 @@
     }
 
     fn burn_refungible_item(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         owner: T::AccountId,
     ) -> DispatchResult {
         ensure!(
@@ -1596,7 +1599,7 @@
         Ok(())
     }
 
-    fn burn_nft_item(collection_id: u64, item_id: u64) -> DispatchResult {
+    fn burn_nft_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {
         ensure!(
             <NftItemList<T>>::contains_key(collection_id, item_id),
             Error::<T>::TokenNotFound
@@ -1617,7 +1620,7 @@
         Ok(())
     }
 
-    fn burn_fungible_item(collection_id: u64, item_id: u64) -> DispatchResult {
+    fn burn_fungible_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {
         ensure!(
             <FungibleItemList<T>>::contains_key(collection_id, item_id),
             Error::<T>::TokenNotFound
@@ -1639,7 +1642,7 @@
         Ok(())
     }
 
-    fn collection_exists(collection_id: u64) -> DispatchResult {
+    fn collection_exists(collection_id: CollectionId) -> DispatchResult {
         ensure!(
             <Collection<T>>::contains_key(collection_id),
             Error::<T>::CollectionNotFound
@@ -1647,7 +1650,7 @@
         Ok(())
     }
 
-    fn check_owner_permissions(collection_id: u64, subject: T::AccountId) -> DispatchResult {
+    fn check_owner_permissions(collection_id: CollectionId, subject: T::AccountId) -> DispatchResult {
         Self::collection_exists(collection_id)?;
 
         let target_collection = <Collection<T>>::get(collection_id);
@@ -1659,7 +1662,7 @@
         Ok(())
     }
 
-    fn is_owner_or_admin_permissions(collection_id: u64, subject: T::AccountId) -> bool {
+    fn is_owner_or_admin_permissions(collection_id: CollectionId, subject: T::AccountId) -> bool {
         let target_collection = <Collection<T>>::get(collection_id);
         let mut result: bool = subject == target_collection.owner;
         let exists = <AdminList<T>>::contains_key(collection_id);
@@ -1674,7 +1677,7 @@
     }
 
     fn check_owner_or_admin_permissions(
-        collection_id: u64,
+        collection_id: CollectionId,
         subject: T::AccountId,
     ) -> DispatchResult {
         Self::collection_exists(collection_id)?;
@@ -1687,7 +1690,7 @@
         Ok(())
     }
 
-    fn is_item_owner(subject: T::AccountId, collection_id: u64, item_id: u64) -> bool {
+    fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {
         let target_collection = <Collection<T>>::get(collection_id);
 
         match target_collection.mode {
@@ -1707,7 +1710,7 @@
         }
     }
 
-    fn check_white_list(collection_id: u64, address: &T::AccountId) -> DispatchResult {
+    fn check_white_list(collection_id: CollectionId, address: &T::AccountId) -> DispatchResult {
         let mes = Error::<T>::AddresNotInWhiteList;
         ensure!(<WhiteList<T>>::contains_key(collection_id), mes);
         let wl = <WhiteList<T>>::get(collection_id);
@@ -1717,8 +1720,8 @@
     }
 
     fn transfer_fungible(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         value: u64,
         owner: T::AccountId,
         new_owner: T::AccountId,
@@ -1806,8 +1809,8 @@
     }
 
     fn transfer_refungible(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         value: u64,
         owner: T::AccountId,
         new_owner: T::AccountId,
@@ -1892,8 +1895,8 @@
     }
 
     fn transfer_nft(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         sender: T::AccountId,
         new_owner: T::AccountId,
     ) -> DispatchResult {
@@ -1934,8 +1937,8 @@
     }
     
     fn item_exists(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         mode: &CollectionMode
     ) -> DispatchResult {
         match mode {
@@ -1949,8 +1952,8 @@
     }
 
     fn set_re_fungible_variable_data(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         data: Vec<u8>
     ) -> DispatchResult {
         let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id);
@@ -1963,8 +1966,8 @@
     }
 
     fn set_nft_variable_data(
-        collection_id: u64,
-        item_id: u64,
+        collection_id: CollectionId,
+        item_id: TokenId,
         data: Vec<u8>
     ) -> DispatchResult {
         let mut item = <NftItemList<T>>::get(collection_id, item_id);
@@ -2058,7 +2061,7 @@
         <Balance<T>>::insert(item.collection, owner.clone(), new_balance);
     }
 
-    fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {
+    fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {
 
         // add to account limit
         if <AccountItemCount<T>>::contains_key(owner.clone()) {
@@ -2096,8 +2099,8 @@
     }
 
     fn remove_token_index(
-        collection_id: u64,
-        item_index: u64,
+        collection_id: CollectionId,
+        item_index: TokenId,
         owner: T::AccountId,
     ) -> DispatchResult {
 
@@ -2123,8 +2126,8 @@
     }
 
     fn move_token_index(
-        collection_id: u64,
-        item_index: u64,
+        collection_id: CollectionId,
+        item_index: TokenId,
         old_owner: T::AccountId,
         new_owner: T::AccountId,
     ) -> DispatchResult {
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
2use super::*;2use super::*;
3use crate::mock::*;3use crate::mock::*;
4use crate::{AccessMode, ApprovePermissions, CollectionMode,4use crate::{AccessMode, ApprovePermissions, CollectionMode,
5 Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData}; //Err5 Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,
6 CollectionId, TokenId}; //Err
6use frame_support::{assert_noop, assert_ok};7use frame_support::{assert_noop, assert_ok};
7use frame_system::{ RawOrigin };8use frame_system::{ RawOrigin };
89
9fn default_collection_numbers_limit() -> u64 {10fn default_collection_numbers_limit() -> u32 {
10 1011 10
11}12}
1213
34 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }35 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }
35}36}
3637
37fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: u64) -> u64 {38fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {
38 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();39 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
39 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();40 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
40 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();41 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
59 id60 id
60}61}
6162
62fn create_test_collection(mode: &CollectionMode, id: u64) -> u64 {63fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {
63 create_test_collection_for_owner(&mode, 1, id)64 create_test_collection_for_owner(&mode, 1, id)
64}65}
6566
66fn create_test_item(collection_id: u64, data: &CreateItemData) {67fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {
67 let origin1 = Origin::signed(1);68 let origin1 = Origin::signed(1);
68 assert_ok!(TemplateModule::create_item(69 assert_ok!(TemplateModule::create_item(
69 origin1.clone(),70 origin1.clone(),
109 items_data.clone().into_iter().map(|d| { d.into() }).collect()110 items_data.clone().into_iter().map(|d| { d.into() }).collect()
110 ));111 ));
111 for (index, data) in items_data.iter().enumerate() {112 for (index, data) in items_data.iter().enumerate() {
112 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as u64).const_data.to_vec(), data.const_data);113 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).const_data.to_vec(), data.const_data);
113 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as u64).variable_data.to_vec(), data.variable_data);114 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).variable_data.to_vec(), data.variable_data);
114 }115 }
115 });116 });
116}117}
160 ));161 ));
161 for (index, data) in items_data.iter().enumerate() {162 for (index, data) in items_data.iter().enumerate() {
162163
163 let item = TemplateModule::refungible_item_id(1, (index + 1) as u64);164 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId);
164 assert_eq!(item.const_data.to_vec(), data.const_data);165 assert_eq!(item.const_data.to_vec(), data.const_data);
165 assert_eq!(item.variable_data.to_vec(), data.variable_data);166 assert_eq!(item.variable_data.to_vec(), data.variable_data);
166 assert_eq!(167 assert_eq!(
207 ));208 ));
208 209
209 for (index, _) in items_data.iter().enumerate() {210 for (index, _) in items_data.iter().enumerate() {
210 assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as u64).owner, 1);211 assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).owner, 1);
211 }212 }
212 assert_eq!(TemplateModule::balance_count(1, 1), 3000);213 assert_eq!(TemplateModule::balance_count(1, 1), 3000);
213 assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);214 assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);