difftreelog
feat benchmark property calls
in: master
30 files changed
Cargo.lockdiffbeforeafterboth5913dependencies = [5913dependencies = [5914 "evm-coder",5914 "evm-coder",5915 "fp-evm-mapping",5915 "fp-evm-mapping",5916 "frame-benchmarking",5916 "frame-support",5917 "frame-support",5917 "frame-system",5918 "frame-system",5918 "pallet-evm",5919 "pallet-evm",6649 "frame-support",6650 "frame-support",6650 "frame-system",6651 "frame-system",6651 "pallet-common",6652 "pallet-common",6653 "pallet-evm",6652 "parity-scale-codec 3.1.2",6654 "parity-scale-codec 3.1.2",6653 "scale-info",6655 "scale-info",6654 "sp-std",6656 "sp-std",Makefilediffbeforeafterboth41bench-evm-migration:41bench-evm-migration:42 make _bench PALLET=evm-migration42 make _bench PALLET=evm-migration4344.PHONY: bench-common45bench-common:46 make _bench PALLET=common434744.PHONY: bench-unique48.PHONY: bench-unique45bench-unique:49bench-unique:pallets/common/Cargo.tomldiffbeforeafterboth25scale-info = { version = "2.0.1", default-features = false, features = [25scale-info = { version = "2.0.1", default-features = false, features = [26 "derive",26 "derive",27] }27] }28frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }282929[features]30[features]30default = ["std"]31default = ["std"]38 "pallet-evm/std",39 "pallet-evm/std",39]40]40runtime-benchmarks = []41runtime-benchmarks = [42 "frame-benchmarking"43]4144pallets/common/src/benchmarking.rsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617use sp_std::vec::Vec;17use sp_std::vec::Vec;18use crate::{Config, CollectionHandle};18use crate::{Config, CollectionHandle, Pallet};19use pallet_evm::account::CrossAccountId;20use frame_benchmarking::{benchmarks, account};19use up_data_structs::{21use up_data_structs::{20 CollectionMode, CreateCollectionData, CollectionId, MAX_COLLECTION_NAME_LENGTH,22 CollectionMode, CreateCollectionData, CollectionId, Property, PropertyKey, PropertyValue,21 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,23 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,22 CONST_ON_CHAIN_SCHEMA_LIMIT,24 OFFCHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, MAX_PROPERTIES_PER_ITEM,23};25};24use frame_support::{26use frame_support::{25 traits::{Currency, Get},27 traits::{Currency, Get},29use core::convert::TryInto;31use core::convert::TryInto;30use sp_runtime::DispatchError;32use sp_runtime::DispatchError;3334const SEED: u32 = 1;313532pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {36pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {33 create_var_data::<S>(S)37 create_var_data::<S>(S)52 .try_into()56 .try_into()53 .unwrap()57 .unwrap()54}58}59pub fn property_key(id: usize) -> PropertyKey {60 #[cfg(not(feature = "std"))]61 use alloc::string::ToString;62 let mut data = create_data();63 // No DerefMut available for .fill64 for i in 0..data.len() {65 data[i] = b'0';66 }67 let bytes = id.to_string();68 let len = data.len();69 data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());70 data71}72pub fn property_value() -> PropertyValue {73 create_data()74}557556pub fn create_collection_raw<T: Config, R>(76pub fn create_collection_raw<T: Config, R>(57 owner: T::AccountId,77 owner: T::AccountId,83 .and_then(CollectionHandle::try_get)103 .and_then(CollectionHandle::try_get)84 .map(cast)104 .map(cast)85}105}106fn create_collection<T: Config>(owner: T::AccountId) -> Result<CollectionHandle<T>, DispatchError> {107 create_collection_raw(108 owner,109 CollectionMode::NFT,110 |owner, data| <Pallet<T>>::init_collection(owner, data),111 |h| h,112 )113}8611487/// Helper macros, which handles all benchmarking preparation in semi-declarative way115/// Helper macros, which handles all benchmarking preparation in semi-declarative way88///116///126 () => {}154 () => {}127}155}156157benchmarks! {158 set_collection_properties {159 let b in 0..MAX_PROPERTIES_PER_ITEM;160 bench_init!{161 owner: sub; collection: collection(owner);162 owner: cross_from_sub;163 };164 let props = (0..b).map(|p| Property {165 key: property_key(p as usize),166 value: property_value(),167 }).collect::<Vec<_>>();168 }: {<Pallet<T>>::set_collection_properties(&collection, &owner, props)?}169170 delete_collection_properties {171 let b in 0..MAX_PROPERTIES_PER_ITEM;172 bench_init!{173 owner: sub; collection: collection(owner);174 owner: cross_from_sub;175 };176 let props = (0..b).map(|p| Property {177 key: property_key(p as usize),178 value: property_value(),179 }).collect::<Vec<_>>();180 <Pallet<T>>::set_collection_properties(&collection, &owner, props)?;181 let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();182 }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete)?}183}128184pallets/common/src/lib.rsdiffbeforeafterboth161617#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]1819extern crate alloc;182019use core::ops::{Deref, DerefMut};21use core::ops::{Deref, DerefMut};20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};22use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};85pub mod dispatch;87pub mod dispatch;86pub mod erc;88pub mod erc;87pub mod eth;89pub mod eth;90pub mod weights;9192pub type SelfWeightOf<T> = <T as Config>::WeightInfo;889389#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]94#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]90pub struct CollectionHandle<T: Config> {95pub struct CollectionHandle<T: Config> {186 use frame_support::traits::Currency;191 use frame_support::traits::Currency;187 use up_data_structs::{TokenId, mapping::TokenAddressMapping};192 use up_data_structs::{TokenId, mapping::TokenAddressMapping};188 use scale_info::TypeInfo;193 use scale_info::TypeInfo;194 use weights::WeightInfo;189195190 #[pallet::config]196 #[pallet::config]191 pub trait Config:197 pub trait Config:192 frame_system::Config + pallet_evm_coder_substrate::Config + TypeInfo + account::Config198 frame_system::Config + pallet_evm_coder_substrate::Config + TypeInfo + account::Config193 {199 {200 type WeightInfo: WeightInfo;194 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;201 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;195202196 type Currency: Currency<Self::AccountId>;203 type Currency: Currency<Self::AccountId>;1131/// Worst cases1139/// Worst cases1132pub trait CommonWeightInfo<CrossAccountId> {1140pub trait CommonWeightInfo<CrossAccountId> {1133 fn create_item() -> Weight;1141 fn create_item() -> Weight;1134 fn create_multiple_items(amount: u32) -> Weight;1142 fn create_multiple_items(amount: &[CreateItemData]) -> Weight;1135 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;1143 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;1136 fn burn_item() -> Weight;1144 fn burn_item() -> Weight;1137 fn set_collection_properties(amount: u32) -> Weight;1145 fn set_collection_properties(amount: u32) -> Weight;pallets/common/src/weights.rsdiffbeforeafterbothno changes
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth40 owner: sub; collection: collection(owner);40 owner: sub; collection: collection(owner);41 sender: cross_from_sub(owner); to: cross_sub;41 sender: cross_from_sub(owner); to: cross_sub;42 };42 };43 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}43 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200), &Unlimited)?}444445 create_multiple_items_ex {45 create_multiple_items_ex {46 let b in 0..MAX_ITEMS_PER_BATCH;46 let b in 0..MAX_ITEMS_PER_BATCH;52 bench_init!(to: cross_sub(i););52 bench_init!(to: cross_sub(i););53 (to, 200)53 (to, 200)54 }).collect::<BTreeMap<_, _>>().try_into().unwrap();54 }).collect::<BTreeMap<_, _>>().try_into().unwrap();55 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}55 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}565657 burn_item {57 burn_item {58 bench_init!{58 bench_init!{59 owner: sub; collection: collection(owner);59 owner: sub; collection: collection(owner);60 owner: cross_from_sub; burner: cross_sub;60 owner: cross_from_sub; burner: cross_sub;61 };61 };62 <Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200))?;62 <Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?;63 }: {<Pallet<T>>::burn(&collection, &burner, 100)?}63 }: {<Pallet<T>>::burn(&collection, &burner, 100)?}646465 transfer {65 transfer {66 bench_init!{66 bench_init!{67 owner: sub; collection: collection(owner);67 owner: sub; collection: collection(owner);68 owner: cross_from_sub; sender: cross_sub; to: cross_sub;68 owner: cross_from_sub; sender: cross_sub; to: cross_sub;69 };69 };70 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;70 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;71 }: {<Pallet<T>>::transfer(&collection, &sender, &to, 200)?}71 }: {<Pallet<T>>::transfer(&collection, &sender, &to, 200, &Unlimited)?}727273 approve {73 approve {74 bench_init!{74 bench_init!{75 owner: sub; collection: collection(owner);75 owner: sub; collection: collection(owner);76 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;76 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;77 };77 };78 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;78 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;79 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}79 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}808081 transfer_from {81 transfer_from {82 bench_init!{82 bench_init!{83 owner: sub; collection: collection(owner);83 owner: sub; collection: collection(owner);84 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;84 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;85 };85 };86 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;86 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;87 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;87 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;88 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100, &Unlimited)?}88 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100, &Unlimited)?}898992 owner: sub; collection: collection(owner);92 owner: sub; collection: collection(owner);93 owner: cross_from_sub; sender: cross_sub; burner: cross_sub;93 owner: cross_from_sub; sender: cross_sub; burner: cross_sub;94 };94 };95 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;95 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;96 <Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;96 <Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;97 }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?}97 }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?}98}98}pallets/fungible/src/common.rsdiffbeforeafterboth17use core::marker::PhantomData;17use core::marker::PhantomData;181819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};19use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget};20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};22use sp_runtime::ArithmeticError;22use sp_runtime::ArithmeticError;23use sp_std::{vec::Vec, vec};23use sp_std::{vec::Vec, vec};33 <SelfWeightOf<T>>::create_item()33 <SelfWeightOf<T>>::create_item()34 }34 }353536 fn create_multiple_items(_amount: u32) -> Weight {36 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {37 // All items minted for the same user, so it works same as create_item37 Self::create_item()38 Self::create_item()38 }39 }394051 }52 }525353 fn set_collection_properties(amount: u32) -> Weight {54 fn set_collection_properties(amount: u32) -> Weight {54 <SelfWeightOf<T>>::set_collection_properties(amount)55 // Error56 055 }57 }565857 fn delete_collection_properties(amount: u32) -> Weight {59 fn delete_collection_properties(amount: u32) -> Weight {58 <SelfWeightOf<T>>::delete_collection_properties(amount)60 // Error61 059 }62 }606361 fn set_token_properties(amount: u32) -> Weight {64 fn set_token_properties(amount: u32) -> Weight {62 <SelfWeightOf<T>>::set_token_properties(amount)65 // Error66 063 }67 }646865 fn delete_token_properties(amount: u32) -> Weight {69 fn delete_token_properties(amount: u32) -> Weight {66 <SelfWeightOf<T>>::delete_token_properties(amount)70 // Error71 067 }72 }687369 fn set_property_permissions(amount: u32) -> Weight {74 fn set_property_permissions(amount: u32) -> Weight {70 <SelfWeightOf<T>>::set_property_permissions(amount)75 // Error76 071 }77 }727873 fn transfer() -> Weight {79 fn transfer() -> Weight {pallets/fungible/src/weights.rsdiffbeforeafterboth35 fn create_item() -> Weight;35 fn create_item() -> Weight;36 fn create_multiple_items_ex(b: u32, ) -> Weight;36 fn create_multiple_items_ex(b: u32, ) -> Weight;37 fn burn_item() -> Weight;37 fn burn_item() -> Weight;38 fn set_collection_properties(amount: u32) -> Weight;39 fn delete_collection_properties(amount: u32) -> Weight;40 fn set_token_properties(amount: u32) -> Weight;41 fn delete_token_properties(amount: u32) -> Weight;42 fn set_property_permissions(amount: u32) -> Weight;43 fn transfer() -> Weight;38 fn transfer() -> Weight;44 fn approve() -> Weight;39 fn approve() -> Weight;45 fn transfer_from() -> Weight;40 fn transfer_from() -> Weight;75 .saturating_add(T::DbWeight::get().writes(2 as Weight))70 .saturating_add(T::DbWeight::get().writes(2 as Weight))76 }71 }7778 fn set_collection_properties(_amount: u32) -> Weight {79 // Error80 081 }8283 fn delete_collection_properties(_amount: u32) -> Weight {84 // Error85 086 }8788 fn set_token_properties(_amount: u32) -> Weight {89 // Error90 091 }9293 fn delete_token_properties(_amount: u32) -> Weight {94 // Error95 096 }9798 fn set_property_permissions(_amount: u32) -> Weight {99 // Error100 0101 }10272103 // Storage: Fungible Balance (r:2 w:2)73 // Storage: Fungible Balance (r:2 w:2)104 fn transfer() -> Weight {74 fn transfer() -> Weight {158 .saturating_add(RocksDbWeight::get().writes(2 as Weight))128 .saturating_add(RocksDbWeight::get().writes(2 as Weight))159 }129 }160161 fn set_collection_properties(_amount: u32) -> Weight {162 // Error163 0164 }165166 fn delete_collection_properties(_amount: u32) -> Weight {167 // Error168 0169 }170171 fn set_token_properties(_amount: u32) -> Weight {172 // Error173 0174 }175176 fn delete_token_properties(_amount: u32) -> Weight {177 // Error178 0179 }180181 fn set_property_permissions(_amount: u32) -> Weight {182 // Error183 0184 }185130186 // Storage: Fungible Balance (r:2 w:2)131 // Storage: Fungible Balance (r:2 w:2)187 fn transfer() -> Weight {132 fn transfer() -> Weight {pallets/nonfungible/Cargo.tomldiffbeforeafterboth49 'frame-benchmarking',49 'frame-benchmarking',50 'frame-support/runtime-benchmarks',50 'frame-support/runtime-benchmarks',51 'frame-system/runtime-benchmarks',51 'frame-system/runtime-benchmarks',52 'up-data-structs/runtime-benchmarks',52]53]5354pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth18use crate::{Pallet, Config, NonfungibleHandle};18use crate::{Pallet, Config, NonfungibleHandle};191920use sp_std::prelude::*;20use sp_std::prelude::*;21use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};21use pallet_common::benchmarking::{create_collection_raw, create_data, property_key, property_value};22use frame_benchmarking::{benchmarks, account};22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited};23use up_data_structs::{24 CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, CUSTOM_DATA_LIMIT,25 budget::Unlimited,26};24use pallet_common::bench_init;27use pallet_common::bench_init;25use core::convert::TryInto;262827const SEED: u32 = 1;29const SEED: u32 = 1;283029fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {31fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {30 let const_data = create_data::<CUSTOM_DATA_LIMIT>();32 let const_data = create_data::<CUSTOM_DATA_LIMIT>();31 CreateItemData::<T> { const_data, owner }33 CreateItemData::<T> {34 const_data,35 owner,36 properties: Default::default(),37 }32}38}33fn create_max_item<T: Config>(39fn create_max_item<T: Config>(34 collection: &NonfungibleHandle<T>,40 collection: &NonfungibleHandle<T>,35 sender: &T::CrossAccountId,41 sender: &T::CrossAccountId,36 owner: T::CrossAccountId,42 owner: T::CrossAccountId,37) -> Result<TokenId, DispatchError> {43) -> Result<TokenId, DispatchError> {38 <Pallet<T>>::create_item(&collection, sender, create_max_item_data::<T>(owner))?;44 <Pallet<T>>::create_item(45 &collection,46 sender,47 create_max_item_data::<T>(owner),48 &Unlimited,49 )?;39 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))50 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))40}51}65 sender: cross_from_sub(owner); to: cross_sub;76 sender: cross_from_sub(owner); to: cross_sub;66 };77 };67 let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();78 let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();68 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}79 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}698070 create_multiple_items_ex {81 create_multiple_items_ex {71 let b in 0..MAX_ITEMS_PER_BATCH;82 let b in 0..MAX_ITEMS_PER_BATCH;77 bench_init!(to: cross_sub(i););88 bench_init!(to: cross_sub(i););78 create_max_item_data::<T>(to)89 create_max_item_data::<T>(to)79 }).collect();90 }).collect();80 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}91 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}819282 burn_item {93 burn_item {83 bench_init!{94 bench_init!{93 owner: cross_from_sub; sender: cross_sub; receiver: cross_sub;104 owner: cross_from_sub; sender: cross_sub; receiver: cross_sub;94 };105 };95 let item = create_max_item(&collection, &owner, sender.clone())?;106 let item = create_max_item(&collection, &owner, sender.clone())?;96 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item)?}107 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, &Unlimited)?}9710898 approve {109 approve {99 bench_init!{110 bench_init!{121 <Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;132 <Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;122 }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?}133 }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?}134135 set_property_permissions {136 let b in 0..MAX_PROPERTIES_PER_ITEM;137 bench_init!{138 owner: sub; collection: collection(owner);139 owner: cross_from_sub;140 };141 let perms = (0..b).map(|k| PropertyKeyPermission {142 key: property_key(k as usize),143 permission: PropertyPermission {144 mutable: false,145 collection_admin: false,146 token_owner: false,147 },148 }).collect::<Vec<_>>();149 }: {<Pallet<T>>::set_property_permissions(&collection, &owner, perms)?}150151 set_token_properties {152 let b in 0..MAX_PROPERTIES_PER_ITEM;153 bench_init!{154 owner: sub; collection: collection(owner);155 owner: cross_from_sub;156 };157 let perms = (0..b).map(|k| PropertyKeyPermission {158 key: property_key(k as usize),159 permission: PropertyPermission {160 mutable: false,161 collection_admin: true,162 token_owner: true,163 },164 }).collect::<Vec<_>>();165 <Pallet<T>>::set_property_permissions(&collection, &owner, perms)?;166 let props = (0..b).map(|k| Property {167 key: property_key(k as usize),168 value: property_value(),169 }).collect::<Vec<_>>();170 let item = create_max_item(&collection, &owner, owner.clone())?;171 }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props)?}172173 delete_token_properties {174 let b in 0..MAX_PROPERTIES_PER_ITEM;175 bench_init!{176 owner: sub; collection: collection(owner);177 owner: cross_from_sub;178 };179 let perms = (0..b).map(|k| PropertyKeyPermission {180 key: property_key(k as usize),181 permission: PropertyPermission {182 mutable: true,183 collection_admin: true,184 token_owner: true,185 },186 }).collect::<Vec<_>>();187 <Pallet<T>>::set_property_permissions(&collection, &owner, perms)?;188 let props = (0..b).map(|k| Property {189 key: property_key(k as usize),190 value: property_value(),191 }).collect::<Vec<_>>();192 let item = create_max_item(&collection, &owner, owner.clone())?;193 <Pallet<T>>::set_token_properties(&collection, &owner, item, props)?;194 let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();195 }: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete)?}123}196}124197pallets/nonfungible/src/common.rsdiffbeforeafterboth22 PropertyKeyPermission, PropertyValue,22 PropertyKeyPermission, PropertyValue,23};23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};24use pallet_common::{25 CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _,26};25use sp_runtime::DispatchError;27use sp_runtime::DispatchError;26use sp_std::vec::Vec;28use sp_std::vec::Vec;384039 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {41 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40 match data {42 match data {41 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),43 CreateItemExData::NFT(t) => {44 <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32)45 + t.iter()46 .map(|t| {47 if t.properties.len() > 0 {48 Self::set_token_properties(t.properties.len() as u32)49 } else {50 051 }52 })53 .sum::<u64>()54 }42 _ => 0,55 _ => 0,43 }56 }44 }57 }455846 fn create_multiple_items(amount: u32) -> Weight {59 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {47 <SelfWeightOf<T>>::create_multiple_items(amount)60 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32)61 + data62 .iter()63 .filter_map(|t| match t {64 up_data_structs::CreateItemData::NFT(n) if n.properties.len() > 0 => {65 Some(Self::set_token_properties(n.properties.len() as u32))66 }67 _ => None,68 })69 .sum::<u64>()48 }70 }497150 fn burn_item() -> Weight {72 fn burn_item() -> Weight {51 <SelfWeightOf<T>>::burn_item()73 <SelfWeightOf<T>>::burn_item()52 }74 }537554 fn set_collection_properties(amount: u32) -> Weight {76 fn set_collection_properties(amount: u32) -> Weight {55 <SelfWeightOf<T>>::set_collection_properties(amount)77 <pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)56 }78 }577958 fn delete_collection_properties(amount: u32) -> Weight {80 fn delete_collection_properties(amount: u32) -> Weight {59 <SelfWeightOf<T>>::delete_collection_properties(amount)81 <pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)60 }82 }618362 fn set_token_properties(amount: u32) -> Weight {84 fn set_token_properties(amount: u32) -> Weight {128 data: Vec<up_data_structs::CreateItemData>,150 data: Vec<up_data_structs::CreateItemData>,129 nesting_budget: &dyn Budget,151 nesting_budget: &dyn Budget,130 ) -> DispatchResultWithPostInfo {152 ) -> DispatchResultWithPostInfo {153 let weight = <CommonWeights<T>>::create_multiple_items(&data);131 let data = data154 let data = data132 .into_iter()155 .into_iter()133 .map(|d| map_create_data::<T>(d, &to))156 .map(|d| map_create_data::<T>(d, &to))134 .collect::<Result<Vec<_>, DispatchError>>()?;157 .collect::<Result<Vec<_>, DispatchError>>()?;135158136 let amount = data.len();137 with_weight(159 with_weight(138 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),160 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),139 <CommonWeights<T>>::create_multiple_items(amount as u32),161 weight,140 )162 )141 }163 }142164pallets/nonfungible/src/lib.rsdiffbeforeafterboth181819use erc::ERC721Events;19use erc::ERC721Events;20use evm_coder::ToLog;20use evm_coder::ToLog;21use frame_support::{BoundedVec, ensure, fail, transactional};21use frame_support::{BoundedVec, ensure, fail, transactional, storage::with_transaction};22use up_data_structs::{22use up_data_structs::{23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,32use pallet_structure::Pallet as PalletStructure;32use pallet_structure::Pallet as PalletStructure;33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};34use sp_core::H160;34use sp_core::H160;35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};36use sp_std::{vec::Vec, vec};36use sp_std::{vec::Vec, vec};37use core::ops::Deref;37use core::ops::Deref;38use sp_std::collections::btree_map::BTreeMap;38use sp_std::collections::btree_map::BTreeMap;600600601 // =========601 // =========602603 with_transaction(|| {604 for (i, data) in data.iter().enumerate() {605 let token = first_token + i as u32 + 1;606607 <TokenData<T>>::insert(608 (collection.id, token),609 ItemData {610 const_data: data.const_data.clone(),611 owner: data.owner.clone(),612 },613 );614615 if let Err(e) = Self::set_token_properties(616 collection,617 sender,618 TokenId(token),619 data.properties.clone().into_inner(),620 ) {621 return TransactionOutcome::Rollback(Err(e));622 }623 }624 TransactionOutcome::Commit(Ok(()))625 })?;602626603 <TokensMinted<T>>::insert(collection.id, tokens_minted);627 <TokensMinted<T>>::insert(collection.id, tokens_minted);604 for (account, balance) in balances {628 for (account, balance) in balances {607 for (i, data) in data.into_iter().enumerate() {631 for (i, data) in data.into_iter().enumerate() {608 let token = first_token + i as u32 + 1;632 let token = first_token + i as u32 + 1;609610 <TokenData<T>>::insert(611 (collection.id, token),612 ItemData {613 const_data: data.const_data,614 owner: data.owner.clone(),615 },616 );617 <Owned<T>>::insert((collection.id, &data.owner, token), true);633 <Owned<T>>::insert((collection.id, &data.owner, token), true);618619 Self::set_token_properties(620 collection,621 sender,622 TokenId(token),623 data.properties.into_inner(),624 )?;625634626 <PalletEvm<T>>::deposit_log(635 <PalletEvm<T>>::deposit_log(627 ERC721Events::Transfer {636 ERC721Events::Transfer {pallets/nonfungible/src/weights.rsdiffbeforeafterboth150 // Storage: Nonfungible TokensBurnt (r:1 w:1)150 // Storage: Nonfungible TokensBurnt (r:1 w:1)151 // Storage: Nonfungible AccountBalance (r:1 w:1)151 // Storage: Nonfungible AccountBalance (r:1 w:1)152 // Storage: Nonfungible Owned (r:0 w:1)152 // Storage: Nonfungible Owned (r:0 w:1)153 fn burn_from() -> Weight {153 fn burn_from() -> Weight {154 }155 // Storage: Common CollectionPropertyPermissions (r:1 w:1)156 fn set_property_permissions(b: u32, ) -> Weight {154 (27_580_000 as Weight)157 (0 as Weight)158 // Standard Error: 3_432_000159 .saturating_add((126_888_000 as Weight).saturating_mul(b as Weight))155 .saturating_add(T::DbWeight::get().reads(4 as Weight))160 .saturating_add(T::DbWeight::get().reads(1 as Weight))156 .saturating_add(T::DbWeight::get().writes(5 as Weight))161 .saturating_add(T::DbWeight::get().writes(1 as Weight))157 }162 }163 // Storage: Common CollectionPropertyPermissions (r:1 w:0)164 // Storage: Nonfungible TokenData (r:1 w:0)165 // Storage: Nonfungible TokenProperties (r:1 w:1)166 fn set_token_properties(b: u32, ) -> Weight {167 (0 as Weight)168 // Standard Error: 158_583_000169 .saturating_add((4_707_700_000 as Weight).saturating_mul(b as Weight))170 .saturating_add(T::DbWeight::get().reads(3 as Weight))171 .saturating_add(T::DbWeight::get().writes(1 as Weight))172 }173 // Storage: Common CollectionPropertyPermissions (r:1 w:0)174 // Storage: Nonfungible TokenData (r:1 w:0)175 // Storage: Nonfungible TokenProperties (r:1 w:1)176 fn delete_token_properties(b: u32, ) -> Weight {177 (0 as Weight)178 // Standard Error: 169_018_000179 .saturating_add((4_783_967_000 as Weight).saturating_mul(b as Weight))180 .saturating_add(T::DbWeight::get().reads(3 as Weight))181 .saturating_add(T::DbWeight::get().writes(1 as Weight))182 }158}183}159184160// For backwards compatibility and tests185// For backwards compatibility and tests259 // Storage: Nonfungible TokensBurnt (r:1 w:1)284 // Storage: Nonfungible TokensBurnt (r:1 w:1)260 // Storage: Nonfungible AccountBalance (r:1 w:1)285 // Storage: Nonfungible AccountBalance (r:1 w:1)261 // Storage: Nonfungible Owned (r:0 w:1)286 // Storage: Nonfungible Owned (r:0 w:1)262 fn burn_from() -> Weight {287 fn burn_from() -> Weight {288 }289 // Storage: Common CollectionPropertyPermissions (r:1 w:1)290 fn set_property_permissions(b: u32, ) -> Weight {263 (27_580_000 as Weight)291 (0 as Weight)292 // Standard Error: 3_432_000293 .saturating_add((126_888_000 as Weight).saturating_mul(b as Weight))264 .saturating_add(RocksDbWeight::get().reads(4 as Weight))294 .saturating_add(RocksDbWeight::get().reads(1 as Weight))265 .saturating_add(RocksDbWeight::get().writes(5 as Weight))295 .saturating_add(RocksDbWeight::get().writes(1 as Weight))266 }296 }297 // Storage: Common CollectionPropertyPermissions (r:1 w:0)298 // Storage: Nonfungible TokenData (r:1 w:0)299 // Storage: Nonfungible TokenProperties (r:1 w:1)300 fn set_token_properties(b: u32, ) -> Weight {301 (0 as Weight)302 // Standard Error: 158_583_000303 .saturating_add((4_707_700_000 as Weight).saturating_mul(b as Weight))304 .saturating_add(RocksDbWeight::get().reads(3 as Weight))305 .saturating_add(RocksDbWeight::get().writes(1 as Weight))306 }307 // Storage: Common CollectionPropertyPermissions (r:1 w:0)308 // Storage: Nonfungible TokenData (r:1 w:0)309 // Storage: Nonfungible TokenProperties (r:1 w:1)310 fn delete_token_properties(b: u32, ) -> Weight {311 (0 as Weight)312 // Standard Error: 169_018_000313 .saturating_add((4_783_967_000 as Weight).saturating_mul(b as Weight))314 .saturating_add(RocksDbWeight::get().reads(3 as Weight))315 .saturating_add(RocksDbWeight::get().writes(1 as Weight))316 }267}317}268318pallets/refungible/src/benchmarking.rsdiffbeforeafterboth18use crate::{Pallet, Config, RefungibleHandle};18use crate::{Pallet, Config, RefungibleHandle};191920use sp_std::prelude::*;20use sp_std::prelude::*;21use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};21use pallet_common::benchmarking::{create_collection_raw, create_data};22use frame_benchmarking::{benchmarks, account};22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited};23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited};24use pallet_common::bench_init;24use pallet_common::bench_init;46 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,46 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,47) -> Result<TokenId, DispatchError> {47) -> Result<TokenId, DispatchError> {48 let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);48 let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);49 <Pallet<T>>::create_item(&collection, sender, data)?;49 <Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;50 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))50 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))51}51}525273 sender: cross_from_sub(owner); to: cross_sub;73 sender: cross_from_sub(owner); to: cross_sub;74 };74 };75 let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();75 let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();76 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}76 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}777778 create_multiple_items_ex_multiple_items {78 create_multiple_items_ex_multiple_items {79 let b in 0..MAX_ITEMS_PER_BATCH;79 let b in 0..MAX_ITEMS_PER_BATCH;85 bench_init!(to: cross_sub(t););85 bench_init!(to: cross_sub(t););86 create_max_item_data([(to, 200)])86 create_max_item_data([(to, 200)])87 }).collect();87 }).collect();88 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}88 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}898990 create_multiple_items_ex_multiple_owners {90 create_multiple_items_ex_multiple_owners {91 let b in 0..MAX_ITEMS_PER_BATCH;91 let b in 0..MAX_ITEMS_PER_BATCH;97 bench_init!(to: cross_sub(u););97 bench_init!(to: cross_sub(u););98 (to, 200)98 (to, 200)99 }))].try_into().unwrap();99 }))].try_into().unwrap();100 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}100 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}101101102 // Other user left, token data is kept102 // Other user left, token data is kept103 burn_item_partial {103 burn_item_partial {122 sender: cross_from_sub(owner); receiver: cross_sub;122 sender: cross_from_sub(owner); receiver: cross_sub;123 };123 };124 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;124 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;125 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100)?}125 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}126 // Target account is created126 // Target account is created127 transfer_creating {127 transfer_creating {128 bench_init!{128 bench_init!{129 owner: sub; collection: collection(owner);129 owner: sub; collection: collection(owner);130 sender: cross_from_sub(owner); receiver: cross_sub;130 sender: cross_from_sub(owner); receiver: cross_sub;131 };131 };132 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;132 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;133 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100)?}133 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}134 // Source account is destroyed134 // Source account is destroyed135 transfer_removing {135 transfer_removing {136 bench_init!{136 bench_init!{137 owner: sub; collection: collection(owner);137 owner: sub; collection: collection(owner);138 sender: cross_from_sub(owner); receiver: cross_sub;138 sender: cross_from_sub(owner); receiver: cross_sub;139 };139 };140 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;140 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;141 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200)?}141 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}142 // Source account destroyed, target created142 // Source account destroyed, target created143 transfer_creating_removing {143 transfer_creating_removing {144 bench_init!{144 bench_init!{145 owner: sub; collection: collection(owner);145 owner: sub; collection: collection(owner);146 sender: cross_from_sub(owner); receiver: cross_sub;146 sender: cross_from_sub(owner); receiver: cross_sub;147 };147 };148 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;148 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;149 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200)?}149 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}150150151 approve {151 approve {152 bench_init!{152 bench_init!{pallets/refungible/src/common.rsdiffbeforeafterboth20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};21use up_data_structs::{21use up_data_structs::{22 CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,22 CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,23 PropertyKey, PropertyValue, PropertyKeyPermission,23 PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData,24};24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;26use sp_runtime::DispatchError;46 <SelfWeightOf<T>>::create_item()46 <SelfWeightOf<T>>::create_item()47 }47 }484849 fn create_multiple_items(amount: u32) -> Weight {49 fn create_multiple_items(data: &[CreateItemData]) -> Weight {50 <SelfWeightOf<T>>::create_multiple_items(amount)50 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32)51 }51 }525253 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {53 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {66 max_weight_of!(burn_item_partial(), burn_item_fully())66 max_weight_of!(burn_item_partial(), burn_item_fully())67 }67 }686869 fn set_collection_properties(amount: u32) -> Weight {69 fn set_collection_properties(_amount: u32) -> Weight {70 <SelfWeightOf<T>>::set_collection_properties(amount)70 // Error71 071 }72 }727373 fn delete_collection_properties(amount: u32) -> Weight {74 fn delete_collection_properties(_amount: u32) -> Weight {74 <SelfWeightOf<T>>::delete_collection_properties(amount)75 // Error76 075 }77 }767877 fn set_token_properties(amount: u32) -> Weight {79 fn set_token_properties(amount: u32) -> Weight {156 data: Vec<up_data_structs::CreateItemData>,158 data: Vec<up_data_structs::CreateItemData>,157 nesting_budget: &dyn Budget,159 nesting_budget: &dyn Budget,158 ) -> DispatchResultWithPostInfo {160 ) -> DispatchResultWithPostInfo {161 let weight = <CommonWeights<T>>::create_multiple_items(&data);159 let data = data162 let data = data160 .into_iter()163 .into_iter()161 .map(|d| map_create_data::<T>(d, &to))164 .map(|d| map_create_data::<T>(d, &to))162 .collect::<Result<Vec<_>, DispatchError>>()?;165 .collect::<Result<Vec<_>, DispatchError>>()?;163166164 let amount = data.len();165 with_weight(167 with_weight(166 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),168 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),167 <CommonWeights<T>>::create_multiple_items(amount as u32),169 weight,168 )170 )169 }171 }170172pallets/refungible/src/weights.rsdiffbeforeafterboth38 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;38 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;39 fn burn_item_partial() -> Weight;39 fn burn_item_partial() -> Weight;40 fn burn_item_fully() -> Weight;40 fn burn_item_fully() -> Weight;41 fn set_collection_properties(amount: u32) -> Weight;42 fn delete_collection_properties(amount: u32) -> Weight;43 fn set_token_properties(amount: u32) -> Weight;41 fn set_token_properties(amount: u32) -> Weight;44 fn delete_token_properties(amount: u32) -> Weight;42 fn delete_token_properties(amount: u32) -> Weight;45 fn set_property_permissions(amount: u32) -> Weight;43 fn set_property_permissions(amount: u32) -> Weight;134 .saturating_add(T::DbWeight::get().writes(6 as Weight))132 .saturating_add(T::DbWeight::get().writes(6 as Weight))135 }133 }136137 fn set_collection_properties(_amount: u32) -> Weight {138 // Error139 0140 }141142 fn delete_collection_properties(_amount: u32) -> Weight {143 // Error144 0145 }146134147 fn set_token_properties(_amount: u32) -> Weight {135 fn set_token_properties(_amount: u32) -> Weight {148 // Error136 // Error322 .saturating_add(RocksDbWeight::get().writes(6 as Weight))310 .saturating_add(RocksDbWeight::get().writes(6 as Weight))323 }311 }324325 fn set_collection_properties(_amount: u32) -> Weight {326 // Error327 0328 }329330 fn delete_collection_properties(_amount: u32) -> Weight {331 // Error332 0333 }334312335 fn set_token_properties(_amount: u32) -> Weight {313 fn set_token_properties(_amount: u32) -> Weight {336 // Error314 // Errorpallets/structure/Cargo.tomldiffbeforeafterboth16 "derive",16 "derive",17] }17] }18up-data-structs = { path = "../../primitives/data-structs", default-features = false }18up-data-structs = { path = "../../primitives/data-structs", default-features = false }19pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }192020[features]21[features]21default = ["std"]22default = ["std"]28 "scale-info/std",29 "scale-info/std",29 "parity-scale-codec/std",30 "parity-scale-codec/std",30 "up-data-structs/std",31 "up-data-structs/std",32 "pallet-evm/std",31]33]32runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']34runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']3335pallets/structure/src/benchmarking.rsdiffbeforeafterboth3use frame_benchmarking::{benchmarks, account};3use frame_benchmarking::{benchmarks, account};4use frame_support::traits::{Currency, Get};4use frame_support::traits::{Currency, Get};5use up_data_structs::{CreateCollectionData, CollectionMode, CreateItemData, CreateNftData};5use up_data_structs::{6 CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,7};6use pallet_common::CrossAccountId;8use pallet_evm::account::CrossAccountId;798const SEED: u32 = 1;10const SEED: u32 = 1;91120 let dispatch = T::CollectionDispatch::dispatch(CollectionHandle::try_get(CollectionId(1))?);22 let dispatch = T::CollectionDispatch::dispatch(CollectionHandle::try_get(CollectionId(1))?);21 let dispatch = dispatch.as_dyn();23 let dispatch = dispatch.as_dyn();222423 dispatch.create_item(caller_cross.clone(), caller_cross.clone(), CreateItemData::NFT(CreateNftData::default()))?;25 dispatch.create_item(caller_cross.clone(), caller_cross.clone(), CreateItemData::NFT(CreateNftData::default()), &Unlimited)?;24 }: {26 }: {25 let parent = <Pallet<T>>::find_parent(CollectionId(1), TokenId(1))?;27 let parent = <Pallet<T>>::find_parent(CollectionId(1), TokenId(1))?;26 assert!(matches!(parent, Parent::Normal(_)))28 assert!(matches!(parent, Parent::User(_)))27 }29 }28}30}2931pallets/unique/src/lib.rsdiffbeforeafterboth687 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].687 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].688 ///688 ///689 /// * owner: Address, initial owner of the NFT.689 /// * owner: Address, initial owner of the NFT.690 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]690 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]691 #[transactional]691 #[transactional]692 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {692 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {693 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);693 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);primitives/data-structs/Cargo.tomldiffbeforeafterboth42]42]43serde1 = ["serde"]43serde1 = ["serde"]44limit-testing = []44limit-testing = []4545runtime-benchmarks = []primitives/data-structs/src/lib.rsdiffbeforeafterboth862 let value_len = value.len();862 let value_len = value.len();863863864 if self.consumed_space as usize + value_len > self.space_limit as usize {864 if self.consumed_space as usize + value_len > self.space_limit as usize865 && !cfg!(feature = "runtime-benchmarks")866 {865 return Err(PropertiesError::NoSpaceForProperty);867 return Err(PropertiesError::NoSpaceForProperty);866 }868 }runtime/common/src/eth_sponsoring.rsdiffbeforeafterboth51 let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;51 let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;52 match call {52 match call {53 UniqueNFTCall::TokenProperties(53 UniqueNFTCall::TokenProperties(TokenPropertiesCall::SetProperty {54 TokenPropertiesCall::SetProperty { token_id, key, value, .. },54 token_id,55 key,56 value,57 ..runtime/common/src/runtime_apis.rsdiffbeforeafterboth776 let mut list = Vec::<BenchmarkList>::new();776 let mut list = Vec::<BenchmarkList>::new();777777778 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);778 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);779 list_benchmark!(list, extra, pallet_common, Common);779 list_benchmark!(list, extra, pallet_unique, Unique);780 list_benchmark!(list, extra, pallet_unique, Unique);780 list_benchmark!(list, extra, pallet_structure, Structure);781 list_benchmark!(list, extra, pallet_structure, Structure);781 list_benchmark!(list, extra, pallet_inflation, Inflation);782 list_benchmark!(list, extra, pallet_inflation, Inflation);814 let params = (&config, &allowlist);815 let params = (&config, &allowlist);815816816 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);817 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);818 add_benchmark!(params, batches, pallet_common, Common);817 add_benchmark!(params, batches, pallet_unique, Unique);819 add_benchmark!(params, batches, pallet_unique, Unique);818 add_benchmark!(params, batches, pallet_structure, Structure);820 add_benchmark!(params, batches, pallet_structure, Structure);819 add_benchmark!(params, batches, pallet_inflation, Inflation);821 add_benchmark!(params, batches, pallet_inflation, Inflation);runtime/common/src/sponsoring.rsdiffbeforeafterbothno syntactic changes
runtime/common/src/weights.rsdiffbeforeafterboth21use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};21use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};23use pallet_refungible::{Config as RefungibleConfig, common::CommonWeights as RefungibleWeights};23use pallet_refungible::{Config as RefungibleConfig, common::CommonWeights as RefungibleWeights};24use up_data_structs::CreateItemExData;24use up_data_structs::{CreateItemExData, CreateItemData};252526macro_rules! max_weight_of {26macro_rules! max_weight_of {27 ($method:ident ( $($args:tt)* )) => {27 ($method:ident ( $($args:tt)* )) => {42 dispatch_weight::<T>() + max_weight_of!(create_item())42 dispatch_weight::<T>() + max_weight_of!(create_item())43 }43 }444445 fn create_multiple_items(amount: u32) -> Weight {45 fn create_multiple_items(data: &[CreateItemData]) -> Weight {46 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(amount))46 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))47 }47 }484849 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {49 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {runtime/opal/src/lib.rsdiffbeforeafterboth875}875}876876877impl pallet_common::Config for Runtime {877impl pallet_common::Config for Runtime {878 type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;878 type Event = Event;879 type Event = Event;879 type Currency = Balances;880 type Currency = Balances;880 type CollectionCreationPrice = CollectionCreationPrice;881 type CollectionCreationPrice = CollectionCreationPrice;runtime/tests/src/lib.rsdiffbeforeafterboth212}212}213213214impl pallet_common::Config for Test {214impl pallet_common::Config for Test {215 type WeightInfo = ();215 type Event = ();216 type Event = ();216 type Currency = Balances;217 type Currency = Balances;217 type CollectionCreationPrice = CollectionCreationPrice;218 type CollectionCreationPrice = CollectionCreationPrice;runtime/unique/Cargo.tomldiffbeforeafterboth39 'pallet-xcm/runtime-benchmarks',39 'pallet-xcm/runtime-benchmarks',40 'sp-runtime/runtime-benchmarks',40 'sp-runtime/runtime-benchmarks',41 'xcm-builder/runtime-benchmarks',41 'xcm-builder/runtime-benchmarks',42 'up-data-structs/runtime-benchmarks',42]43]43try-runtime = [44try-runtime = [44 'frame-try-runtime',45 'frame-try-runtime',runtime/unique/src/lib.rsdiffbeforeafterboth66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,67 },67 },68};68};69use unique_runtime_common::dispatch::{CollectionDispatchT, CollectionDispatch};69use unique_runtime_common::{70 dispatch::{CollectionDispatchT, CollectionDispatch},71 weights::CommonWeights,72 sponsoring::UniqueSponsorshipHandler,73 eth_sponsoring::UniqueEthSponsorshipHandler,74};70use up_data_structs::*;75use up_data_structs::*;71// use pallet_contracts::weights::WeightInfo;76// use pallet_contracts::weights::WeightInfo;72// #[cfg(any(feature = "std", test))]77// #[cfg(any(feature = "std", test))]846}851}847852848impl pallet_common::Config for Runtime {853impl pallet_common::Config for Runtime {854 type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;849 type Event = Event;855 type Event = Event;850 type Currency = Balances;856 type Currency = Balances;851 type CollectionCreationPrice = CollectionCreationPrice;857 type CollectionCreationPrice = CollectionCreationPrice;881impl pallet_unique::Config for Runtime {887impl pallet_unique::Config for Runtime {882 type Event = Event;888 type Event = Event;883 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;889 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;890 type CommonWeightInfo = CommonWeights<Self>;884}891}885892886parameter_types! {893parameter_types! {902// }909// }903910904type EvmSponsorshipHandler = (911type EvmSponsorshipHandler = (905 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,912 UniqueEthSponsorshipHandler<Runtime>,906 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,913 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,907);914);908type SponsorshipHandler = (915type SponsorshipHandler = (909 pallet_unique::UniqueSponsorshipHandler<Runtime>,916 UniqueSponsorshipHandler<Runtime>,910 //pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,917 //pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,911 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,918 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,912);919);