difftreelog
Merge branch 'develop' into feature/NFTPAR-142
in: master
# Conflicts: # pallets/nft/src/lib.rs
5 files changed
pallets/nft/src/benchmarking.rsdiffbeforeafterboth1#[cfg(feature = "runtime-benchmarks")]2// mod benchmarking {3 use super::*;4 use sp_std::prelude::*;5 use frame_system::RawOrigin;6 // use frame_support::{ensure, traits::OnFinalize};7 use frame_benchmarking::{benchmarks, account, whitelisted_caller}; // , TrackedStorageKey, 8 use crate::Module as Nft;910 const SEED: u32 = 1;1112 fn default_nft_data() -> CreateItemData {13 CreateItemData::NFT(CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })14 }15 16 fn default_fungible_data () -> CreateItemData {17 CreateItemData::Fungible(CreateFungibleData { })18 }19 20 fn default_re_fungible_data () -> CreateItemData {21 CreateItemData::ReFungible(CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })22 }232425 benchmarks! {2627 _ {}2829 create_collection {30 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();31 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();32 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();33 let mode: CollectionMode = CollectionMode::NFT;34 let caller: T::AccountId = account("caller", 0, SEED);35 }: create_collection(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)36 verify {37 assert_eq!(Nft::<T>::collection(2).owner, caller);38 }3940 destroy_collection {41 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();42 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();43 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();44 let mode: CollectionMode = CollectionMode::NFT;45 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());46 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;47 }: destroy_collection(RawOrigin::Signed(caller.clone()), 2)4849 add_to_white_list {50 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();51 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();52 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();53 let mode: CollectionMode = CollectionMode::NFT;54 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());55 let whitelist_account: T::AccountId = account("admin", 0, SEED);56 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;57 }: add_to_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)5859 remove_from_white_list {60 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();61 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();62 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();63 let mode: CollectionMode = CollectionMode::NFT;64 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());65 let whitelist_account: T::AccountId = account("admin", 0, SEED);66 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;67 Nft::<T>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), 2, whitelist_account.clone())?;68 }: remove_from_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)6970 set_public_access_mode {71 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();72 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();73 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();74 let mode: CollectionMode = CollectionMode::NFT;75 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());76 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;77 }: set_public_access_mode(RawOrigin::Signed(caller.clone()), 2, AccessMode::WhiteList)7879 set_mint_permission {80 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();81 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();82 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();83 let mode: CollectionMode = CollectionMode::NFT;84 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());85 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;86 }: set_mint_permission(RawOrigin::Signed(caller.clone()), 2, true)8788 change_collection_owner {89 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();90 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();91 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();92 let mode: CollectionMode = CollectionMode::NFT;93 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());94 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;95 let new_owner: T::AccountId = account("admin", 0, SEED);96 }: change_collection_owner(RawOrigin::Signed(caller.clone()), 2, new_owner)9798 add_collection_admin {99 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();100 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();101 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();102 let mode: CollectionMode = CollectionMode::NFT;103 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());104 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;105 let new_admin: T::AccountId = account("admin", 0, SEED);106 }: add_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)107108 remove_collection_admin {109 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();110 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();111 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();112 let mode: CollectionMode = CollectionMode::NFT;113 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());114 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;115 let new_admin: T::AccountId = account("admin", 0, SEED);116 Nft::<T>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, new_admin.clone())?;117 }: remove_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)118119 set_collection_sponsor {120 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();121 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();122 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();123 let mode: CollectionMode = CollectionMode::NFT;124 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());125 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;126 }: set_collection_sponsor(RawOrigin::Signed(caller.clone()), 2, caller.clone())127128 confirm_sponsorship {129 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();130 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();131 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();132 let mode: CollectionMode = CollectionMode::NFT;133 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());134 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;135 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;136 }: confirm_sponsorship(RawOrigin::Signed(caller.clone()), 2)137138 remove_collection_sponsor {139 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();140 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();141 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();142 let mode: CollectionMode = CollectionMode::NFT;143 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());144 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;145 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;146 Nft::<T>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;147 }: remove_collection_sponsor(RawOrigin::Signed(caller.clone()), 2)148149 // nft item150 create_item_nft {151 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();152 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();153 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();154 let mode: CollectionMode = CollectionMode::NFT;155 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());156 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;157 let data = default_nft_data();158 159 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)160161 #[extra]162 create_item_nft_large {163 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();164 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();165 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();166 let mode: CollectionMode = CollectionMode::NFT;167 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());168 let nft_data = CreateNftData {169 const_data: vec![],170 variable_data: vec![]171 };172 for i in 0..1998 {173 nft_data.const_data.push(10);174 nft_data.variable_data.push(10);175 }176 let mut data = CreateItemData::NFT(nft_data);177 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;178179 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)180181 // fungible item182 create_item_fungible {183 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();184 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();185 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();186 let mode: CollectionMode = CollectionMode::Fungible(3);187 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());188 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;189 let data = default_fungible_data();190191 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)192193 // refungible item194 create_item_refungible {195 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();196 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();197 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();198 let mode: CollectionMode = CollectionMode::ReFungible(3);199 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());200 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;201 let data = default_re_fungible_data();202203 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)204205 burn_item {206 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();207 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();208 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();209 let mode: CollectionMode = CollectionMode::NFT;210 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());211 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;212 let data = default_nft_data();213 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;214215 }: burn_item(RawOrigin::Signed(caller.clone()), 2, 1)216217 transfer_nft {218 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();219 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();220 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();221 let mode: CollectionMode = CollectionMode::NFT;222 let recipient: T::AccountId = account("recipient", 0, SEED);223 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());224 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;225 let data = default_nft_data();226 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;227228 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)229 230 transfer_fungible {231 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();232 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();233 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();234 let mode: CollectionMode = CollectionMode::Fungible(3);235 let recipient: T::AccountId = account("recipient", 0, SEED);236 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());237 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;238 let data = default_fungible_data();239 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;240241 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)242243 transfer_refungible {244 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();245 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();246 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();247 let mode: CollectionMode = CollectionMode::ReFungible(3);248 let recipient: T::AccountId = account("recipient", 0, SEED);249 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());250 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;251 let data = default_re_fungible_data();252 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;253254 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)255256 approve {257 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();258 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();259 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();260 let mode: CollectionMode = CollectionMode::ReFungible(3);261 let recipient: T::AccountId = account("recipient", 0, SEED);262 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());263 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;264 let data = default_re_fungible_data();265 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;266267 }: approve(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1)268269 // Nft270 transfer_from_nft {271 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();272 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();273 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();274 let mode: CollectionMode = CollectionMode::NFT;275 let recipient: T::AccountId = account("recipient", 0, SEED);276 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());277 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;278 let data = default_nft_data();279 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;280 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;281282 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)283284 // Fungible285 transfer_from_fungible {286 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();287 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();288 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();289 let mode: CollectionMode = CollectionMode::Fungible(3);290 let recipient: T::AccountId = account("recipient", 0, SEED);291 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());292 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;293 let data = default_fungible_data();294 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;295 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;296297 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)298299 // ReFungible300 transfer_from_refungible {301 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();302 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();303 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();304 let mode: CollectionMode = CollectionMode::ReFungible(3);305 let recipient: T::AccountId = account("recipient", 0, SEED);306 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());307 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;308 let data = default_re_fungible_data();309 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;310 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;311312 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)313314 set_offchain_schema {315 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();316 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();317 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();318 let mode: CollectionMode = CollectionMode::ReFungible(3);319 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());320 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;321322 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())323324 set_const_on_chain_schema {325 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();326 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();327 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();328 let mode: CollectionMode = CollectionMode::ReFungible(3);329 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());330 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;331 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())332 333 set_variable_on_chain_schema {334 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();335 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();336 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();337 let mode: CollectionMode = CollectionMode::ReFungible(3);338 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());339 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;340 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())341342 set_variable_meta_data {343 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();344 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();345 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();346 let mode: CollectionMode = CollectionMode::NFT;347 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());348 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;349 let data = default_nft_data();350 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;351352 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())353}1#[cfg(feature = "runtime-benchmarks")]2// mod benchmarking {3 use super::*;4 use sp_std::prelude::*;5 use frame_system::RawOrigin;6 // use frame_support::{ensure, traits::OnFinalize};7 use frame_benchmarking::{benchmarks, account, whitelisted_caller}; // , TrackedStorageKey, 8 use crate::Module as Nft;910 const SEED: u32 = 1;1112 fn default_nft_data() -> CreateItemData {13 CreateItemData::NFT(CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })14 }15 16 fn default_fungible_data () -> CreateItemData {17 CreateItemData::Fungible(CreateFungibleData { })18 }19 20 fn default_re_fungible_data () -> CreateItemData {21 CreateItemData::ReFungible(CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })22 }232425 benchmarks! {2627 _ {}2829 create_collection {30 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();31 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();32 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();33 let mode: CollectionMode = CollectionMode::NFT;34 let caller: T::AccountId = account("caller", 0, SEED);35 }: create_collection(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)36 verify {37 assert_eq!(Nft::<T>::collection(2).owner, caller);38 }3940 destroy_collection {41 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();42 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();43 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();44 let mode: CollectionMode = CollectionMode::NFT;45 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());46 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;47 }: destroy_collection(RawOrigin::Signed(caller.clone()), 2)4849 add_to_white_list {50 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();51 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();52 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();53 let mode: CollectionMode = CollectionMode::NFT;54 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());55 let whitelist_account: T::AccountId = account("admin", 0, SEED);56 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;57 }: add_to_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)5859 remove_from_white_list {60 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();61 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();62 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();63 let mode: CollectionMode = CollectionMode::NFT;64 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());65 let whitelist_account: T::AccountId = account("admin", 0, SEED);66 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;67 Nft::<T>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), 2, whitelist_account.clone())?;68 }: remove_from_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)6970 set_public_access_mode {71 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();72 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();73 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();74 let mode: CollectionMode = CollectionMode::NFT;75 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());76 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;77 }: set_public_access_mode(RawOrigin::Signed(caller.clone()), 2, AccessMode::WhiteList)7879 set_mint_permission {80 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();81 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();82 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();83 let mode: CollectionMode = CollectionMode::NFT;84 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());85 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;86 }: set_mint_permission(RawOrigin::Signed(caller.clone()), 2, true)8788 change_collection_owner {89 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();90 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();91 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();92 let mode: CollectionMode = CollectionMode::NFT;93 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());94 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;95 let new_owner: T::AccountId = account("admin", 0, SEED);96 }: change_collection_owner(RawOrigin::Signed(caller.clone()), 2, new_owner)9798 add_collection_admin {99 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();100 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();101 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();102 let mode: CollectionMode = CollectionMode::NFT;103 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());104 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;105 let new_admin: T::AccountId = account("admin", 0, SEED);106 }: add_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)107108 remove_collection_admin {109 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();110 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();111 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();112 let mode: CollectionMode = CollectionMode::NFT;113 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());114 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;115 let new_admin: T::AccountId = account("admin", 0, SEED);116 Nft::<T>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, new_admin.clone())?;117 }: remove_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)118119 set_collection_sponsor {120 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();121 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();122 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();123 let mode: CollectionMode = CollectionMode::NFT;124 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());125 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;126 }: set_collection_sponsor(RawOrigin::Signed(caller.clone()), 2, caller.clone())127128 confirm_sponsorship {129 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();130 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();131 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();132 let mode: CollectionMode = CollectionMode::NFT;133 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());134 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;135 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;136 }: confirm_sponsorship(RawOrigin::Signed(caller.clone()), 2)137138 remove_collection_sponsor {139 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();140 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();141 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();142 let mode: CollectionMode = CollectionMode::NFT;143 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());144 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;145 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;146 Nft::<T>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;147 }: remove_collection_sponsor(RawOrigin::Signed(caller.clone()), 2)148149 // nft item150 create_item_nft {151 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();152 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();153 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();154 let mode: CollectionMode = CollectionMode::NFT;155 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());156 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;157 let data = default_nft_data();158 159 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)160161 #[extra]162 create_item_nft_large {163 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();164 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();165 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();166 let mode: CollectionMode = CollectionMode::NFT;167 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());168 let mut nft_data = CreateNftData {169 const_data: vec![],170 variable_data: vec![]171 };172 for i in 0..1998 {173 nft_data.const_data.push(10);174 nft_data.variable_data.push(10);175 }176 let data = CreateItemData::NFT(nft_data);177 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;178179 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)180181 // fungible item182 create_item_fungible {183 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();184 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();185 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();186 let mode: CollectionMode = CollectionMode::Fungible(3);187 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());188 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;189 let data = default_fungible_data();190191 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)192193 // refungible item194 create_item_refungible {195 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();196 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();197 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();198 let mode: CollectionMode = CollectionMode::ReFungible(3);199 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());200 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;201 let data = default_re_fungible_data();202203 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)204205 burn_item {206 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();207 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();208 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();209 let mode: CollectionMode = CollectionMode::NFT;210 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());211 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;212 let data = default_nft_data();213 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;214215 }: burn_item(RawOrigin::Signed(caller.clone()), 2, 1)216217 transfer_nft {218 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();219 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();220 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();221 let mode: CollectionMode = CollectionMode::NFT;222 let recipient: T::AccountId = account("recipient", 0, SEED);223 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());224 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;225 let data = default_nft_data();226 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;227228 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)229 230 transfer_fungible {231 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();232 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();233 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();234 let mode: CollectionMode = CollectionMode::Fungible(3);235 let recipient: T::AccountId = account("recipient", 0, SEED);236 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());237 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;238 let data = default_fungible_data();239 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;240241 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)242243 transfer_refungible {244 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();245 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();246 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();247 let mode: CollectionMode = CollectionMode::ReFungible(3);248 let recipient: T::AccountId = account("recipient", 0, SEED);249 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());250 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;251 let data = default_re_fungible_data();252 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;253254 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)255256 approve {257 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();258 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();259 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();260 let mode: CollectionMode = CollectionMode::ReFungible(3);261 let recipient: T::AccountId = account("recipient", 0, SEED);262 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());263 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;264 let data = default_re_fungible_data();265 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;266267 }: approve(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1)268269 // Nft270 transfer_from_nft {271 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();272 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();273 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();274 let mode: CollectionMode = CollectionMode::NFT;275 let recipient: T::AccountId = account("recipient", 0, SEED);276 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());277 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;278 let data = default_nft_data();279 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;280 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;281282 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)283284 // Fungible285 transfer_from_fungible {286 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();287 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();288 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();289 let mode: CollectionMode = CollectionMode::Fungible(3);290 let recipient: T::AccountId = account("recipient", 0, SEED);291 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());292 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;293 let data = default_fungible_data();294 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;295 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;296297 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)298299 // ReFungible300 transfer_from_refungible {301 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();302 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();303 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();304 let mode: CollectionMode = CollectionMode::ReFungible(3);305 let recipient: T::AccountId = account("recipient", 0, SEED);306 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());307 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;308 let data = default_re_fungible_data();309 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;310 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;311312 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)313314 set_offchain_schema {315 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();316 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();317 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();318 let mode: CollectionMode = CollectionMode::ReFungible(3);319 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());320 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;321322 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())323324 set_const_on_chain_schema {325 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();326 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();327 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();328 let mode: CollectionMode = CollectionMode::ReFungible(3);329 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());330 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;331 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())332 333 set_variable_on_chain_schema {334 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();335 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();336 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();337 let mode: CollectionMode = CollectionMode::ReFungible(3);338 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());339 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;340 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())341342 set_variable_meta_data {343 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();344 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();345 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();346 let mode: CollectionMode = CollectionMode::NFT;347 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());348 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;349 let data = default_nft_data();350 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;351352 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())353}pallets/nft/src/default_weights.rsdiffbeforeafterboth--- a/pallets/nft/src/default_weights.rs
+++ b/pallets/nft/src/default_weights.rs
@@ -63,7 +63,7 @@
}
fn create_item(s: usize, ) -> Weight {
(130_000_000 as Weight)
- .saturating_add((2135 as Weight).saturating_mul(s as Weight))
+ .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temporary multiplier, fee for storage
.saturating_add(DbWeight::get().reads(10 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
}
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -8,9 +8,9 @@
use codec::{Decode, Encode};
pub use frame_support::{
- construct_runtime, decl_event, decl_module, decl_storage,
+ construct_runtime, decl_event, decl_module, decl_storage, decl_error,
dispatch::DispatchResult,
- ensure, parameter_types, fail,
+ ensure, fail, parameter_types,
traits::{
Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,
Randomness, WithdrawReason,
@@ -22,7 +22,6 @@
},
IsSubType, StorageValue,
};
-// use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
use frame_system::{self as system, ensure_signed, ensure_root};
use sp_runtime::sp_std::prelude::Vec;
@@ -116,13 +115,6 @@
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-pub struct CollectionAdminsType<AccountId> {
- pub admin: AccountId,
- pub collection_id: u64,
-}
-
-#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct NftItemType<AccountId> {
pub collection: u64,
pub owner: AccountId,
@@ -268,6 +260,59 @@
}
}
+
+decl_error! {
+ /// Error for non-fungible-token module.
+ pub enum Error for Module<T: Trait> {
+ /// Total collections bound exceeded
+ TotalCollectionsLimitExceeded,
+ /// Decimal_points parameter must be lower than 4
+ CollectionDecimalPointLimitExceeded,
+ /// Collection name can not be longer than 63 char
+ CollectionNameLimitExceeded,
+ /// Collection description can not be longer than 255 char
+ CollectionDescriptionLimitExceeded,
+ /// Token prefix can not be longer than 15 char
+ CollectionTokenPrefixLimitExceeded,
+ /// This collection does not exist
+ CollectionNotFound,
+ /// Item not exists
+ TokenNotFound,
+ /// Arithmetic calculation overflow
+ NumOverflow,
+ /// Account already has admin role
+ AlreadyAdmin,
+ /// You do not own this collection
+ NoPermission,
+ /// This address is not set as sponsor, use setCollectionSponsor first
+ ConfirmUnsetSponsorFail,
+ /// Collection is not in mint mode
+ PublicMintingNotAllowed,
+ /// Sender parameter and item owner must be equal
+ MustBeTokenOwner,
+ /// Item balance not enouth
+ TokenValueTooLow,
+ /// Size of item is too large
+ NftSizeLimitExceeded,
+ /// Size of item must be 0 with fungible type
+ FungibleUnexpectedParam,
+ /// No approve found
+ ApproveNotFound,
+ /// Requested value more than approved
+ TokenValueNotEnough,
+ /// Only approved addresses can call this method
+ ApproveRequired,
+ /// Address is not in white list
+ AddresNotInWhiteList,
+ /// Number of collection admins bound exceeded
+ CollectionAdminsLimitExceeded,
+ /// Owned tokens by a single address bound exceeded
+ AddressOwnershipLimitExceeded,
+ /// Length of items properties must be greater than 0
+ EmptyArgument,
+ }
+}
+
pub trait Trait: system::Trait + Sized + transaction_payment::Trait + pallet_contracts::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
@@ -386,6 +431,7 @@
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
+ type Error = Error<T>;
fn on_initialize(now: T::BlockNumber) -> Weight {
@@ -432,32 +478,32 @@
};
// bound Total number of collections
- ensure!(CollectionCount::get() < ChainLimit::get().collection_numbers_limit, "Total collections bound exceeded");
+ ensure!(CollectionCount::get() < ChainLimit::get().collection_numbers_limit, Error::<T>::TotalCollectionsLimitExceeded);
// check params
- ensure!(decimal_points <= 4, "decimal_points parameter must be lower than 4");
+ ensure!(decimal_points <= 4, Error::<T>::CollectionDecimalPointLimitExceeded);
let mut name = collection_name.to_vec();
name.push(0);
- ensure!(name.len() <= 64, "Collection name can not be longer than 63 char");
+ ensure!(name.len() <= 64, Error::<T>::CollectionNameLimitExceeded);
let mut description = collection_description.to_vec();
description.push(0);
- ensure!(name.len() <= 256, "Collection description can not be longer than 255 char");
+ ensure!(name.len() <= 256, Error::<T>::CollectionDescriptionLimitExceeded);
let mut prefix = token_prefix.to_vec();
prefix.push(0);
- ensure!(prefix.len() <= 16, "Token prefix can not be longer than 15 char");
+ ensure!(prefix.len() <= 16, Error::<T>::CollectionTokenPrefixLimitExceeded);
// Generate next collection ID
let next_id = CreatedCollectionCount::get()
.checked_add(1)
- .expect("collection id error");
+ .ok_or(Error::<T>::NumOverflow)?;
// bound counter
let total = CollectionCount::get()
.checked_add(1)
- .expect("collection counter error");
+ .ok_or(Error::<T>::NumOverflow)?;
CreatedCollectionCount::put(next_id);
CollectionCount::put(total);
@@ -489,7 +535,7 @@
}
/// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.
- ///
+ ///
/// # Permissions
///
/// * Collection Owner.
@@ -524,7 +570,7 @@
// bound couter
let total = CollectionCount::get()
.checked_sub(1)
- .expect("collection counter error");
+ .ok_or(Error::<T>::NumOverflow)?;
CollectionCount::put(total);
}
@@ -693,11 +739,11 @@
if <AdminList<T>>::contains_key(collection_id)
{
admin_arr = <AdminList<T>>::get(collection_id);
- ensure!(!admin_arr.contains(&new_admin_id), "Account already has admin role");
+ ensure!(!admin_arr.contains(&new_admin_id), Error::<T>::AlreadyAdmin);
}
// Number of collection admins
- ensure!((admin_arr.len() as u64) < ChainLimit::get().collections_admins_limit, "Number of collection admins bound exceeded");
+ ensure!((admin_arr.len() as u64) < ChainLimit::get().collections_admins_limit, Error::<T>::CollectionAdminsLimitExceeded);
admin_arr.push(new_admin_id);
<AdminList<T>>::insert(collection_id, admin_arr);
@@ -746,10 +792,10 @@
pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
- ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");
+ ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
let mut target_collection = <Collection<T>>::get(collection_id);
- ensure!(sender == target_collection.owner, "You do not own this collection");
+ ensure!(sender == target_collection.owner, Error::<T>::NoPermission);
target_collection.unconfirmed_sponsor = new_sponsor;
<Collection<T>>::insert(collection_id, target_collection);
@@ -768,10 +814,10 @@
pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
- ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");
+ ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
let mut target_collection = <Collection<T>>::get(collection_id);
- ensure!(sender == target_collection.unconfirmed_sponsor, "This address is not set as sponsor, use setCollectionSponsor first");
+ ensure!(sender == target_collection.unconfirmed_sponsor, Error::<T>::ConfirmUnsetSponsorFail);
target_collection.sponsor = target_collection.unconfirmed_sponsor;
target_collection.unconfirmed_sponsor = T::AccountId::default();
@@ -793,10 +839,10 @@
pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
- ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");
+ ensure!(<Collection<T>>::contains_key(collection_id), Error::<T>::CollectionNotFound);
let mut target_collection = <Collection<T>>::get(collection_id);
- ensure!(sender == target_collection.owner, "You do not own this collection");
+ ensure!(sender == target_collection.owner, Error::<T>::NoPermission);
target_collection.sponsor = T::AccountId::default();
<Collection<T>>::insert(collection_id, target_collection);
@@ -832,79 +878,55 @@
pub fn create_item(origin, collection_id: u64, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
let sender = ensure_signed(origin)?;
+
Self::collection_exists(collection_id)?;
+
let target_collection = <Collection<T>>::get(collection_id);
- if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {
- ensure!(target_collection.mint_mode == true, "Public minting is not allowed for this collection.");
- Self::check_white_list(collection_id, &owner)?;
- Self::check_white_list(collection_id, &sender)?;
- }
+ Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;
+ Self::validate_create_item_args(&target_collection, &data)?;
+ Self::create_item_no_validation(collection_id, &target_collection, owner, data)?;
+
+ Ok(())
+ }
- match target_collection.mode
- {
- CollectionMode::NFT => {
- if let CreateItemData::NFT(data) = data {
- // check sizes
- ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
- ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
-
- // Create nft item
- let item = NftItemType {
- collection: collection_id,
- owner: owner,
- const_data: data.const_data.clone(),
- variable_data: data.variable_data.clone()
- };
-
- Self::add_nft_item(item)?;
-
- } else {
- fail!("Not NFT item data used to mint in NFT collection.");
- }
- },
- CollectionMode::Fungible(_) => {
- if let CreateItemData::Fungible(_) = data {
-
- let item = FungibleItemType {
- collection: collection_id,
- owner: owner,
- value: (10 as u128).pow(target_collection.decimal_points)
- };
-
- Self::add_fungible_item(item)?;
- } else {
- fail!("Not Fungible item data used to mint in Fungible collection.");
- }
- },
- CollectionMode::ReFungible(_) => {
- if let CreateItemData::ReFungible(data) = data {
-
- // check sizes
- ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
- ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
-
- let mut owner_list = Vec::new();
- let value = (10 as u128).pow(target_collection.decimal_points);
- owner_list.push(Ownership {owner: owner.clone(), fraction: value});
-
- let item = ReFungibleItemType {
- collection: collection_id,
- owner: owner_list,
- const_data: data.const_data.clone(),
- variable_data: data.variable_data.clone()
- };
-
- Self::add_refungible_item(item)?;
- } else {
- fail!("Not Re Fungible item data used to mint in Re Fungible collection.");
- }
- },
- _ => { ensure!(1 == 0,"Unexpected collection type."); }
- };
+ /// This method creates multiple instances of NFT Collection created with CreateCollection method.
+ ///
+ /// # Permissions
+ ///
+ /// * Collection Owner.
+ /// * Collection Admin.
+ /// * Anyone if
+ /// * White List is enabled, and
+ /// * Address is added to white list, and
+ /// * MintPermission is enabled (see SetMintPermission method)
+ ///
+ /// # Arguments
+ ///
+ /// * collection_id: ID of the collection.
+ ///
+ /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].
+ ///
+ /// * owner: Address, initial owner of the NFT.
+ #[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 {
+
+ ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);
+ let sender = ensure_signed(origin)?;
+
+ Self::collection_exists(collection_id)?;
+ let target_collection = <Collection<T>>::get(collection_id);
+
+ Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?;
- // call event
- Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id)));
+ for data in &items_data {
+ Self::validate_create_item_args(&target_collection, data)?;
+ }
+ for data in &items_data {
+ Self::create_item_no_validation(collection_id, &target_collection, owner.clone(), data.clone())?;
+ }
Ok(())
}
@@ -932,7 +954,7 @@
let target_collection = <Collection<T>>::get(collection_id);
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
- "Only item owner, collection owner and admins can modify item");
+ Error::<T>::NoPermission);
if target_collection.access == AccessMode::WhiteList {
Self::check_white_list(collection_id, &sender)?;
@@ -984,7 +1006,7 @@
let target_collection = <Collection<T>>::get(collection_id);
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
- "Only item owner, collection owner and admins can modify item");
+ Error::<T>::NoPermission);
if target_collection.access == AccessMode::WhiteList {
Self::check_white_list(collection_id, &sender)?;
@@ -1026,7 +1048,7 @@
let target_collection = <Collection<T>>::get(collection_id);
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
- "Only item owner, collection owner and admins can approve");
+ Error::<T>::NoPermission);
if target_collection.access == AccessMode::WhiteList {
Self::check_white_list(collection_id, &sender)?;
@@ -1088,14 +1110,14 @@
if opt_item.is_some()
{
appoved_transfer = true;
- ensure!(opt_item.unwrap().amount >= value, "Requested value more than approved");
+ ensure!(opt_item.unwrap().amount >= value, Error::<T>::TokenValueNotEnough);
}
}
// Transfer permissions check
let target_collection = <Collection<T>>::get(collection_id);
- ensure!(appoved_transfer || Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
- "Only item owner, collection owner and admins can modify items");
+ ensure!(appoved_transfer || Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
+ Error::<T>::NoPermission);
if target_collection.access == AccessMode::WhiteList {
Self::check_white_list(collection_id, &sender)?;
@@ -1134,7 +1156,7 @@
Ok(())
}
-
+
/// Set off-chain data schema.
///
/// # Permissions
@@ -1162,7 +1184,7 @@
let target_collection = <Collection<T>>::get(collection_id);
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
- "Only item owner, collection owner and admins can modify item.");
+ Error::<T>::NoPermission);
Self::item_exists(collection_id, item_id, &target_collection.mode)?;
@@ -1296,7 +1318,7 @@
let owner = <ContractOwner<T>>::get(&contract_address);
is_owner = sender == owner;
}
- ensure!(is_owner, "Only contract owner may call this method");
+ ensure!(is_owner, Error::<T>::NoPermission);
<ContractSelfSponsoring<T>>::insert(contract_address, enable);
Ok(())
@@ -1306,10 +1328,101 @@
}
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 {
+
+ if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) {
+ ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);
+ Self::check_white_list(collection_id, owner)?;
+ Self::check_white_list(collection_id, sender)?;
+ }
+
+ Ok(())
+ }
+
+ fn validate_create_item_args(target_collection: &CollectionType<T::AccountId>, data: &CreateItemData) -> DispatchResult {
+ match target_collection.mode
+ {
+ CollectionMode::NFT => {
+ if let CreateItemData::NFT(data) = data {
+ // check sizes
+ ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
+ ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
+ } else {
+ fail!("Not NFT item data used to mint in NFT collection.");
+ }
+ },
+ CollectionMode::Fungible(_) => {
+ if let CreateItemData::Fungible(_) = data {
+ } else {
+ fail!("Not Fungible item data used to mint in Fungible collection.");
+ }
+ },
+ CollectionMode::ReFungible(_) => {
+ if let CreateItemData::ReFungible(data) = data {
+
+ // check sizes
+ ensure!(ChainLimit::get().custom_data_limit >= data.const_data.len() as u32, "const_data exceeded data limit.");
+ ensure!(ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32, "variable_data exceeded data limit.");
+ } else {
+ fail!("Not Re Fungible item data used to mint in Re Fungible collection.");
+ }
+ },
+ _ => { fail!("Unexpected collection type."); }
+ };
+
+ Ok(())
+ }
+
+ fn create_item_no_validation(collection_id: u64, collection: &CollectionType<T::AccountId>, owner: T::AccountId, data: CreateItemData) -> DispatchResult {
+ match data
+ {
+ CreateItemData::NFT(data) => {
+ let item = NftItemType {
+ collection: collection_id,
+ owner,
+ const_data: data.const_data,
+ variable_data: data.variable_data
+ };
+
+ Self::add_nft_item(item)?;
+ },
+ CreateItemData::Fungible(_) => {
+ let item = FungibleItemType {
+ collection: collection_id,
+ owner,
+ value: (10 as u128).pow(collection.decimal_points)
+ };
+
+ Self::add_fungible_item(item)?;
+ },
+ CreateItemData::ReFungible(data) => {
+ let mut owner_list = Vec::new();
+ let value = (10 as u128).pow(collection.decimal_points);
+ owner_list.push(Ownership {owner: owner.clone(), fraction: value});
+
+ let item = ReFungibleItemType {
+ collection: collection_id,
+ owner: owner_list,
+ const_data: data.const_data,
+ variable_data: data.variable_data
+ };
+
+ Self::add_refungible_item(item)?;
+ }
+ };
+
+
+ // call event
+ Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id)));
+
+ Ok(())
+ }
+
fn add_fungible_item(item: FungibleItemType<T::AccountId>) -> DispatchResult {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .ok_or(Error::<T>::NumOverflow)?;
let itemcopy = item.clone();
let owner = item.owner.clone();
let value = item.value as u64;
@@ -1326,7 +1439,7 @@
// Update balance
let new_balance = <Balance<T>>::get(item.collection, owner.clone())
.checked_add(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(item.collection, owner.clone(), new_balance);
Ok(())
@@ -1335,7 +1448,7 @@
fn add_refungible_item(item: ReFungibleItemType<T::AccountId>) -> DispatchResult {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .ok_or(Error::<T>::NumOverflow)?;
let itemcopy = item.clone();
let value = item.owner.first().unwrap().fraction as u64;
@@ -1353,7 +1466,7 @@
// Update balance
let new_balance = <Balance<T>>::get(item.collection, owner.clone())
.checked_add(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(item.collection, owner.clone(), new_balance);
Ok(())
@@ -1362,7 +1475,7 @@
fn add_nft_item(item: NftItemType<T::AccountId>) -> DispatchResult {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .ok_or(Error::<T>::NumOverflow)?;
let item_owner = item.owner.clone();
let collection_id = item.collection.clone();
@@ -1378,7 +1491,7 @@
// Update balance
let new_balance = <Balance<T>>::get(collection_id, item_owner.clone())
.checked_add(1)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);
Ok(())
@@ -1391,7 +1504,7 @@
) -> DispatchResult {
ensure!(
<ReFungibleItemList<T>>::contains_key(collection_id, item_id),
- "Item does not exists"
+ Error::<T>::TokenNotFound
);
let collection = <ReFungibleItemList<T>>::get(collection_id, item_id);
let item = collection
@@ -1408,7 +1521,7 @@
// update balance
let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())
.checked_sub(item.fraction as u64)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);
<ReFungibleItemList<T>>::remove(collection_id, item_id);
@@ -1419,7 +1532,7 @@
fn burn_nft_item(collection_id: u64, item_id: u64) -> DispatchResult {
ensure!(
<NftItemList<T>>::contains_key(collection_id, item_id),
- "Item does not exists"
+ Error::<T>::TokenNotFound
);
let item = <NftItemList<T>>::get(collection_id, item_id);
Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
@@ -1430,7 +1543,7 @@
// update balance
let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())
.checked_sub(1)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);
<NftItemList<T>>::remove(collection_id, item_id);
@@ -1440,7 +1553,7 @@
fn burn_fungible_item(collection_id: u64, item_id: u64) -> DispatchResult {
ensure!(
<FungibleItemList<T>>::contains_key(collection_id, item_id),
- "Item does not exists"
+ Error::<T>::TokenNotFound
);
let item = <FungibleItemList<T>>::get(collection_id, item_id);
Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
@@ -1451,7 +1564,7 @@
// update balance
let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())
.checked_sub(item.value as u64)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);
<FungibleItemList<T>>::remove(collection_id, item_id);
@@ -1462,7 +1575,7 @@
fn collection_exists(collection_id: u64) -> DispatchResult {
ensure!(
<Collection<T>>::contains_key(collection_id),
- "This collection does not exist"
+ Error::<T>::CollectionNotFound
);
Ok(())
}
@@ -1473,7 +1586,7 @@
let target_collection = <Collection<T>>::get(collection_id);
ensure!(
subject == target_collection.owner,
- "You do not own this collection"
+ Error::<T>::NoPermission
);
Ok(())
@@ -1502,7 +1615,7 @@
ensure!(
result,
- "You do not have permissions to modify this collection"
+ Error::<T>::NoPermission
);
Ok(())
}
@@ -1528,7 +1641,7 @@
}
fn check_white_list(collection_id: u64, address: &T::AccountId) -> DispatchResult {
- let mes = "Address is not in white list";
+ let mes = Error::<T>::AddresNotInWhiteList;
ensure!(<WhiteList<T>>::contains_key(collection_id), mes);
let wl = <WhiteList<T>>::get(collection_id);
ensure!(wl.contains(address), mes);
@@ -1545,18 +1658,18 @@
) -> DispatchResult {
ensure!(
<FungibleItemList<T>>::contains_key(collection_id, item_id),
- "Item not exists"
+ Error::<T>::TokenNotFound
);
let full_item = <FungibleItemList<T>>::get(collection_id, item_id);
let amount = full_item.value;
- ensure!(amount >= value.into(), "Item balance not enouth");
+ ensure!(amount >= value.into(), Error::<T>::TokenValueTooLow);
// update balance
let balance_old_owner = <Balance<T>>::get(collection_id, owner.clone())
.checked_sub(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, owner.clone(), balance_old_owner);
let mut new_owner_account_id = 0;
@@ -1578,7 +1691,7 @@
// update balance
let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())
.checked_add(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, new_owner.clone(), balance_new_owner);
// update index collection
@@ -1596,7 +1709,7 @@
// update balance
let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())
.checked_add(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, new_owner.clone(), balance_new_owner);
<FungibleItemList<T>>::insert(collection_id, new_owner_account_id, item);
@@ -1634,7 +1747,7 @@
) -> DispatchResult {
ensure!(
<ReFungibleItemList<T>>::contains_key(collection_id, item_id),
- "Item not exists"
+ Error::<T>::TokenNotFound
);
let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id);
@@ -1643,20 +1756,20 @@
.iter()
.filter(|i| i.owner == owner)
.next()
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
let amount = item.fraction;
- ensure!(amount >= value.into(), "Item balance not enouth");
+ ensure!(amount >= value.into(), Error::<T>::TokenValueTooLow);
// update balance
let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.clone())
.checked_sub(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), balance_old_owner);
let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())
.checked_add(value)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, new_owner.clone(), balance_new_owner);
let old_owner = item.owner.clone();
@@ -1719,25 +1832,25 @@
) -> DispatchResult {
ensure!(
<NftItemList<T>>::contains_key(collection_id, item_id),
- "Item not exists"
+ Error::<T>::TokenNotFound
);
let mut item = <NftItemList<T>>::get(collection_id, item_id);
ensure!(
sender == item.owner,
- "sender parameter and item owner must be equal"
+ Error::<T>::MustBeTokenOwner
);
// update balance
let balance_old_owner = <Balance<T>>::get(collection_id, item.owner.clone())
.checked_sub(1)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), balance_old_owner);
let balance_new_owner = <Balance<T>>::get(collection_id, new_owner.clone())
.checked_add(1)
- .unwrap();
+ .ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, new_owner.clone(), balance_new_owner);
// change owner
@@ -1759,9 +1872,9 @@
mode: &CollectionMode
) -> DispatchResult {
match mode {
- CollectionMode::NFT => ensure!(<NftItemList<T>>::contains_key(collection_id, item_id), "Item does not exists"),
- CollectionMode::ReFungible(_) => ensure!(<ReFungibleItemList<T>>::contains_key(collection_id, item_id), "Item does not exists"),
- CollectionMode::Fungible(_) => ensure!(<FungibleItemList<T>>::contains_key(collection_id, item_id), "Item does not exists"),
+ CollectionMode::NFT => ensure!(<NftItemList<T>>::contains_key(collection_id, item_id), Error::<T>::TokenNotFound),
+ CollectionMode::ReFungible(_) => ensure!(<ReFungibleItemList<T>>::contains_key(collection_id, item_id), Error::<T>::TokenNotFound),
+ CollectionMode::Fungible(_) => ensure!(<FungibleItemList<T>>::contains_key(collection_id, item_id), Error::<T>::TokenNotFound),
_ => ()
};
@@ -1818,7 +1931,7 @@
// Generate next collection ID
let next_id = CreatedCollectionCount::get()
.checked_add(1)
- .expect("collection id error");
+ .unwrap();
CreatedCollectionCount::put(next_id);
}
@@ -1826,7 +1939,7 @@
fn init_nft_token(item: &NftItemType<T::AccountId>) {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .unwrap();
let item_owner = item.owner.clone();
let collection_id = item.collection.clone();
@@ -1844,7 +1957,7 @@
fn init_fungible_token(item: &FungibleItemType<T::AccountId>) {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .unwrap();
let owner = item.owner.clone();
let value = item.value as u64;
@@ -1862,7 +1975,7 @@
fn init_refungible_token(item: &ReFungibleItemType<T::AccountId>) {
let current_index = <ItemListIndex>::get(item.collection)
.checked_add(1)
- .expect("Item list index id error");
+ .unwrap();
let value = item.owner.first().unwrap().fraction as u64;
let owner = item.owner.first().unwrap().owner.clone();
@@ -1885,10 +1998,11 @@
// bound Owned tokens by a single address
let count = <AccountItemCount<T>>::get(owner.clone());
- ensure!(count < ChainLimit::get().account_token_ownership_limit, "Owned tokens by a single address bound exceeded");
+ ensure!(count < ChainLimit::get().account_token_ownership_limit, Error::<T>::AddressOwnershipLimitExceeded);
- <AccountItemCount<T>>::insert(owner.clone(),
- count.checked_add(1).unwrap());
+ <AccountItemCount<T>>::insert(owner.clone(), count
+ .checked_add(1)
+ .ok_or(Error::<T>::NumOverflow)?);
}
else {
<AccountItemCount<T>>::insert(owner.clone(), 1);
@@ -1922,7 +2036,9 @@
// update counter
<AccountItemCount<T>>::insert(owner.clone(),
- <AccountItemCount<T>>::get(owner.clone()).checked_sub(1).unwrap());
+ <AccountItemCount<T>>::get(owner.clone())
+ .checked_sub(1)
+ .ok_or(Error::<T>::NumOverflow)?);
let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.clone());
@@ -2236,5 +2352,3 @@
}
// #endregion
-
-
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -87,6 +87,32 @@
});
}
+// Use cases tests region
+// #region
+#[test]
+fn create_nft_multiple_items() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ create_test_collection(&CollectionMode::NFT, 1);
+
+ let origin1 = Origin::signed(1);
+
+ let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];
+
+ assert_ok!(TemplateModule::create_multiple_items(
+ origin1.clone(),
+ 1,
+ 1,
+ 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);
+ }
+ });
+}
+
#[test]
fn create_refungible_item() {
new_test_ext().execute_with(|| {
@@ -114,6 +140,39 @@
}
#[test]
+fn create_multiple_refungible_items() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ create_test_collection(&CollectionMode::ReFungible(3), 1);
+
+ let origin1 = Origin::signed(1);
+
+ let items_data = vec![default_re_fungible_data(), default_re_fungible_data(), default_re_fungible_data()];
+
+ assert_ok!(TemplateModule::create_multiple_items(
+ origin1.clone(),
+ 1,
+ 1,
+ items_data.clone().into_iter().map(|d| { d.into() }).collect()
+ ));
+ for (index, data) in items_data.iter().enumerate() {
+
+ let item = TemplateModule::refungible_item_id(1, (index + 1) as u64);
+ assert_eq!(item.const_data.to_vec(), data.const_data);
+ assert_eq!(item.variable_data.to_vec(), data.variable_data);
+ assert_eq!(
+ item.owner[0],
+ Ownership {
+ owner: 1,
+ fraction: 1000
+ }
+ );
+ }
+ });
+}
+
+#[test]
fn create_fungible_item() {
new_test_ext().execute_with(|| {
default_limits();
@@ -124,12 +183,36 @@
create_test_item(collection_id, &data.into());
assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).owner, 1);
- assert_eq!(TemplateModule::balance_count(1, 1), 1000);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
});
}
#[test]
+fn create_multiple_fungible_items() {
+ new_test_ext().execute_with(|| {
+ default_limits();
+
+ create_test_collection(&CollectionMode::Fungible(3), 1);
+
+ let origin1 = Origin::signed(1);
+
+ let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];
+
+ assert_ok!(TemplateModule::create_multiple_items(
+ origin1.clone(),
+ 1,
+ 1,
+ items_data.clone().into_iter().map(|d| { d.into() }).collect()
+ ));
+
+ for (index, _) in items_data.iter().enumerate() {
+ assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as u64).owner, 1);
+ }
+ assert_eq!(TemplateModule::balance_count(1, 1), 3000);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);
+ });
+}
+
+#[test]
fn transfer_fungible_item() {
new_test_ext().execute_with(|| {
default_limits();
@@ -1333,7 +1416,7 @@
assert_noop!(
TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),
- "Public minting is not allowed for this collection."
+ "Public minting is not allowed for this collection"
);
});
}
@@ -1362,7 +1445,7 @@
assert_noop!(
TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),
- "Public minting is not allowed for this collection."
+ "Public minting is not allowed for this collection"
);
});
}
runtime/src/nft_weights.rsdiffbeforeafterboth--- a/runtime/src/nft_weights.rs
+++ b/runtime/src/nft_weights.rs
@@ -64,7 +64,7 @@
}
fn create_item(s: usize, ) -> Weight {
(130_000_000 as Weight)
- .saturating_add((2135 as Weight).saturating_mul(s as Weight))
+ .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temparary multiplier, fee for storage
.saturating_add(DbWeight::get().reads(10 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
}