difftreelog
Merge pull request #31 from usetech-llc/feature/NFTPAR-183
in: master
Feature/NFTPAR-183 Storage Refactoring.
3 files changed
README.mddiffbeforeafterboth--- a/README.md
+++ b/README.md
@@ -164,12 +164,13 @@
"WhiteList"
]
},
+ "DecimalPoints": "u8",
"CollectionMode": {
"_enum": {
"Invalid": null,
"NFT": null,
- "Fungible": "u32",
- "ReFungible": "u32"
+ "Fungible": "DecimalPoints",
+ "ReFungible": "DecimalPoints"
}
},
"Ownership": {
@@ -177,17 +178,17 @@
"Fraction": "u128"
},
"FungibleItemType": {
- "Collection": "u64",
+ "Collection": "CollectionId",
"Owner": "AccountId",
"Value": "u128"
},
"ReFungibleItemType": {
- "Collection": "u64",
+ "Collection": "CollectionId",
"Owner": "Vec<Ownership>",
"Data": "Vec<u8>"
},
"NftItemType": {
- "Collection": "u64",
+ "Collection": "CollectionId",
"Owner": "AccountId",
"ConstData": "Vec<u8>",
"VariableData": "Vec<u8>"
@@ -197,7 +198,7 @@
"fraction": "u128"
},
"ReFungibleItemType": {
- "Collection": "u64",
+ "Collection": "CollectionId",
"Owner": "Vec<Ownership<AccountId>>",
"ConstData": "Vec<u8>",
"VariableData": "Vec<u8>"
@@ -206,7 +207,7 @@
"Owner": "AccountId",
"Mode": "CollectionMode",
"Access": "AccessMode",
- "DecimalPoints": "u32",
+ "DecimalPoints": "DecimalPoints",
"Name": "Vec<u16>",
"Description": "Vec<u16>",
"TokenPrefix": "Vec<u8>",
@@ -219,7 +220,7 @@
},
"ApprovePermissions": {
"Approved": "AccountId",
- "Amount": "u64"
+ "Amount": "u128"
},
"RawData": "Vec<u8>",
"Address": "AccountId",
@@ -240,7 +241,9 @@
"Fungible": "CreateFungibleData",
"ReFungible": "CreateReFungibleData"
}
- }
+ },
+ "CollectionId": "u32",
+ "TokenId": "u32"
}
```
\ No newline at end of file
pallets/nft/src/lib.rsdiffbeforeafterboth454546mod default_weights;46mod default_weights;4748pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;474948// Structs50// Structs49// #region51// #region5253pub type CollectionId = u32;54pub type TokenId = u32;5556pub type DecimalPoints = u8;505751#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]58#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]52#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]59#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]53pub enum CollectionMode {60pub enum CollectionMode {54 Invalid,61 Invalid,55 NFT,62 NFT,56 // decimal points63 // decimal points57 Fungible(u32),64 Fungible(DecimalPoints),58 // decimal points65 // decimal points59 ReFungible(u32),66 ReFungible(DecimalPoints),60}67}616862impl Into<u8> for CollectionMode {69impl Into<u8> for CollectionMode {101 pub owner: AccountId,108 pub owner: AccountId,102 pub mode: CollectionMode,109 pub mode: CollectionMode,103 pub access: AccessMode,110 pub access: AccessMode,104 pub decimal_points: u32,111 pub decimal_points: DecimalPoints,105 pub name: Vec<u16>, // 64 include null escape char112 pub name: Vec<u16>, // 64 include null escape char106 pub description: Vec<u16>, // 256 include null escape char113 pub description: Vec<u16>, // 256 include null escape char107 pub token_prefix: Vec<u8>, // 16 include null escape char114 pub token_prefix: Vec<u8>, // 16 include null escape char116#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]123#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]117#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]124#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]118pub struct NftItemType<AccountId> {125pub struct NftItemType<AccountId> {119 pub collection: u64,126 pub collection: CollectionId,120 pub owner: AccountId,127 pub owner: AccountId,121 pub const_data: Vec<u8>,128 pub const_data: Vec<u8>,122 pub variable_data: Vec<u8>,129 pub variable_data: Vec<u8>,125#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]132#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]126#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]133#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]127pub struct FungibleItemType<AccountId> {134pub struct FungibleItemType<AccountId> {128 pub collection: u64,135 pub collection: CollectionId,129 pub owner: AccountId,136 pub owner: AccountId,130 pub value: u128,137 pub value: u128,131}138}132139133#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]140#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]134#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]141#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]135pub struct ReFungibleItemType<AccountId> {142pub struct ReFungibleItemType<AccountId> {136 pub collection: u64,143 pub collection: CollectionId,137 pub owner: Vec<Ownership<AccountId>>,144 pub owner: Vec<Ownership<AccountId>>,138 pub const_data: Vec<u8>,145 pub const_data: Vec<u8>,139 pub variable_data: Vec<u8>,146 pub variable_data: Vec<u8>,143#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]150#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]144pub struct ApprovePermissions<AccountId> {151pub struct ApprovePermissions<AccountId> {145 pub approved: AccountId,152 pub approved: AccountId,146 pub amount: u64,153 pub amount: u128,147}154}148155149#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]156#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]150#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]157#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]151pub struct VestingItem<AccountId, Moment> {158pub struct VestingItem<AccountId, Moment> {152 pub sender: AccountId,159 pub sender: AccountId,153 pub recipient: AccountId,160 pub recipient: AccountId,154 pub collection_id: u64,161 pub collection_id: CollectionId,155 pub item_id: u64,162 pub item_id: TokenId,156 pub amount: u64,163 pub amount: u64,157 pub vesting_date: Moment,164 pub vesting_date: Moment,158}165}167#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]174#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]168#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]175#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]169pub struct ChainLimits {176pub struct ChainLimits {170 pub collection_numbers_limit: u64,177 pub collection_numbers_limit: u32,171 pub account_token_ownership_limit: u64,178 pub account_token_ownership_limit: u32,172 pub collections_admins_limit: u64,179 pub collections_admins_limit: u64,173 pub custom_data_limit: u32,180 pub custom_data_limit: u32,174181266 pub enum Error for Module<T: Trait> {273 pub enum Error for Module<T: Trait> {267 /// Total collections bound exceeded.274 /// Total collections bound exceeded.268 TotalCollectionsLimitExceeded,275 TotalCollectionsLimitExceeded,269 /// Decimal_points parameter must be lower than 4.276 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.270 CollectionDecimalPointLimitExceeded, 277 CollectionDecimalPointLimitExceeded, 271 /// Collection name can not be longer than 63 char.278 /// Collection name can not be longer than 63 char.272 CollectionNameLimitExceeded, 279 CollectionNameLimitExceeded, 341 trait Store for Module<T: Trait> as Nft {348 trait Store for Module<T: Trait> as Nft {342349343 // Private members350 // Private members344 NextCollectionID: u64;351 NextCollectionID: CollectionId;345 CreatedCollectionCount: u64;352 CreatedCollectionCount: u32;346 ChainVersion: u64;353 ChainVersion: u64;347 ItemListIndex: map hasher(blake2_128_concat) u64 => u64;354 ItemListIndex: map hasher(identity) CollectionId => TokenId;348355349 // Chain limits struct356 // Chain limits struct350 pub ChainLimit get(fn chain_limit) config(): ChainLimits;357 pub ChainLimit get(fn chain_limit) config(): ChainLimits;351358352 // Bound counters359 // Bound counters353 CollectionCount: u64;360 CollectionCount: u32;354 pub AccountItemCount get(fn account_item_count): map hasher(identity) T::AccountId => u64;361 pub AccountItemCount get(fn account_item_count): map hasher(twox_64_concat) T::AccountId => u32;355362356 // Basic collections363 // Basic collections357 pub Collection get(fn collection) config(): map hasher(identity) u64 => CollectionType<T::AccountId>;364 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>;365 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>;366 pub WhiteList get(fn white_list): map hasher(identity) CollectionId => Vec<T::AccountId>;360367361 /// Balance owner per collection map368 /// 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;369 pub Balance get(fn balance_count): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => u128;363370364 /// second parameter: item id + owner account id371 /// 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>>;372 pub ApprovedList get(fn approved): double_map hasher(identity) CollectionId, hasher(twox_64_concat) (TokenId, T::AccountId) => Vec<ApprovePermissions<T::AccountId>>;366373367 /// Item collections374 /// 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>;375 pub NftItemList get(fn nft_item_id) config(): double_map hasher(identity) CollectionId, hasher(identity) 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>;376 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(identity) CollectionId, hasher(identity) 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>;377 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(identity) CollectionId, hasher(identity) TokenId => ReFungibleItemType<T::AccountId>;371378372 /// Index list379 /// Index list373 pub AddressTokens get(fn address_tokens): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) T::AccountId => Vec<u64>;380 pub AddressTokens get(fn address_tokens): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => Vec<TokenId>;374381375 /// Tokens transfer baskets382 /// Tokens transfer baskets376 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;383 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) 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>>;384 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) 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;385 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;379386380 // Contract Sponsorship and Ownership387 // Contract Sponsorship and Ownership381 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;388 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;419 /// * mode: [CollectionMode] converted into u8.426 /// * mode: [CollectionMode] converted into u8.420 /// 427 /// 421 /// * account_id: Collection owner.428 /// * account_id: Collection owner.422 Created(u64, u8, AccountId),429 Created(CollectionId, u8, AccountId),423430424 /// New item was created.431 /// New item was created.425 /// 432 /// 428 /// * collection_id: Id of the collection where item was created.435 /// * collection_id: Id of the collection where item was created.429 /// 436 /// 430 /// * item_id: Id of an item. Unique within the collection.437 /// * item_id: Id of an item. Unique within the collection.431 ItemCreated(u64, u64),438 ItemCreated(CollectionId, TokenId),432439433 /// Collection item was burned.440 /// Collection item was burned.434 /// 441 /// 437 /// collection_id.444 /// collection_id.438 /// 445 /// 439 /// item_id: Identifier of burned NFT.446 /// item_id: Identifier of burned NFT.440 ItemDestroyed(u64, u64),447 ItemDestroyed(CollectionId, TokenId),441 }448 }442);449);443450495 ensure!(CollectionCount::get() < ChainLimit::get().collection_numbers_limit, Error::<T>::TotalCollectionsLimitExceeded);502 ensure!(CollectionCount::get() < ChainLimit::get().collection_numbers_limit, Error::<T>::TotalCollectionsLimitExceeded);496503497 // check params504 // check params498 ensure!(decimal_points <= 4, Error::<T>::CollectionDecimalPointLimitExceeded);505 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);499506500 let mut name = collection_name.to_vec();507 let mut name = collection_name.to_vec();501 name.push(0);508 name.push(0);558 /// 565 /// 559 /// * collection_id: collection to destroy.566 /// * collection_id: collection to destroy.560 #[weight = T::WeightInfo::destroy_collection()]567 #[weight = T::WeightInfo::destroy_collection()]561 pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {568 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {562569563 let sender = ensure_signed(origin)?;570 let sender = ensure_signed(origin)?;564 Self::check_owner_permissions(collection_id, sender)?;571 Self::check_owner_permissions(collection_id, sender)?;605 /// 612 /// 606 /// * address.613 /// * address.607 #[weight = T::WeightInfo::add_to_white_list()]614 #[weight = T::WeightInfo::add_to_white_list()]608 pub fn add_to_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{615 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{609616610 let sender = ensure_signed(origin)?;617 let sender = ensure_signed(origin)?;611 Self::check_owner_or_admin_permissions(collection_id, sender)?;618 Self::check_owner_or_admin_permissions(collection_id, sender)?;640 /// 647 /// 641 /// * address.648 /// * address.642 #[weight = T::WeightInfo::remove_from_white_list()]649 #[weight = T::WeightInfo::remove_from_white_list()]643 pub fn remove_from_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{650 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::AccountId) -> DispatchResult{644651645 let sender = ensure_signed(origin)?;652 let sender = ensure_signed(origin)?;646 Self::check_owner_or_admin_permissions(collection_id, sender)?;653 Self::check_owner_or_admin_permissions(collection_id, sender)?;669 /// 676 /// 670 /// * mode: [AccessMode]677 /// * mode: [AccessMode]671 #[weight = T::WeightInfo::set_public_access_mode()]678 #[weight = T::WeightInfo::set_public_access_mode()]672 pub fn set_public_access_mode(origin, collection_id: u64, mode: AccessMode) -> DispatchResult679 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult673 {680 {674 let sender = ensure_signed(origin)?;681 let sender = ensure_signed(origin)?;675682695 /// 702 /// 696 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.703 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.697 #[weight = T::WeightInfo::set_mint_permission()]704 #[weight = T::WeightInfo::set_mint_permission()]698 pub fn set_mint_permission(origin, collection_id: u64, mint_permission: bool) -> DispatchResult705 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult699 {706 {700 let sender = ensure_signed(origin)?;707 let sender = ensure_signed(origin)?;701708719 /// 726 /// 720 /// * new_owner.727 /// * new_owner.721 #[weight = T::WeightInfo::change_collection_owner()]728 #[weight = T::WeightInfo::change_collection_owner()]722 pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {729 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {723730724 let sender = ensure_signed(origin)?;731 let sender = ensure_signed(origin)?;725 Self::check_owner_permissions(collection_id, sender)?;732 Self::check_owner_permissions(collection_id, sender)?;744 /// 751 /// 745 /// * new_admin_id: Address of new admin to add.752 /// * new_admin_id: Address of new admin to add.746 #[weight = T::WeightInfo::add_collection_admin()]753 #[weight = T::WeightInfo::add_collection_admin()]747 pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {754 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::AccountId) -> DispatchResult {748755749 let sender = ensure_signed(origin)?;756 let sender = ensure_signed(origin)?;750 Self::check_owner_or_admin_permissions(collection_id, sender)?;757 Self::check_owner_or_admin_permissions(collection_id, sender)?;778 /// 785 /// 779 /// * account_id: Address of admin to remove.786 /// * account_id: Address of admin to remove.780 #[weight = T::WeightInfo::remove_collection_admin()]787 #[weight = T::WeightInfo::remove_collection_admin()]781 pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {788 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::AccountId) -> DispatchResult {782789783 let sender = ensure_signed(origin)?;790 let sender = ensure_signed(origin)?;784 Self::check_owner_or_admin_permissions(collection_id, sender)?;791 Self::check_owner_or_admin_permissions(collection_id, sender)?;803 /// 810 /// 804 /// * new_sponsor.811 /// * new_sponsor.805 #[weight = T::WeightInfo::set_collection_sponsor()]812 #[weight = T::WeightInfo::set_collection_sponsor()]806 pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {813 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {807814808 let sender = ensure_signed(origin)?;815 let sender = ensure_signed(origin)?;809 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);816 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);825 /// 832 /// 826 /// * collection_id.833 /// * collection_id.827 #[weight = T::WeightInfo::confirm_sponsorship()]834 #[weight = T::WeightInfo::confirm_sponsorship()]828 pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {835 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {829836830 let sender = ensure_signed(origin)?;837 let sender = ensure_signed(origin)?;831 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);838 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);850 /// 857 /// 851 /// * collection_id.858 /// * collection_id.852 #[weight = T::WeightInfo::remove_collection_sponsor()]859 #[weight = T::WeightInfo::remove_collection_sponsor()]853 pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {860 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {854861855 let sender = ensure_signed(origin)?;862 let sender = ensure_signed(origin)?;856 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);863 ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);889 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]896 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]890897891 #[weight = T::WeightInfo::create_item(data.len())]898 #[weight = T::WeightInfo::create_item(data.len())]892 pub fn create_item(origin, collection_id: u64, owner: T::AccountId, data: CreateItemData) -> DispatchResult {899 pub fn create_item(origin, collection_id: CollectionId, owner: T::AccountId, data: CreateItemData) -> DispatchResult {893900894 let sender = ensure_signed(origin)?;901 let sender = ensure_signed(origin)?;895902925 #[weight = T::WeightInfo::create_item(items_data.into_iter()932 #[weight = T::WeightInfo::create_item(items_data.into_iter()926 .map(|data| { data.len() })933 .map(|data| { data.len() })927 .sum())]934 .sum())]928 pub fn create_multiple_items(origin, collection_id: u64, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {935 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::AccountId, items_data: Vec<CreateItemData>) -> DispatchResult {929936930 ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);937 ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);931 let sender = ensure_signed(origin)?;938 let sender = ensure_signed(origin)?;959 /// 966 /// 960 /// * item_id: ID of NFT to burn.967 /// * item_id: ID of NFT to burn.961 #[weight = T::WeightInfo::burn_item()]968 #[weight = T::WeightInfo::burn_item()]962 pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {969 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {963970964 let sender = ensure_signed(origin)?;971 let sender = ensure_signed(origin)?;965 Self::collection_exists(collection_id)?;972 Self::collection_exists(collection_id)?;1012 /// * Fungible Mode: Must specify transferred amount1019 /// * Fungible Mode: Must specify transferred amount1013 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)1020 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)1014 #[weight = T::WeightInfo::transfer()]1021 #[weight = T::WeightInfo::transfer()]1015 pub fn transfer(origin, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {1022 pub fn transfer(origin, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {101610231017 let sender = ensure_signed(origin)?;1024 let sender = ensure_signed(origin)?;101810251054 /// 1061 /// 1055 /// * item_id: ID of the item.1062 /// * item_id: ID of the item.1056 #[weight = T::WeightInfo::approve()]1063 #[weight = T::WeightInfo::approve()]1057 pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {1064 pub fn approve(origin, approved: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> DispatchResult {105810651059 let sender = ensure_signed(origin)?;1066 let sender = ensure_signed(origin)?;106010671112 /// 1119 /// 1113 /// * value: Amount to transfer.1120 /// * value: Amount to transfer.1114 #[weight = T::WeightInfo::transfer_from()]1121 #[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 {1122 pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResult {111611231117 let sender = ensure_signed(origin)?;1124 let sender = ensure_signed(origin)?;1118 let mut appoved_transfer = false;1125 let mut appoved_transfer = false;115711641158 ///1165 ///1159 #[weight = 0]1166 #[weight = 0]1160 pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {1167 pub fn safe_transfer_from(origin, collection_id: CollectionId, item_id: TokenId, new_owner: T::AccountId) -> DispatchResult {116111681162 // let no_perm_mes = "You do not have permissions to modify this collection";1169 // 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);1170 // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);1186 #[weight = T::WeightInfo::set_variable_meta_data()]1193 #[weight = T::WeightInfo::set_variable_meta_data()]1187 pub fn set_variable_meta_data (1194 pub fn set_variable_meta_data (1188 origin,1195 origin,1189 collection_id: u64,1196 collection_id: CollectionId,1190 item_id: u64,1197 item_id: TokenId,1191 data: Vec<u8>1198 data: Vec<u8>1192 ) -> DispatchResult {1199 ) -> DispatchResult {1193 let sender = ensure_signed(origin)?;1200 let sender = ensure_signed(origin)?;1231 #[weight = T::WeightInfo::set_offchain_schema()]1238 #[weight = T::WeightInfo::set_offchain_schema()]1232 pub fn set_offchain_schema(1239 pub fn set_offchain_schema(1233 origin,1240 origin,1234 collection_id: u64,1241 collection_id: CollectionId,1235 schema: Vec<u8>1242 schema: Vec<u8>1236 ) -> DispatchResult {1243 ) -> DispatchResult {1237 let sender = ensure_signed(origin)?;1244 let sender = ensure_signed(origin)?;1259 #[weight = T::WeightInfo::set_const_on_chain_schema()]1266 #[weight = T::WeightInfo::set_const_on_chain_schema()]1260 pub fn set_const_on_chain_schema (1267 pub fn set_const_on_chain_schema (1261 origin,1268 origin,1262 collection_id: u64,1269 collection_id: CollectionId,1263 schema: Vec<u8>1270 schema: Vec<u8>1264 ) -> DispatchResult {1271 ) -> DispatchResult {1265 let sender = ensure_signed(origin)?;1272 let sender = ensure_signed(origin)?;1287 #[weight = T::WeightInfo::set_const_on_chain_schema()]1294 #[weight = T::WeightInfo::set_const_on_chain_schema()]1288 pub fn set_variable_on_chain_schema (1295 pub fn set_variable_on_chain_schema (1289 origin,1296 origin,1290 collection_id: u64,1297 collection_id: CollectionId,1291 schema: Vec<u8>1298 schema: Vec<u8>1292 ) -> DispatchResult {1299 ) -> DispatchResult {1293 let sender = ensure_signed(origin)?;1300 let sender = ensure_signed(origin)?;139614031397impl<T: Trait> Module<T> {1404impl<T: Trait> Module<T> {139814051399 fn can_create_items_in_collection(collection_id: u64, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {1406 fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult {140014071401 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {1408 if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {1402 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1409 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1441 Ok(())1448 Ok(())1442 }1449 }144314501444 fn create_item_no_validation(collection_id: u64, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1451 fn create_item_no_validation(collection_id: CollectionId, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {1445 match data1452 match data1446 {1453 {1447 CreateItemData::NFT(data) => {1454 CreateItemData::NFT(data) => {1458 let item = FungibleItemType {1465 let item = FungibleItemType {1459 collection: collection_id,1466 collection: collection_id,1460 owner,1467 owner,1461 value: (10 as u128).pow(collection.decimal_points)1468 value: (10 as u128).pow(collection.decimal_points as u32)1462 };1469 };146314701464 Self::add_fungible_item(item)?;1471 Self::add_fungible_item(item)?;1465 },1472 },1466 CreateItemData::ReFungible(data) => {1473 CreateItemData::ReFungible(data) => {1467 let mut owner_list = Vec::new();1474 let mut owner_list = Vec::new();1468 let value = (10 as u128).pow(collection.decimal_points);1475 let value = (10 as u128).pow(collection.decimal_points as u32);1469 owner_list.push(Ownership {owner: owner.clone(), fraction: value});1476 owner_list.push(Ownership {owner: owner.clone(), fraction: value});147014771471 let item = ReFungibleItemType {1478 let item = ReFungibleItemType {1492 .ok_or(Error::<T>::NumOverflow)?;1499 .ok_or(Error::<T>::NumOverflow)?;1493 let itemcopy = item.clone();1500 let itemcopy = item.clone();1494 let owner = item.owner.clone();1501 let owner = item.owner.clone();1495 let value = item.value as u64;149615021497 Self::add_token_index(item.collection, current_index, owner.clone())?;1503 Self::add_token_index(item.collection, current_index, owner.clone())?;149815041505 1511 1506 // Update balance1512 // Update balance1507 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1513 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1508 .checked_add(value)1514 .checked_add(item.value)1509 .ok_or(Error::<T>::NumOverflow)?;1515 .ok_or(Error::<T>::NumOverflow)?;1510 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);1516 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);151115171518 .ok_or(Error::<T>::NumOverflow)?;1524 .ok_or(Error::<T>::NumOverflow)?;1519 let itemcopy = item.clone();1525 let itemcopy = item.clone();152015261521 let value = item.owner.first().unwrap().fraction as u64;1527 let value = item.owner.first().unwrap().fraction;1522 let owner = item.owner.first().unwrap().owner.clone();1528 let owner = item.owner.first().unwrap().owner.clone();152315291524 Self::add_token_index(item.collection, current_index, owner.clone())?;1530 Self::add_token_index(item.collection, current_index, owner.clone())?;1565 }1571 }156615721567 fn burn_refungible_item(1573 fn burn_refungible_item(1568 collection_id: u64,1574 collection_id: CollectionId,1569 item_id: u64,1575 item_id: TokenId,1570 owner: T::AccountId,1576 owner: T::AccountId,1571 ) -> DispatchResult {1577 ) -> DispatchResult {1572 ensure!(1578 ensure!(158715931588 // update balance1594 // update balance1589 let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())1595 let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())1590 .checked_sub(item.fraction as u64)1596 .checked_sub(item.fraction)1591 .ok_or(Error::<T>::NumOverflow)?;1597 .ok_or(Error::<T>::NumOverflow)?;1592 <Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);1598 <Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);159315991596 Ok(())1602 Ok(())1597 }1603 }159816041599 fn burn_nft_item(collection_id: u64, item_id: u64) -> DispatchResult {1605 fn burn_nft_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {1600 ensure!(1606 ensure!(1601 <NftItemList<T>>::contains_key(collection_id, item_id),1607 <NftItemList<T>>::contains_key(collection_id, item_id),1602 Error::<T>::TokenNotFound1608 Error::<T>::TokenNotFound1617 Ok(())1623 Ok(())1618 }1624 }161916251620 fn burn_fungible_item(collection_id: u64, item_id: u64) -> DispatchResult {1626 fn burn_fungible_item(collection_id: CollectionId, item_id: TokenId) -> DispatchResult {1621 ensure!(1627 ensure!(1622 <FungibleItemList<T>>::contains_key(collection_id, item_id),1628 <FungibleItemList<T>>::contains_key(collection_id, item_id),1623 Error::<T>::TokenNotFound1629 Error::<T>::TokenNotFound163016361631 // update balance1637 // update balance1632 let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())1638 let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())1633 .checked_sub(item.value as u64)1639 .checked_sub(item.value)1634 .ok_or(Error::<T>::NumOverflow)?;1640 .ok_or(Error::<T>::NumOverflow)?;1635 <Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);1641 <Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);163616421639 Ok(())1645 Ok(())1640 }1646 }164116471642 fn collection_exists(collection_id: u64) -> DispatchResult {1648 fn collection_exists(collection_id: CollectionId) -> DispatchResult {1643 ensure!(1649 ensure!(1644 <Collection<T>>::contains_key(collection_id),1650 <Collection<T>>::contains_key(collection_id),1645 Error::<T>::CollectionNotFound1651 Error::<T>::CollectionNotFound1646 );1652 );1647 Ok(())1653 Ok(())1648 }1654 }164916551650 fn check_owner_permissions(collection_id: u64, subject: T::AccountId) -> DispatchResult {1656 fn check_owner_permissions(collection_id: CollectionId, subject: T::AccountId) -> DispatchResult {1651 Self::collection_exists(collection_id)?;1657 Self::collection_exists(collection_id)?;165216581653 let target_collection = <Collection<T>>::get(collection_id);1659 let target_collection = <Collection<T>>::get(collection_id);1659 Ok(())1665 Ok(())1660 }1666 }166116671662 fn is_owner_or_admin_permissions(collection_id: u64, subject: T::AccountId) -> bool {1668 fn is_owner_or_admin_permissions(collection_id: CollectionId, subject: T::AccountId) -> bool {1663 let target_collection = <Collection<T>>::get(collection_id);1669 let target_collection = <Collection<T>>::get(collection_id);1664 let mut result: bool = subject == target_collection.owner;1670 let mut result: bool = subject == target_collection.owner;1665 let exists = <AdminList<T>>::contains_key(collection_id);1671 let exists = <AdminList<T>>::contains_key(collection_id);1674 }1680 }167516811676 fn check_owner_or_admin_permissions(1682 fn check_owner_or_admin_permissions(1677 collection_id: u64,1683 collection_id: CollectionId,1678 subject: T::AccountId,1684 subject: T::AccountId,1679 ) -> DispatchResult {1685 ) -> DispatchResult {1680 Self::collection_exists(collection_id)?;1686 Self::collection_exists(collection_id)?;1687 Ok(())1693 Ok(())1688 }1694 }168916951690 fn is_item_owner(subject: T::AccountId, collection_id: u64, item_id: u64) -> bool {1696 fn is_item_owner(subject: T::AccountId, collection_id: CollectionId, item_id: TokenId) -> bool {1691 let target_collection = <Collection<T>>::get(collection_id);1697 let target_collection = <Collection<T>>::get(collection_id);169216981693 match target_collection.mode {1699 match target_collection.mode {1707 }1713 }1708 }1714 }170917151710 fn check_white_list(collection_id: u64, address: &T::AccountId) -> DispatchResult {1716 fn check_white_list(collection_id: CollectionId, address: &T::AccountId) -> DispatchResult {1711 let mes = Error::<T>::AddresNotInWhiteList;1717 let mes = Error::<T>::AddresNotInWhiteList;1712 ensure!(<WhiteList<T>>::contains_key(collection_id), mes);1718 ensure!(<WhiteList<T>>::contains_key(collection_id), mes);1713 let wl = <WhiteList<T>>::get(collection_id);1719 let wl = <WhiteList<T>>::get(collection_id);1717 }1723 }171817241719 fn transfer_fungible(1725 fn transfer_fungible(1720 collection_id: u64,1726 collection_id: CollectionId,1721 item_id: u64,1727 item_id: TokenId,1722 value: u64,1728 value: u128,1723 owner: T::AccountId,1729 owner: T::AccountId,1724 new_owner: T::AccountId,1730 new_owner: T::AccountId,1725 ) -> DispatchResult {1731 ) -> DispatchResult {1731 let full_item = <FungibleItemList<T>>::get(collection_id, item_id);1737 let full_item = <FungibleItemList<T>>::get(collection_id, item_id);1732 let amount = full_item.value;1738 let amount = full_item.value;173317391734 ensure!(amount >= value.into(), Error::<T>::TokenValueTooLow);1740 ensure!(amount >= value, Error::<T>::TokenValueTooLow);173517411736 // update balance1742 // update balance1737 let balance_old_owner = <Balance<T>>::get(collection_id, owner.clone())1743 let balance_old_owner = <Balance<T>>::get(collection_id, owner.clone())1745 new_owner_account_id = new_owner_items[0];1751 new_owner_account_id = new_owner_items[0];1746 }1752 }17471748 let val64 = value.into();174917531750 // transfer1754 // transfer1751 if amount == val64 && new_owner_account_id == 0 {1755 if amount == value && new_owner_account_id == 0 {1752 // change owner1756 // change owner1753 // new owner do not have account1757 // new owner do not have account1754 let mut new_full_item = full_item.clone();1758 let mut new_full_item = full_item.clone();1765 Self::move_token_index(collection_id, item_id, owner.clone(), new_owner.clone())?;1769 Self::move_token_index(collection_id, item_id, owner.clone(), new_owner.clone())?;1766 } else {1770 } else {1767 let mut new_full_item = full_item.clone();1771 let mut new_full_item = full_item.clone();1768 new_full_item.value -= val64;1772 new_full_item.value -= value;176917731770 // separate amount1774 // separate amount1771 if new_owner_account_id > 0 {1775 if new_owner_account_id > 0 {1772 // new owner has account1776 // new owner has account1773 let mut item = <FungibleItemList<T>>::get(collection_id, new_owner_account_id);1777 let mut item = <FungibleItemList<T>>::get(collection_id, new_owner_account_id);1774 item.value += val64;1778 item.value += value;177517791776 // update balance1780 // update balance1777 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())1781 let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())1785 let item = FungibleItemType {1789 let item = FungibleItemType {1786 collection: collection_id,1790 collection: collection_id,1787 owner: new_owner.clone(),1791 owner: new_owner.clone(),1788 value: val64,1792 value1789 };1793 };179017941791 Self::add_fungible_item(item)?;1795 Self::add_fungible_item(item)?;1792 }1796 }179317971794 if amount == val64 {1798 if amount == value {1795 Self::remove_token_index(collection_id, item_id, full_item.owner.clone())?;1799 Self::remove_token_index(collection_id, item_id, full_item.owner.clone())?;179618001797 // remove approve list1801 // remove approve list1806 }1810 }180718111808 fn transfer_refungible(1812 fn transfer_refungible(1809 collection_id: u64,1813 collection_id: CollectionId,1810 item_id: u64,1814 item_id: TokenId,1811 value: u64,1815 value: u128,1812 owner: T::AccountId,1816 owner: T::AccountId,1813 new_owner: T::AccountId,1817 new_owner: T::AccountId,1814 ) -> DispatchResult {1818 ) -> DispatchResult {1826 .ok_or(Error::<T>::NumOverflow)?;1830 .ok_or(Error::<T>::NumOverflow)?;1827 let amount = item.fraction;1831 let amount = item.fraction;182818321829 ensure!(amount >= value.into(), Error::<T>::TokenValueTooLow);1833 ensure!(amount >= value, Error::<T>::TokenValueTooLow);183018341831 // update balance1835 // update balance1832 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.clone())1836 let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.clone())184118451842 let old_owner = item.owner.clone();1846 let old_owner = item.owner.clone();1843 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);1847 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);1844 let val64 = value.into();184518481846 // transfer1849 // transfer1847 if amount == val64 && !new_owner_has_account {1850 if amount == value && !new_owner_has_account {1848 // change owner1851 // change owner1849 // new owner do not have account1852 // new owner do not have account1850 let mut new_full_item = full_item.clone();1853 let mut new_full_item = full_item.clone();1865 .iter_mut()1868 .iter_mut()1866 .find(|i| i.owner == owner)1869 .find(|i| i.owner == owner)1867 .unwrap()1870 .unwrap()1868 .fraction -= val64;1871 .fraction -= value;186918721870 // separate amount1873 // separate amount1871 if new_owner_has_account {1874 if new_owner_has_account {1875 .iter_mut()1878 .iter_mut()1876 .find(|i| i.owner == new_owner)1879 .find(|i| i.owner == new_owner)1877 .unwrap()1880 .unwrap()1878 .fraction += val64;1881 .fraction += value;1879 } else {1882 } else {1880 // new owner do not have account1883 // new owner do not have account1881 new_full_item.owner.push(Ownership {1884 new_full_item.owner.push(Ownership {1882 owner: new_owner.clone(),1885 owner: new_owner.clone(),1883 fraction: val64,1886 fraction: value,1884 });1887 });1885 Self::add_token_index(collection_id, item_id, new_owner.clone())?;1888 Self::add_token_index(collection_id, item_id, new_owner.clone())?;1886 }1889 }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);1979 fn init_collection(item: &CollectionType<T::AccountId>) {1982 fn init_collection(item: &CollectionType<T::AccountId>) {1980 // check params1983 // check params1981 assert!(1984 assert!(1982 item.decimal_points <= 4,1985 item.decimal_points <= MAX_DECIMAL_POINTS,1983 "decimal_points parameter must be lower than 4"1986 "decimal_points parameter must be lower than MAX_DECIMAL_POINTS"1984 );1987 );1985 assert!(1988 assert!(1986 item.name.len() <= 64,1989 item.name.len() <= 64,2026 .checked_add(1)2029 .checked_add(1)2027 .unwrap();2030 .unwrap();2028 let owner = item.owner.clone();2031 let owner = item.owner.clone();2029 let value = item.value as u64;203020322031 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2033 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();203220342033 <ItemListIndex>::insert(item.collection, current_index);2035 <ItemListIndex>::insert(item.collection, current_index);203420362035 // Update balance2037 // Update balance2036 let new_balance = <Balance<T>>::get(item.collection, owner.clone())2038 let new_balance = <Balance<T>>::get(item.collection, owner.clone())2037 .checked_add(value)2039 .checked_add(item.value)2038 .unwrap();2040 .unwrap();2039 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2041 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2040 }2042 }2044 .checked_add(1)2046 .checked_add(1)2045 .unwrap();2047 .unwrap();204620482047 let value = item.owner.first().unwrap().fraction as u64;2049 let value = item.owner.first().unwrap().fraction;2048 let owner = item.owner.first().unwrap().owner.clone();2050 let owner = item.owner.first().unwrap().owner.clone();204920512050 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2052 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2058 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2060 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2059 }2061 }206020622061 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {2063 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {206220642063 // add to account limit2065 // add to account limit2064 if <AccountItemCount<T>>::contains_key(owner.clone()) {2066 if <AccountItemCount<T>>::contains_key(owner.clone()) {2096 }2098 }209720992098 fn remove_token_index(2100 fn remove_token_index(2099 collection_id: u64,2101 collection_id: CollectionId,2100 item_index: u64,2102 item_index: TokenId,2101 owner: T::AccountId,2103 owner: T::AccountId,2102 ) -> DispatchResult {2104 ) -> DispatchResult {210321052123 }2125 }212421262125 fn move_token_index(2127 fn move_token_index(2126 collection_id: u64,2128 collection_id: CollectionId,2127 item_index: u64,2129 item_index: TokenId,2128 old_owner: T::AccountId,2130 old_owner: T::AccountId,2129 new_owner: T::AccountId,2131 new_owner: T::AccountId,2130 ) -> DispatchResult {2132 ) -> 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, MAX_DECIMAL_POINTS}; //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(),
@@ -77,6 +78,46 @@
// Use cases tests region
// #region
#[test]
+fn create_fungible_collection_fails_with_large_decimal_numbers() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ 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();
+
+ let origin1 = Origin::signed(1);
+ assert_noop!(TemplateModule::create_collection(
+ origin1,
+ col_name1,
+ col_desc1,
+ token_prefix1,
+ CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)
+ ), Error::<Test>::CollectionDecimalPointLimitExceeded);
+ });
+}
+
+#[test]
+fn create_re_fungible_collection_fails_with_large_decimal_numbers() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ 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();
+
+ let origin1 = Origin::signed(1);
+ assert_noop!(TemplateModule::create_collection(
+ origin1,
+ col_name1,
+ col_desc1,
+ token_prefix1,
+ CollectionMode::ReFungible(MAX_DECIMAL_POINTS + 1)
+ ), Error::<Test>::CollectionDecimalPointLimitExceeded);
+ });
+}
+
+#[test]
fn create_nft_item() {
new_test_ext().execute_with(|| {
default_limits();
@@ -109,8 +150,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 +201,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 +248,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]);