difftreelog
Merge pull request #189 from UniqueNetwork/fix/nft-benchmarking
in: master
Update pallet-nft benchmarks
8 files changed
Makefilediffbeforeafterboth35bench-evm-migration:35bench-evm-migration:36 make _bench PALLET=evm-migration36 make _bench PALLET=evm-migration3738.PHONY: bench-nft39bench-nft:40 make _bench PALLET=nft374138.PHONY: bench42.PHONY: bench39bench: bench-evm-migration43bench: bench-evm-migration bench-nft4044pallets/nft/src/benchmarking.rsdiffbeforeafterboth1#![cfg(feature = "runtime-benchmarks")]1#![cfg(feature = "runtime-benchmarks")]223use super::*;3use super::*;4use crate::Module as Nft;4use crate::Pallet;56use sp_std::prelude::*;7use frame_system::RawOrigin;5use frame_system::RawOrigin;8use frame_benchmarking::{benchmarks, account, whitelisted_caller}; // , TrackedStorageKey,6use frame_benchmarking::{benchmarks, account};7use nft_data_structs::*;8use core::convert::TryInto;9use sp_runtime::DispatchError;91010const SEED: u32 = 1;11const SEED: u32 = 1;11/*1212fn default_nft_data() -> CreateItemData {13fn create_data(size: usize) -> Vec<u8> {13 CreateItemData::NFT(CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })14 (0..size).map(|v| (v & 0xff) as u8).collect()14}15}1516fn create_u16_data(size: usize) -> Vec<u16> {16fn default_fungible_data () -> CreateItemData {17 (0..size).map(|v| (v & 0xffff) as u16).collect()17 CreateItemData::Fungible(CreateFungibleData { })18}18}191920fn default_nft_data() -> CreateItemData {20fn default_re_fungible_data () -> CreateItemData {21 CreateItemData::NFT(CreateNftData {21 CreateItemData::ReFungible(CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] })22 const_data: create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap(),22}23 variable_data: create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap(),23*/24 })25}2627fn default_fungible_data() -> CreateItemData {28 CreateItemData::Fungible(CreateFungibleData { value: 1000 })29}3031fn default_re_fungible_data() -> CreateItemData {32 CreateItemData::ReFungible(CreateReFungibleData {33 const_data: create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap(),34 variable_data: create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap(),35 pieces: 1000,36 })37}3839fn create_collection_helper<T: Config>(40 owner: T::AccountId,41 mode: CollectionMode,42) -> Result<CollectionId, DispatchError> {43 T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());44 let col_name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)45 .try_into()46 .unwrap();47 let col_desc = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)48 .try_into()49 .unwrap();50 let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();51 <Pallet<T>>::create_collection(52 RawOrigin::Signed(owner).into(),53 col_name,54 col_desc,55 token_prefix,56 mode,57 )?;58 Ok(CreatedCollectionCount::get())59}60fn create_nft_collection<T: Config>(owner: T::AccountId) -> Result<CollectionId, DispatchError> {61 create_collection_helper::<T>(owner, CollectionMode::NFT)62}63fn create_fungible_collection<T: Config>(64 owner: T::AccountId,65) -> Result<CollectionId, DispatchError> {66 create_collection_helper::<T>(owner, CollectionMode::Fungible(0))67}68fn create_refungible_collection<T: Config>(69 owner: T::AccountId,70) -> Result<CollectionId, DispatchError> {71 create_collection_helper::<T>(owner, CollectionMode::ReFungible)72}247325benchmarks! {74benchmarks! {267527 create_collection {76 create_collection {28 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();77 let col_name: Vec<u16> = create_u16_data(MAX_COLLECTION_NAME_LENGTH);78 let col_desc: Vec<u16> = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH);79 let token_prefix: Vec<u8> = create_data(MAX_TOKEN_PREFIX_LENGTH);80 let mode: CollectionMode = CollectionMode::NFT;81 let caller: T::AccountId = account("caller", 0, SEED);82 T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());83 }: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)84 verify {85 assert_eq!(<Pallet<T>>::collection_id(2).unwrap().owner, caller);86 }8788 destroy_collection {89 let caller: T::AccountId = account("caller", 0, SEED);90 let collection = create_nft_collection::<T>(caller.clone())?;91 }: _(RawOrigin::Signed(caller.clone()), collection)9293 add_to_white_list {94 let caller: T::AccountId = account("caller", 0, SEED);95 let whitelist_account: T::AccountId = account("admin", 0, SEED);96 let collection = create_nft_collection::<T>(caller.clone())?;97 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(whitelist_account))9899 remove_from_white_list {100 let caller: T::AccountId = account("caller", 0, SEED);101 let whitelist_account: T::AccountId = account("admin", 0, SEED);102 let collection = create_nft_collection::<T>(caller.clone())?;103 <Pallet<T>>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(whitelist_account.clone()))?;104 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(whitelist_account))105106 set_public_access_mode {107 let caller: T::AccountId = account("caller", 0, SEED);108 let collection = create_nft_collection::<T>(caller.clone())?;109 }: _(RawOrigin::Signed(caller.clone()), collection, AccessMode::WhiteList)110111 set_mint_permission {112 let caller: T::AccountId = account("caller", 0, SEED);113 let collection = create_nft_collection::<T>(caller.clone())?;114 }: _(RawOrigin::Signed(caller.clone()), collection, true)115116 change_collection_owner {117 let caller: T::AccountId = account("caller", 0, SEED);118 let collection = create_nft_collection::<T>(caller.clone())?;119 let new_owner: T::AccountId = account("admin", 0, SEED);120 }: _(RawOrigin::Signed(caller.clone()), collection, new_owner)121122 add_collection_admin {123 let caller: T::AccountId = account("caller", 0, SEED);124 let collection = create_nft_collection::<T>(caller.clone())?;125 let new_admin: T::AccountId = account("admin", 0, SEED);126 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin))127128 remove_collection_admin {129 let caller: T::AccountId = account("caller", 0, SEED);130 let collection = create_nft_collection::<T>(caller.clone())?;131 let new_admin: T::AccountId = account("admin", 0, SEED);132 <Pallet<T>>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(new_admin.clone()))?;133 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin))134135 set_collection_sponsor {136 let caller: T::AccountId = account("caller", 0, SEED);137 let collection = create_nft_collection::<T>(caller.clone())?;138 }: _(RawOrigin::Signed(caller.clone()), collection, caller.clone())139140 confirm_sponsorship {141 let caller: T::AccountId = account("caller", 0, SEED);29 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();142 let collection = create_nft_collection::<T>(caller.clone())?;143 <Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;144 }: _(RawOrigin::Signed(caller.clone()), collection)145146 remove_collection_sponsor {147 let caller: T::AccountId = account("caller", 0, SEED);148 let collection = create_nft_collection::<T>(caller.clone())?;149 <Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;150 <Pallet<T>>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;151 }: _(RawOrigin::Signed(caller.clone()), collection)152153 // nft item154 create_item_nft {155 let b in 0..(CUSTOM_DATA_LIMIT * 2);156157 let caller: T::AccountId = account("caller", 0, SEED);158 let collection = create_nft_collection::<T>(caller.clone())?;159 let data = CreateItemData::NFT(CreateNftData {160 const_data: create_data(b.min(CUSTOM_DATA_LIMIT) as usize).try_into().unwrap(),161 variable_data: create_data(b.saturating_sub(CUSTOM_DATA_LIMIT) as usize).try_into().unwrap(),162 });163 }: create_item(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)164165 create_multiple_items_nft {166 // TODO: Take item data size into account. As create_item_nft bench shows, this parameter has no effect on execution time,167 // but it may if we increase CUSTOM_DATA_LIMIT168 let b in 1..1000;169170 let caller: T::AccountId = account("caller", 0, SEED);171 let collection = create_nft_collection::<T>(caller.clone())?;172 let data = (0..b).map(|_| default_nft_data()).collect();173 }: create_multiple_items(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)174175 // fungible item176 create_item_fungible {177 let caller: T::AccountId = account("caller", 0, SEED);178 let collection = create_fungible_collection::<T>(caller.clone())?;179 let data = CreateItemData::Fungible(CreateFungibleData {180 value: 1000,181 });182 }: create_item(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)183184 create_multiple_items_fungible {185 let b in 1..1000;186187 let caller: T::AccountId = account("caller", 0, SEED);188 let collection = create_fungible_collection::<T>(caller.clone())?;189 let data = (0..b).map(|_| default_fungible_data()).collect();190 }: create_multiple_items(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)191192 // refungible item193 create_item_refungible {194 let b in 0..(CUSTOM_DATA_LIMIT * 2);195196 let caller: T::AccountId = account("caller", 0, SEED);197 let collection = create_refungible_collection::<T>(caller.clone())?;198 let data = CreateItemData::ReFungible(CreateReFungibleData {199 const_data: create_data(b.min(CUSTOM_DATA_LIMIT) as usize).try_into().unwrap(),200 variable_data: create_data(b.saturating_sub(CUSTOM_DATA_LIMIT) as usize).try_into().unwrap(),201 pieces: 1000,202 });203 }: create_item(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)204205 create_multiple_items_refungible {206 // TODO: Take item data size into account. As create_item_nft bench shows, this parameter has no effect on execution time,207 // but it may if we increase CUSTOM_DATA_LIMIT208 let b in 1..1000;209210 let caller: T::AccountId = account("caller", 0, SEED);211 let collection = create_refungible_collection::<T>(caller.clone())?;212 let data = (0..b).map(|_| default_re_fungible_data()).collect();213 }: create_multiple_items(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(caller.clone()), data)214215 burn_item_nft {216 let caller: T::AccountId = account("caller", 0, SEED);217 let collection = create_nft_collection::<T>(caller.clone())?;218 let data = default_nft_data();219 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(caller.clone()), data)?;220 }: burn_item(RawOrigin::Signed(caller.clone()), collection, 1, 1)221222 transfer_nft {30 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();223 let caller: T::AccountId = account("caller", 0, SEED);224 let collection = create_nft_collection::<T>(caller.clone())?;225 let recipient: T::AccountId = account("recipient", 0, SEED);226 let data = default_nft_data();227 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(caller.clone()), data)?;228 }: transfer(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), collection, 1, 1)229230 transfer_fungible {231 let caller: T::AccountId = account("caller", 0, SEED);232 let collection = create_fungible_collection::<T>(caller.clone())?;233 let recipient: T::AccountId = account("recipient", 0, SEED);234 let data = default_fungible_data();235 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(caller.clone()), data)?;236 }: transfer(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), collection, 1, 1)237238 transfer_refungible {31 let mode: CollectionMode = CollectionMode::NFT;239 let caller: T::AccountId = account("caller", 0, SEED);240 let collection = create_refungible_collection::<T>(caller.clone())?;32 let caller: T::AccountId = account("caller", 0, SEED);241 let recipient: T::AccountId = account("recipient", 0, SEED);242 let data = default_re_fungible_data();243 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(caller.clone()), data)?;244 }: transfer(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), collection, 1, 1)245246 set_transfers_enabled_flag {247 let caller: T::AccountId = account("caller", 0, SEED);248 let collection = create_nft_collection::<T>(caller.clone())?;33 }: _(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)249 }: _(RawOrigin::Signed(caller.clone()), collection, false)34/*25035 verify {251 approve_nft {36 assert_eq!(Nft::<T>::collection_id(2).owner, caller);252 let caller: T::AccountId = account("caller", 0, SEED);37 }253 let collection = create_nft_collection::<T>(caller.clone())?;38 destroy_collection {254 let recipient: T::AccountId = account("recipient", 0, SEED);39 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();255 let data = default_nft_data();40 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();256 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(caller.clone()), data)?;41 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();257 }: approve(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), collection, 1, 1)42 let mode: CollectionMode = CollectionMode::NFT;25843 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());259 // Nft44 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;260 transfer_from_nft {45 }: _(RawOrigin::Signed(caller.clone()), 2)261 let caller: T::AccountId = account("caller", 0, SEED);46262 let collection = create_nft_collection::<T>(caller.clone())?;47 add_to_white_list {263 let recipient: T::AccountId = account("recipient", 0, SEED);48 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();264 let data = default_nft_data();49 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();265 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(caller.clone()), data)?;50 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();266 <Pallet<T>>::approve(RawOrigin::Signed(caller.clone()).into(), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)?;51 let mode: CollectionMode = CollectionMode::NFT;267 }: transfer_from(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)52 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());26853 let whitelist_account: T::AccountId = account("admin", 0, SEED);269 // Fungible54 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;270 transfer_from_fungible {55 }: add_to_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)271 let caller: T::AccountId = account("caller", 0, SEED);56272 let collection = create_fungible_collection::<T>(caller.clone())?;57 remove_from_white_list {273 let recipient: T::AccountId = account("recipient", 0, SEED);58 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();274 let data = default_fungible_data();59 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();275 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(caller.clone()), data)?;60 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();276 <Pallet<T>>::approve(RawOrigin::Signed(caller.clone()).into(), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)?;61 let mode: CollectionMode = CollectionMode::NFT;277 }: transfer_from(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)62 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());27863 let whitelist_account: T::AccountId = account("admin", 0, SEED);279 // ReFungible64 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;280 transfer_from_refungible {65 Nft::<T>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), 2, whitelist_account.clone())?;281 let caller: T::AccountId = account("caller", 0, SEED);66 }: remove_from_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)282 let collection = create_refungible_collection::<T>(caller.clone())?;67283 let recipient: T::AccountId = account("recipient", 0, SEED);68 set_public_access_mode {284 let data = default_re_fungible_data();69 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();285 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(caller.clone()), data)?;70 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();286 <Pallet<T>>::approve(RawOrigin::Signed(caller.clone()).into(), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)?;71 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();287 }: transfer_from(RawOrigin::Signed(caller.clone()), T::CrossAccountId::from_sub(caller.clone()), T::CrossAccountId::from_sub(recipient.clone()), 2, 1, 1)72 let mode: CollectionMode = CollectionMode::NFT;28873 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());289 set_offchain_schema {74 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;290 let b in 0..OFFCHAIN_SCHEMA_LIMIT;75 }: set_public_access_mode(RawOrigin::Signed(caller.clone()), 2, AccessMode::WhiteList)29176292 let caller: T::AccountId = account("caller", 0, SEED);77 set_mint_permission {293 let collection = create_nft_collection::<T>(caller.clone())?;78 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();294 let data = create_data(b as usize);79 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();295 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), collection, data)80 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();29681 let mode: CollectionMode = CollectionMode::NFT;297 set_const_on_chain_schema {82 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());298 let b in 0..CONST_ON_CHAIN_SCHEMA_LIMIT;83 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;29984 }: set_mint_permission(RawOrigin::Signed(caller.clone()), 2, true)300 let caller: T::AccountId = account("caller", 0, SEED);85301 let collection = create_nft_collection::<T>(caller.clone())?;86 change_collection_owner {302 let data = create_data(b as usize);87 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();303 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)88 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();30489 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();305 set_variable_on_chain_schema {90 let mode: CollectionMode = CollectionMode::NFT;306 let b in 0..VARIABLE_ON_CHAIN_SCHEMA_LIMIT;91 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());30792 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;308 let caller: T::AccountId = account("caller", 0, SEED);93 let new_owner: T::AccountId = account("admin", 0, SEED);309 let collection = create_nft_collection::<T>(caller.clone())?;94 }: change_collection_owner(RawOrigin::Signed(caller.clone()), 2, new_owner)310 let data = create_data(b as usize);95311 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, data)96 add_collection_admin {31297 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();313 set_variable_meta_data_nft {98 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();314 let b in 0..CUSTOM_DATA_LIMIT;99 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();315100 let mode: CollectionMode = CollectionMode::NFT;316 let caller: T::AccountId = account("caller", 0, SEED);101 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());317 let collection = create_nft_collection::<T>(caller.clone())?;102 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;318 let data = default_nft_data();103 let new_admin: T::AccountId = account("admin", 0, SEED);319 <Pallet<T>>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, T::CrossAccountId::from_sub(caller.clone()), data)?;104 }: add_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)320 let data = create_data(b as usize);105321 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), collection, 1, data)106 remove_collection_admin {322107 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();323 set_schema_version {108 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();324 let caller: T::AccountId = account("caller", 0, SEED);109 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();325 let collection = create_nft_collection::<T>(caller.clone())?;110 let mode: CollectionMode = CollectionMode::NFT;326 }: set_schema_version(RawOrigin::Signed(caller.clone()), 2, SchemaVersion::Unique)111 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());327112 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;328 set_collection_limits{113 let new_admin: T::AccountId = account("admin", 0, SEED);329 let caller: T::AccountId = account("caller", 0, SEED);114 Nft::<T>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, new_admin.clone())?;330 let collection = create_nft_collection::<T>(caller.clone())?;115 }: remove_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)331116332 let cl = CollectionLimits {117 set_collection_sponsor {333 account_token_ownership_limit: 0,118 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();334 sponsored_data_size: 0,119 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();335 token_limit: 1,120 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();336 sponsor_transfer_timeout: 0,121 let mode: CollectionMode = CollectionMode::NFT;337 owner_can_destroy: true,122 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());338 owner_can_transfer: true,123 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;339 sponsored_data_rate_limit: None,124 }: set_collection_sponsor(RawOrigin::Signed(caller.clone()), 2, caller.clone())340 };125341 }: set_collection_limits(RawOrigin::Signed(caller.clone()), 2, cl)126 confirm_sponsorship {127 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();128 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();129 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();130 let mode: CollectionMode = CollectionMode::NFT;131 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());132 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;133 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;134 }: confirm_sponsorship(RawOrigin::Signed(caller.clone()), 2)135136 remove_collection_sponsor {137 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();138 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();139 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();140 let mode: CollectionMode = CollectionMode::NFT;141 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());142 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;143 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;144 Nft::<T>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;145 }: remove_collection_sponsor(RawOrigin::Signed(caller.clone()), 2)146147 // nft item148 create_item_nft {149 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();150 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();151 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();152 let mode: CollectionMode = CollectionMode::NFT;153 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());154 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;155 let data = default_nft_data();156157 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)158159 #[extra]160 create_item_nft_large {161 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();162 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();163 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();164 let mode: CollectionMode = CollectionMode::NFT;165 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());166 let mut nft_data = CreateNftData {167 const_data: vec![],168 variable_data: vec![]169 };170 for i in 0..1998 {171 nft_data.const_data.push(10);172 nft_data.variable_data.push(10);173 }174 let data = CreateItemData::NFT(nft_data);175 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;176177 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)178179 // fungible item180 create_item_fungible {181 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();182 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();183 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();184 let mode: CollectionMode = CollectionMode::Fungible(3);185 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());186 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;187 let data = default_fungible_data();188189 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)190191 // refungible item192 create_item_refungible {193 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();194 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();195 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();196 let mode: CollectionMode = CollectionMode::ReFungible(3);197 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());198 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;199 let data = default_re_fungible_data();200201 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)202203 burn_item {204 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();205 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();206 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();207 let mode: CollectionMode = CollectionMode::NFT;208 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());209 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;210 let data = default_nft_data();211 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;212213 }: burn_item(RawOrigin::Signed(caller.clone()), 2, 1)214215 transfer_nft {216 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();217 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();218 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();219 let mode: CollectionMode = CollectionMode::NFT;220 let recipient: T::AccountId = account("recipient", 0, SEED);221 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());222 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;223 let data = default_nft_data();224 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;225226 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)227228 transfer_fungible {229 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();230 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();231 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();232 let mode: CollectionMode = CollectionMode::Fungible(3);233 let recipient: T::AccountId = account("recipient", 0, SEED);234 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());235 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;236 let data = default_fungible_data();237 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;238239 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)240241 transfer_refungible {242 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();243 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();244 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();245 let mode: CollectionMode = CollectionMode::ReFungible(3);246 let recipient: T::AccountId = account("recipient", 0, SEED);247 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());248 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;249 let data = default_re_fungible_data();250 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;251252 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)253254 approve {255 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();256 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();257 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();258 let mode: CollectionMode = CollectionMode::ReFungible(3);259 let recipient: T::AccountId = account("recipient", 0, SEED);260 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());261 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;262 let data = default_re_fungible_data();263 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;264265 }: approve(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1)266267 // Nft268 transfer_from_nft {269 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();270 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();271 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();272 let mode: CollectionMode = CollectionMode::NFT;273 let recipient: T::AccountId = account("recipient", 0, SEED);274 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());275 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;276 let data = default_nft_data();277 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;278 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;279280 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)281282 // Fungible283 transfer_from_fungible {284 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();285 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();286 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();287 let mode: CollectionMode = CollectionMode::Fungible(3);288 let recipient: T::AccountId = account("recipient", 0, SEED);289 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());290 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;291 let data = default_fungible_data();292 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;293 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;294295 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)296297 // ReFungible298 transfer_from_refungible {299 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();300 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();301 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();302 let mode: CollectionMode = CollectionMode::ReFungible(3);303 let recipient: T::AccountId = account("recipient", 0, SEED);304 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());305 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;306 let data = default_re_fungible_data();307 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;308 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;309310 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)311312 enable_contract_sponsoring {313 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());314315 }: enable_contract_sponsoring(RawOrigin::Signed(caller.clone()), caller.clone(), true)316317 set_offchain_schema {318 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();319 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();320 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();321 let mode: CollectionMode = CollectionMode::ReFungible(3);322 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());323 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;324325 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())326327 set_const_on_chain_schema {328 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();329 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();330 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();331 let mode: CollectionMode = CollectionMode::ReFungible(3);332 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());333 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;334 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())335336 set_variable_on_chain_schema {337 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();338 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();339 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();340 let mode: CollectionMode = CollectionMode::ReFungible(3);341 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());342 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;343 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())344345 set_variable_meta_data {346 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();347 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();348 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();349 let mode: CollectionMode = CollectionMode::NFT;350 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());351 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;352 let data = default_nft_data();353 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;354355 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())356357 set_schema_version {358 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();359 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();360 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();361 let mode: CollectionMode = CollectionMode::NFT;362 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());363 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;364 }: set_schema_version(RawOrigin::Signed(caller.clone()), 2, SchemaVersion::Unique)365366 set_chain_limits {367 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());368 let limits = ChainLimits {369 collection_numbers_limit: 0,370 account_token_ownership_limit: 0,371 collections_admins_limit: 0,372 custom_data_limit: 0,373 nft_sponsor_transfer_timeout: 0,374 fungible_sponsor_transfer_timeout: 0,375 refungible_sponsor_transfer_timeout: 0376 };377 }: set_chain_limits(RawOrigin::Signed(caller.clone()), limits)378379 set_contract_sponsoring_rate_limit {380 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();381 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();382 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();383 let mode: CollectionMode = CollectionMode::NFT;384 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());385 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;386 let block_number: T::BlockNumber = 0.into();387 }: set_contract_sponsoring_rate_limit(RawOrigin::Signed(caller.clone()), caller.clone(), block_number)388389 set_collection_limits{390 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();391 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();392 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();393 let mode: CollectionMode = CollectionMode::NFT;394 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());395 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;396397 let cl = CollectionLimits {398 account_token_ownership_limit: 0,399 sponsored_data_size: 0,400 token_limit: 0,401 sponsor_transfer_timeout: 0402 };403404 }: set_collection_limits(RawOrigin::Signed(caller.clone()), 2, cl)405406 add_to_contract_white_list{407 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());408 }: add_to_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())409410 remove_from_contract_white_list{411 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());412 Nft::<T>::add_to_contract_white_list(RawOrigin::Signed(caller.clone()).into(), caller.clone(), caller.clone())?;413 }: remove_from_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())414415 toggle_contract_white_list{416 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());417 }: toggle_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), true)418*/419}342}420343pallets/nft/src/default_weights.rsdiffbeforeafterbothno changes
pallets/nft/src/lib.rsdiffbeforeafterboth40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,40 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,41 CUSTOM_DATA_LIMIT, COLLECTION_NUMBER_LIMIT, ACCOUNT_TOKEN_OWNERSHIP_LIMIT,41 CUSTOM_DATA_LIMIT, COLLECTION_NUMBER_LIMIT, ACCOUNT_TOKEN_OWNERSHIP_LIMIT,42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, COLLECTION_ADMINS_LIMIT,42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, COLLECTION_ADMINS_LIMIT,43 OFFCHAIN_SCHEMA_LIMIT, AccessMode, Collection, CreateItemData, CollectionLimits, CollectionId,43 OFFCHAIN_SCHEMA_LIMIT, MAX_TOKEN_PREFIX_LENGTH, MAX_COLLECTION_NAME_LENGTH,44 MAX_COLLECTION_DESCRIPTION_LENGTH, AccessMode, Collection, CreateItemData, CollectionLimits,44 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,45 CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,45 FungibleItemType, ReFungibleItemType,46 FungibleItemType, ReFungibleItemType,46};47};51#[cfg(test)]52#[cfg(test)]52mod tests;53mod tests;535454mod default_weights;55mod eth;55mod eth;56mod sponsorship;56mod sponsorship;57pub use sponsorship::NftSponsorshipHandler;57pub use sponsorship::NftSponsorshipHandler;64#[cfg(feature = "runtime-benchmarks")]64#[cfg(feature = "runtime-benchmarks")]65mod benchmarking;65mod benchmarking;6667pub trait WeightInfo {66pub mod weights;68 fn create_collection() -> Weight;69 fn destroy_collection() -> Weight;70 fn add_to_white_list() -> Weight;71 fn remove_from_white_list() -> Weight;72 fn set_public_access_mode() -> Weight;73 fn set_mint_permission() -> Weight;74 fn change_collection_owner() -> Weight;75 fn add_collection_admin() -> Weight;76 fn remove_collection_admin() -> Weight;77 fn set_collection_sponsor() -> Weight;78 fn confirm_sponsorship() -> Weight;79 fn remove_collection_sponsor() -> Weight;80 fn create_item(s: usize) -> Weight;67use weights::WeightInfo;81 fn burn_item() -> Weight;82 fn transfer() -> Weight;83 fn approve() -> Weight;84 fn transfer_from() -> Weight;85 fn set_offchain_schema() -> Weight;86 fn set_const_on_chain_schema() -> Weight;87 fn set_variable_on_chain_schema() -> Weight;88 fn set_variable_meta_data() -> Weight;89 fn enable_contract_sponsoring() -> Weight;90 fn set_schema_version() -> Weight;91 fn set_contract_sponsoring_rate_limit() -> Weight;92 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;93 fn toggle_contract_white_list() -> Weight;94 fn add_to_contract_white_list() -> Weight;95 fn remove_from_contract_white_list() -> Weight;96 fn set_collection_limits() -> Weight;97}986899decl_error! {69decl_error! {100 /// Error for non-fungible-token module.70 /// Error for non-fungible-token module.255 type TreasuryAccountId: Get<Self::AccountId>;225 type TreasuryAccountId: Get<Self::AccountId>;256}226}227228type SelfWeightOf<T> = <T as Config>::WeightInfo;229230trait WeightInfoHelpers: WeightInfo {231 fn transfer() -> Weight {232 Self::transfer_nft()233 .max(Self::transfer_fungible())234 .max(Self::transfer_refungible())235 }236 fn transfer_from() -> Weight {237 Self::transfer_from_nft()238 .max(Self::transfer_from_fungible())239 .max(Self::transfer_from_refungible())240 }241 fn approve() -> Weight {242 // TODO: refungible, fungible243 Self::approve_nft()244 }245 fn set_variable_meta_data(data: u32) -> Weight {246 // TODO: refungible247 Self::set_variable_meta_data_nft(data)248 }249 fn create_item(data: u32) -> Weight {250 Self::create_item_nft(data)251 .max(Self::create_item_fungible())252 .max(Self::create_item_refungible(data))253 }254 fn burn_item() -> Weight {255 // TODO: refungible, fungible256 Self::burn_item_nft()257 }258}259impl<T: WeightInfo> WeightInfoHelpers for T {}257260258// # Used definitions261// # Used definitions259//262//464 ///467 ///465 /// * mode: [CollectionMode] collection type and type dependent data.468 /// * mode: [CollectionMode] collection type and type dependent data.466 // returns collection ID469 // returns collection ID467 #[weight = <T as Config>::WeightInfo::create_collection()]470 #[weight = <SelfWeightOf<T>>::create_collection()]468 #[transactional]471 #[transactional]469 pub fn create_collection(origin,472 pub fn create_collection(origin,470 collection_name: Vec<u16>,473 collection_name: Vec<u16>,501504502 // check params505 // check params503 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);506 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);504 ensure!(collection_name.len() <= 64, Error::<T>::CollectionNameLimitExceeded);507 ensure!(collection_name.len() <= MAX_COLLECTION_NAME_LENGTH, Error::<T>::CollectionNameLimitExceeded);505 ensure!(collection_description.len() <= 256, Error::<T>::CollectionDescriptionLimitExceeded);508 ensure!(collection_description.len() <= MAX_COLLECTION_DESCRIPTION_LENGTH, Error::<T>::CollectionDescriptionLimitExceeded);506 ensure!(token_prefix.len() <= 16, Error::<T>::CollectionTokenPrefixLimitExceeded);509 ensure!(token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH, Error::<T>::CollectionTokenPrefixLimitExceeded);507510508 // Generate next collection ID511 // Generate next collection ID509 let next_id = created_count512 let next_id = created_count554 /// # Arguments557 /// # Arguments555 ///558 ///556 /// * collection_id: collection to destroy.559 /// * collection_id: collection to destroy.557 #[weight = <T as Config>::WeightInfo::destroy_collection()]560 #[weight = <SelfWeightOf<T>>::destroy_collection()]558 #[transactional]561 #[transactional]559 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {562 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {560563602 /// * collection_id.605 /// * collection_id.603 ///606 ///604 /// * address.607 /// * address.605 #[weight = <T as Config>::WeightInfo::add_to_white_list()]608 #[weight = <SelfWeightOf<T>>::add_to_white_list()]606 #[transactional]609 #[transactional]607 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{610 pub fn add_to_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{608611631 /// * collection_id.634 /// * collection_id.632 ///635 ///633 /// * address.636 /// * address.634 #[weight = <T as Config>::WeightInfo::remove_from_white_list()]637 #[weight = <SelfWeightOf<T>>::remove_from_white_list()]635 #[transactional]638 #[transactional]636 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{639 pub fn remove_from_white_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{637640659 /// * collection_id.662 /// * collection_id.660 ///663 ///661 /// * mode: [AccessMode]664 /// * mode: [AccessMode]662 #[weight = <T as Config>::WeightInfo::set_public_access_mode()]665 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]663 #[transactional]666 #[transactional]664 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult667 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult665 {668 {684 /// * collection_id.687 /// * collection_id.685 ///688 ///686 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.689 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.687 #[weight = <T as Config>::WeightInfo::set_mint_permission()]690 #[weight = <SelfWeightOf<T>>::set_mint_permission()]688 #[transactional]691 #[transactional]689 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult692 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult690 {693 {707 /// * collection_id.710 /// * collection_id.708 ///711 ///709 /// * new_owner.712 /// * new_owner.710 #[weight = <T as Config>::WeightInfo::change_collection_owner()]713 #[weight = <SelfWeightOf<T>>::change_collection_owner()]711 #[transactional]714 #[transactional]712 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {715 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {713716731 /// * collection_id: ID of the Collection to add admin for.734 /// * collection_id: ID of the Collection to add admin for.732 ///735 ///733 /// * new_admin_id: Address of new admin to add.736 /// * new_admin_id: Address of new admin to add.734 #[weight = <T as Config>::WeightInfo::add_collection_admin()]737 #[weight = <SelfWeightOf<T>>::add_collection_admin()]735 #[transactional]738 #[transactional]736 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {739 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {737 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);762 /// * collection_id: ID of the Collection to remove admin for.765 /// * collection_id: ID of the Collection to remove admin for.763 ///766 ///764 /// * account_id: Address of admin to remove.767 /// * account_id: Address of admin to remove.765 #[weight = <T as Config>::WeightInfo::remove_collection_admin()]768 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]766 #[transactional]769 #[transactional]767 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {770 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {768 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);786 /// * collection_id.789 /// * collection_id.787 ///790 ///788 /// * new_sponsor.791 /// * new_sponsor.789 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]792 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]790 #[transactional]793 #[transactional]791 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {794 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {792 let sender = ensure_signed(origin)?;795 let sender = ensure_signed(origin)?;804 /// # Arguments807 /// # Arguments805 ///808 ///806 /// * collection_id.809 /// * collection_id.807 #[weight = <T as Config>::WeightInfo::confirm_sponsorship()]810 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]808 #[transactional]811 #[transactional]809 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {812 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {810 let sender = ensure_signed(origin)?;813 let sender = ensure_signed(origin)?;828 /// # Arguments831 /// # Arguments829 ///832 ///830 /// * collection_id.833 /// * collection_id.831 #[weight = <T as Config>::WeightInfo::remove_collection_sponsor()]834 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]832 #[transactional]835 #[transactional]833 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {836 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {834 let sender = ensure_signed(origin)?;837 let sender = ensure_signed(origin)?;864 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))867 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))865 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]868 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]866869867 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]870 #[weight = <SelfWeightOf<T>>::create_item(data.data_size() as u32)]868 #[transactional]871 #[transactional]869 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {872 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {870 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);873 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);893 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].896 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].894 ///897 ///895 /// * owner: Address, initial owner of the NFT.898 /// * owner: Address, initial owner of the NFT.896 #[weight = <T as Config>::WeightInfo::create_item(items_data.iter()899 #[weight = <SelfWeightOf<T>>::create_item(items_data.iter()897 .map(|data| { data.data_size() })900 .map(|data| { data.data_size() as u32 })898 .sum())]901 .sum())]899 #[transactional]902 #[transactional]900 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {903 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {921 /// * collection_id: ID of the collection.924 /// * collection_id: ID of the collection.922 ///925 ///923 /// * value: New flag value.926 /// * value: New flag value.924 #[weight = <T as Config>::WeightInfo::burn_item()]927 #[weight = <SelfWeightOf<T>>::burn_item()]925 #[transactional]928 #[transactional]926 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {929 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {927930947 /// * collection_id: ID of the collection.950 /// * collection_id: ID of the collection.948 ///951 ///949 /// * item_id: ID of NFT to burn.952 /// * item_id: ID of NFT to burn.950 #[weight = <T as Config>::WeightInfo::burn_item()]953 #[weight = <SelfWeightOf<T>>::burn_item()]951 #[transactional]954 #[transactional]952 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {955 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {953956982 /// * Non-Fungible Mode: Ignored985 /// * Non-Fungible Mode: Ignored983 /// * Fungible Mode: Must specify transferred amount986 /// * Fungible Mode: Must specify transferred amount984 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)987 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)985 #[weight = <T as Config>::WeightInfo::transfer()]988 #[weight = <SelfWeightOf<T>>::transfer()]986 #[transactional]989 #[transactional]987 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {990 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResult {988 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);991 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1008 /// * collection_id.1011 /// * collection_id.1009 ///1012 ///1010 /// * item_id: ID of the item.1013 /// * item_id: ID of the item.1011 #[weight = <T as Config>::WeightInfo::approve()]1014 #[weight = <SelfWeightOf<T>>::approve()]1012 #[transactional]1015 #[transactional]1013 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResult {1016 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResult {1014 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1017 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1038 /// * item_id: ID of the item.1041 /// * item_id: ID of the item.1039 ///1042 ///1040 /// * value: Amount to transfer.1043 /// * value: Amount to transfer.1041 #[weight = <T as Config>::WeightInfo::transfer_from()]1044 #[weight = <SelfWeightOf<T>>::transfer_from()]1042 #[transactional]1045 #[transactional]1043 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResult {1046 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResult {1044 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1047 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1073 /// * collection_id.1076 /// * collection_id.1074 ///1077 ///1075 /// * schema: String representing the offchain data schema.1078 /// * schema: String representing the offchain data schema.1076 #[weight = <T as Config>::WeightInfo::set_variable_meta_data()]1079 #[weight = <SelfWeightOf<T>>::set_variable_meta_data(data.len() as u32)]1077 #[transactional]1080 #[transactional]1078 pub fn set_variable_meta_data (1081 pub fn set_variable_meta_data (1079 origin,1082 origin,1104 /// * collection_id.1107 /// * collection_id.1105 ///1108 ///1106 /// * schema: SchemaVersion: enum1109 /// * schema: SchemaVersion: enum1107 #[weight = <T as Config>::WeightInfo::set_schema_version()]1110 #[weight = <SelfWeightOf<T>>::set_schema_version()]1108 #[transactional]1111 #[transactional]1109 pub fn set_schema_version(1112 pub fn set_schema_version(1110 origin,1113 origin,1130 /// * collection_id.1133 /// * collection_id.1131 ///1134 ///1132 /// * schema: String representing the offchain data schema.1135 /// * schema: String representing the offchain data schema.1133 #[weight = <T as Config>::WeightInfo::set_offchain_schema()]1136 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1134 #[transactional]1137 #[transactional]1135 pub fn set_offchain_schema(1138 pub fn set_offchain_schema(1136 origin,1139 origin,1160 /// * collection_id.1163 /// * collection_id.1161 ///1164 ///1162 /// * schema: String representing the const on-chain data schema.1165 /// * schema: String representing the const on-chain data schema.1163 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1166 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1164 #[transactional]1167 #[transactional]1165 pub fn set_const_on_chain_schema (1168 pub fn set_const_on_chain_schema (1166 origin,1169 origin,1190 /// * collection_id.1193 /// * collection_id.1191 ///1194 ///1192 /// * schema: String representing the variable on-chain data schema.1195 /// * schema: String representing the variable on-chain data schema.1193 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1196 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1194 #[transactional]1197 #[transactional]1195 pub fn set_variable_on_chain_schema (1198 pub fn set_variable_on_chain_schema (1196 origin,1199 origin,1208 target_collection.save()1211 target_collection.save()1209 }1212 }121012131211 #[weight = <T as Config>::WeightInfo::set_collection_limits()]1214 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1212 #[transactional]1215 #[transactional]1213 pub fn set_collection_limits(1216 pub fn set_collection_limits(1214 origin,1217 origin,pallets/nft/src/weights.rsdiffbeforeafterbothno changes
primitives/nft/src/lib.rsdiffbeforeafterboth55pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;55pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;56pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;56pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;5758pub const MAX_COLLECTION_NAME_LENGTH: usize = 64;59pub const MAX_COLLECTION_DESCRIPTION_LENGTH: usize = 256;60pub const MAX_TOKEN_PREFIX_LENGTH: usize = 16;576158/// How much items can be created per single62/// How much items can be created per single59/// create_many call63/// create_many callruntime/src/lib.rsdiffbeforeafterboth119/// Digest item type.119/// Digest item type.120pub type DigestItem = generic::DigestItem<Hash>;120pub type DigestItem = generic::DigestItem<Hash>;121122mod nft_weights;123121124/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know122/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know125/// the specifics of the runtime. They can then be made to be agnostic over specific formats123/// the specifics of the runtime. They can then be made to be agnostic over specific formats695/// Used for the pallet nft in `./nft.rs`693/// Used for the pallet nft in `./nft.rs`696impl pallet_nft::Config for Runtime {694impl pallet_nft::Config for Runtime {697 type Event = Event;695 type Event = Event;698 type WeightInfo = nft_weights::WeightInfo;696 type WeightInfo = pallet_nft::weights::SubstrateWeight<Self>;699697700 type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;698 type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;701 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;699 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;runtime/src/nft_weights.rsdiffbeforeafterbothno changes