difftreelog
fix EVM mint with properties, minor improvements
in: master
9 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth29use sp_std::{vec, vec::Vec};29use sp_std::{vec, vec::Vec};30use up_data_structs::{30use up_data_structs::{31 AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,31 AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,32 NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue,32 NestingPermissions, Property, PropertyKey, PropertyValue, MAX_COLLECTION_DESCRIPTION_LENGTH,33 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM,33 MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM, MAX_TOKEN_PREFIX_LENGTH,34 MAX_TOKEN_PREFIX_LENGTH,35};34};195 Ok(())194 Ok(())196 }195 }197198 #[benchmark]199 fn delete_collection_properties(200 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,201 ) -> Result<(), BenchmarkError> {202 bench_init! {203 owner: sub; collection: collection(owner);204 owner: cross_from_sub;205 };206 let props = (0..b)207 .map(|p| Property {208 key: property_key(p as usize),209 value: property_value(),210 })211 .collect::<Vec<_>>();212 <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;213 let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();214215 #[block]216 {217 <Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?;218 }219220 Ok(())221 }222196223 #[benchmark]197 #[benchmark]224 fn check_accesslist() -> Result<(), BenchmarkError> {198 fn check_accesslist() -> Result<(), BenchmarkError> {253 }227 }254228255 #[benchmark]229 #[benchmark]256 fn init_token_properties_common() -> Result<(), BenchmarkError> {230 fn property_writer_load_collection_info() -> Result<(), BenchmarkError> {257 bench_init! {231 bench_init! {258 owner: sub; collection: collection(owner);232 owner: sub; collection: collection(owner);259 sender: sub;233 sender: sub;pallets/common/src/erc.rsdiffbeforeafterboth126 ///126 ///127 /// @param key Property key.127 /// @param key Property key.128 #[solidity(hide)]128 #[solidity(hide)]129 #[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]129 #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]130 fn delete_collection_property(&mut self, caller: Caller, key: String) -> Result<()> {130 fn delete_collection_property(&mut self, caller: Caller, key: String) -> Result<()> {131 let caller = T::CrossAccountId::from_eth(caller);131 let caller = T::CrossAccountId::from_eth(caller);132 let key = <Vec<u8>>::from(key)132 let key = <Vec<u8>>::from(key)139 /// Delete collection properties.139 /// Delete collection properties.140 ///140 ///141 /// @param keys Properties keys.141 /// @param keys Properties keys.142 #[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]142 #[weight(<SelfWeightOf<T>>::set_collection_properties(keys.len() as u32))]143 fn delete_collection_properties(&mut self, caller: Caller, keys: Vec<String>) -> Result<()> {143 fn delete_collection_properties(&mut self, caller: Caller, keys: Vec<String>) -> Result<()> {144 let caller = T::CrossAccountId::from_eth(caller);144 let caller = T::CrossAccountId::from_eth(caller);145 let keys = keys145 let keys = keyspallets/common/src/lib.rsdiffbeforeafterboth2626impl<T: Config> BenchmarkPropertyWriter<T> {2626impl<T: Config> BenchmarkPropertyWriter<T> {2627 /// Creates a [`PropertyWriter`] for benchmarking tokens properties writing.2627 /// Creates a [`PropertyWriter`] for benchmarking tokens properties writing.2628 pub fn new<'a, Handle>(2628 pub fn new<'a, Handle>(2629 collection: &Handle,2629 collection: &'a Handle,2630 collection_lazy_info: PropertyWriterLazyCollectionInfo,2630 collection_lazy_info: PropertyWriterLazyCollectionInfo<'a>,2631 ) -> PropertyWriter<'a, Self, T, Handle>2631 ) -> PropertyWriter<'a, Self, T, Handle>2632 where2632 where2633 Handle: CommonCollectionOperations<T> + Deref<Target = CollectionHandle<T>>,2633 Handle: CommonCollectionOperations<T> + Deref<Target = CollectionHandle<T>>,pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth18use pallet_common::{18use pallet_common::{19 bench_init,19 bench_init,20 benchmarking::{create_collection_raw, property_key, property_value},20 benchmarking::{create_collection_raw, property_key, property_value},21 CommonCollectionOperations,22};21};23use sp_std::prelude::*;22use sp_std::prelude::*;24use up_data_structs::{23use up_data_structs::{136 Ok(())135 Ok(())137 }136 }138139 #[benchmark]140 fn burn_recursively_self_raw() -> Result<(), BenchmarkError> {141 bench_init! {142 owner: sub; collection: collection(owner);143 sender: cross_from_sub(owner); burner: cross_sub;144 };145 let item = create_max_item(&collection, &sender, burner.clone())?;146147 #[block]148 {149 <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;150 }151152 Ok(())153 }154155 #[benchmark]156 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(157 b: Linear<0, 200>,158 ) -> Result<(), BenchmarkError> {159 bench_init! {160 owner: sub; collection: collection(owner);161 sender: cross_from_sub(owner); burner: cross_sub;162 };163 let item = create_max_item(&collection, &sender, burner.clone())?;164 for _ in 0..b {165 create_max_item(166 &collection,167 &sender,168 T::CrossTokenAddressMapping::token_to_address(collection.id, item),169 )?;170 }171172 #[block]173 {174 <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;175 }176177 Ok(())178 }179137180 #[benchmark]138 #[benchmark]181 fn transfer_raw() -> Result<(), BenchmarkError> {139 fn transfer_raw() -> Result<(), BenchmarkError> {263 <Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?;221 <Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?;264 }222 }223224 Ok(())265 }225 }266226267 // set_token_properties {227 #[benchmark]268 // let b in 0..MAX_PROPERTIES_PER_ITEM;228 fn load_token_properties() -> Result<(), BenchmarkError> {269 // bench_init!{229 bench_init! {270 // owner: sub; collection: collection(owner);230 owner: sub; collection: collection(owner);271 // owner: cross_from_sub;231 owner: cross_from_sub;272 // };232 };273 // let perms = (0..b).map(|k| PropertyKeyPermission {233274 // key: property_key(k as usize),234 let item = create_max_item(&collection, &owner, owner.clone())?;275 // permission: PropertyPermission {235276 // mutable: false,236 #[block]277 // collection_admin: true,237 {278 // token_owner: true,238 pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);279 // },239 }280 // }).collect::<Vec<_>>();240281 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;241 Ok(())282 // let props = (0..b).map(|k| Property {242 }283 // key: property_key(k as usize),243284 // value: property_value(),244 #[benchmark]285 // }).collect::<Vec<_>>();245 fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {286 // let item = create_max_item(&collection, &owner, owner.clone())?;246 bench_init! {287 // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}247 owner: sub; collection: collection(owner);288248 owner: cross_from_sub;289 // load_token_properties {249 };290 // bench_init!{250291 // owner: sub; collection: collection(owner);251 let perms = (0..b)292 // owner: cross_from_sub;252 .map(|k| PropertyKeyPermission {293 // };253 key: property_key(k as usize),294254 permission: PropertyPermission {295 // let item = create_max_item(&collection, &owner, owner.clone())?;255 mutable: false,296 // }: {256 collection_admin: true,297 // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(257 token_owner: true,298 // &collection,258 },299 // item,259 })300 // )260 .collect::<Vec<_>>();301 // }261 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;302262 let props = (0..b)303 // write_token_properties {263 .map(|k| Property {304 // let b in 0..MAX_PROPERTIES_PER_ITEM;264 key: property_key(k as usize),305 // bench_init!{265 value: property_value(),306 // owner: sub; collection: collection(owner);266 })307 // owner: cross_from_sub;267 .collect::<Vec<_>>();308 // };268 let item = create_max_item(&collection, &owner, owner.clone())?;309269310 // let perms = (0..b).map(|k| PropertyKeyPermission {270 let lazy_collection_info =311 // key: property_key(k as usize),271 pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);312 // permission: PropertyPermission {272313 // mutable: false,273 #[block]314 // collection_admin: true,274 {315 // token_owner: true,275 let mut property_writer =316 // },276 pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);317 // }).collect::<Vec<_>>();277318 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;278 property_writer.write_token_properties(319 // let props = (0..b).map(|k| Property {279 item,320 // key: property_key(k as usize),280 props.into_iter(),321 // value: property_value(),281 crate::erc::ERC721TokenEvent::TokenChanged {322 // }).collect::<Vec<_>>();282 token_id: item.into(),323 // let item = create_max_item(&collection, &owner, owner.clone())?;283 }324284 .to_log(T::ContractAddress::get()),325 // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(285 )?;326 // &collection,286 }327 // &owner,287328 // );288 Ok(())329 // }: {289 }330 // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);331332 // property_writer.write_token_properties(333 // item,334 // props.into_iter(),335 // crate::erc::ERC721TokenEvent::TokenChanged {336 // token_id: item.into(),337 // }338 // .to_log(T::ContractAddress::get()),339 // )?340 // }341290342 #[benchmark]291 #[benchmark]343 fn set_token_property_permissions(292 fn set_token_property_permissions(366 Ok(())315 Ok(())367 }316 }368369 #[benchmark]370 fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {371 bench_init! {372 owner: sub; collection: collection(owner);373 owner: cross_from_sub;374 };375 let perms = (0..b)376 .map(|k| PropertyKeyPermission {377 key: property_key(k as usize),378 permission: PropertyPermission {379 mutable: false,380 collection_admin: true,381 token_owner: true,382 },383 })384 .collect::<Vec<_>>();385 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;386 let props = (0..b)387 .map(|k| Property {388 key: property_key(k as usize),389 value: property_value(),390 })391 .collect::<Vec<_>>();392 let item = create_max_item(&collection, &owner, owner.clone())?;393394 #[block]395 {396 <Pallet<T>>::set_token_properties(397 &collection,398 &owner,399 item,400 props.into_iter(),401 &Unlimited,402 )?;403 }404405 Ok(())406 }407408 // TODO:409 #[benchmark]410 fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {411 // bench_init! {412 // owner: sub; collection: collection(owner);413 // owner: cross_from_sub;414 // };415416 // let perms = (0..b)417 // .map(|k| PropertyKeyPermission {418 // key: property_key(k as usize),419 // permission: PropertyPermission {420 // mutable: false,421 // collection_admin: true,422 // token_owner: true,423 // },424 // })425 // .collect::<Vec<_>>();426 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;427 #[block]428 {}429 // let props = (0..b)430 // .map(|k| Property {431 // key: property_key(k as usize),432 // value: property_value(),433 // })434 // .collect::<Vec<_>>();435 // let item = create_max_item(&collection, &owner, owner.clone())?;436437 // let (is_collection_admin, property_permissions) =438 // load_is_admin_and_property_permissions(&collection, &owner);439 // #[block]440 // {441 // let mut property_writer =442 // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);443444 // property_writer.write_token_properties(445 // item,446 // props.into_iter(),447 // crate::erc::ERC721TokenEvent::TokenChanged {448 // token_id: item.into(),449 // }450 // .to_log(T::ContractAddress::get()),451 // )?;452 // }453454 Ok(())455 }456457 #[benchmark]458 fn delete_token_properties(459 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,460 ) -> Result<(), BenchmarkError> {461 bench_init! {462 owner: sub; collection: collection(owner);463 owner: cross_from_sub;464 };465 let perms = (0..b)466 .map(|k| PropertyKeyPermission {467 key: property_key(k as usize),468 permission: PropertyPermission {469 mutable: true,470 collection_admin: true,471 token_owner: true,472 },473 })474 .collect::<Vec<_>>();475 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;476 let props = (0..b)477 .map(|k| Property {478 key: property_key(k as usize),479 value: property_value(),480 })481 .collect::<Vec<_>>();482 let item = create_max_item(&collection, &owner, owner.clone())?;483 <Pallet<T>>::set_token_properties(484 &collection,485 &owner,486 item,487 props.into_iter(),488 &Unlimited,489 )?;490 let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();491492 #[block]493 {494 <Pallet<T>>::delete_token_properties(495 &collection,496 &owner,497 item,498 to_delete.into_iter(),499 &Unlimited,500 )?;501 }502503 Ok(())504 }505506 #[benchmark]507 fn token_owner() -> Result<(), BenchmarkError> {508 bench_init! {509 owner: sub; collection: collection(owner);510 owner: cross_from_sub;511 };512 let item = create_max_item(&collection, &owner, owner.clone())?;513514 #[block]515 {516 collection.token_owner(item).unwrap();517 }518519 Ok(())520 }521317522 #[benchmark]318 #[benchmark]523 fn set_allowance_for_all() -> Result<(), BenchmarkError> {319 fn set_allowance_for_all() -> Result<(), BenchmarkError> {pallets/nonfungible/src/common.rsdiffbeforeafterboth39impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {39impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {40 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {41 match data {41 match data {42 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32)42 CreateItemExData::NFT(t) => mint_with_props_weight::<T>(43 .saturating_add(write_token_properties_total_weight::<T, _>(43 <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),44 t.iter().map(|t| t.properties.len() as u32),44 t.iter().map(|t| t.properties.len() as u32),45 <SelfWeightOf<T>>::write_token_properties,46 )),45 ),47 _ => Weight::zero(),46 _ => Weight::zero(),48 }47 }49 }48 }504951 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {50 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {51 mint_with_props_weight::<T>(52 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(52 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),53 write_token_properties_total_weight::<T, _>(54 data.iter().map(|t| match t {53 data.iter().map(|t| match t {55 up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,54 up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,56 _ => 0,55 _ => 0,57 }),56 }),58 <SelfWeightOf<T>>::write_token_properties,57 )59 ),60 )61 }58 }625963 fn burn_item() -> Weight {60 fn burn_item() -> Weight {113 }110 }114}111}112113pub(crate) fn mint_with_props_weight<T: Config>(114 create_no_data_weight: Weight,115 tokens: impl Iterator<Item = u32> + Clone,116) -> Weight {117 create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(118 tokens,119 <SelfWeightOf<T>>::write_token_properties,120 ))121}115122116fn map_create_data<T: Config>(123fn map_create_data<T: Config>(117 data: up_data_structs::CreateItemData,124 data: up_data_structs::CreateItemData,pallets/nonfungible/src/erc.rsdiffbeforeafterboth49};49};505051use crate::{51use crate::{52 common::CommonWeights, weights::WeightInfo, AccountBalance, Config, CreateItemData,52 common::{mint_with_props_weight, CommonWeights},53 weights::WeightInfo,53 NonfungibleHandle, Pallet, SelfWeightOf, TokenData, TokenProperties, TokensMinted,54 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, SelfWeightOf, TokenData,55 TokenProperties, TokensMinted,620 /// @param tokenUri Token URI that would be stored in the NFT properties622 /// @param tokenUri Token URI that would be stored in the NFT properties621 /// @return uint256 The id of the newly minted token623 /// @return uint256 The id of the newly minted token622 #[solidity(rename_selector = "mintWithTokenURI")]624 #[solidity(rename_selector = "mintWithTokenURI")]623 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]625 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]624 fn mint_with_token_uri(626 fn mint_with_token_uri(625 &mut self,627 &mut self,626 caller: Caller,628 caller: Caller,642 /// @param tokenId ID of the minted NFT644 /// @param tokenId ID of the minted NFT643 /// @param tokenUri Token URI that would be stored in the NFT properties645 /// @param tokenUri Token URI that would be stored in the NFT properties644 #[solidity(hide, rename_selector = "mintWithTokenURI")]646 #[solidity(hide, rename_selector = "mintWithTokenURI")]645 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]647 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]646 fn mint_with_token_uri_check_id(648 fn mint_with_token_uri_check_id(647 &mut self,649 &mut self,648 caller: Caller,650 caller: Caller,974976975 /// @notice Function to mint a token.977 /// @notice Function to mint a token.976 /// @param data Array of pairs of token owner and token's properties for minted token978 /// @param data Array of pairs of token owner and token's properties for minted token977 #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]979 #[weight(980 mint_with_props_weight::<T>(981 <SelfWeightOf<T>>::create_multiple_items_ex(data.len() as u32),982 data.iter().map(|d| d.properties.len() as u32),983 )984 )]978 fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {985 fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {979 let caller = T::CrossAccountId::from_eth(caller);986 let caller = T::CrossAccountId::from_eth(caller);1008 /// @param to The new owner1015 /// @param to The new owner1009 /// @param tokens array of pairs of token ID and token URI for minted tokens1016 /// @param tokens array of pairs of token ID and token URI for minted tokens1010 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1017 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1011 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]1018 #[weight(1019 mint_with_props_weight::<T>(1020 <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),1021 tokens.iter().map(|_| 1),1022 )1023 )]1012 fn mint_bulk_with_token_uri(1024 fn mint_bulk_with_token_uri(1013 &mut self,1025 &mut self,1056 /// @param to The new owner crossAccountId1068 /// @param to The new owner crossAccountId1057 /// @param properties Properties of minted token1069 /// @param properties Properties of minted token1058 /// @return uint256 The id of the newly minted token1070 /// @return uint256 The id of the newly minted token1059 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]1071 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]1060 fn mint_cross(1072 fn mint_cross(1061 &mut self,1073 &mut self,1062 caller: Caller,1074 caller: Caller,pallets/refungible/src/benchmarking.rsdiffbeforeafterboth421 Ok(())421 Ok(())422 }422 }423423424 // set_token_properties {424 #[benchmark]425 // let b in 0..MAX_PROPERTIES_PER_ITEM;425 fn load_token_properties() -> Result<(), BenchmarkError> {426 // bench_init!{426 bench_init! {427 // owner: sub; collection: collection(owner);427 owner: sub; collection: collection(owner);428 // owner: cross_from_sub;428 owner: cross_from_sub;429 // };429 };430 // let perms = (0..b).map(|k| PropertyKeyPermission {430431 // key: property_key(k as usize),431 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;432 // permission: PropertyPermission {432433 // mutable: false,433 #[block]434 // collection_admin: true,434 {435 // token_owner: true,435 pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);436 // },436 }437 // }).collect::<Vec<_>>();437438 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;438 Ok(())439 // let props = (0..b).map(|k| Property {439 }440 // key: property_key(k as usize),440441 // value: property_value(),441 #[benchmark]442 // }).collect::<Vec<_>>();442 fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {443 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;443 bench_init! {444 // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}444 owner: sub; collection: collection(owner);445445 owner: cross_from_sub;446 // load_token_properties {446 };447 // bench_init!{447448 // owner: sub; collection: collection(owner);448 let perms = (0..b)449 // owner: cross_from_sub;449 .map(|k| PropertyKeyPermission {450 // };450 key: property_key(k as usize),451451 permission: PropertyPermission {452 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;452 mutable: false,453 // }: {453 collection_admin: true,454 // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(454 token_owner: true,455 // &collection,455 },456 // item,456 })457 // )457 .collect::<Vec<_>>();458 // }458 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;459459 let props = (0..b)460 // write_token_properties {460 .map(|k| Property {461 // let b in 0..MAX_PROPERTIES_PER_ITEM;461 key: property_key(k as usize),462 // bench_init!{462 value: property_value(),463 // owner: sub; collection: collection(owner);463 })464 // owner: cross_from_sub;464 .collect::<Vec<_>>();465 // };465 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;466466467 // let perms = (0..b).map(|k| PropertyKeyPermission {467 let lazy_collection_info =468 // key: property_key(k as usize),468 pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);469 // permission: PropertyPermission {469470 // mutable: false,470 #[block]471 // collection_admin: true,471 {472 // token_owner: true,472 let mut property_writer =473 // },473 pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);474 // }).collect::<Vec<_>>();474475 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;475 property_writer.write_token_properties(476 // let props = (0..b).map(|k| Property {476 item,477 // key: property_key(k as usize),477 props.into_iter(),478 // value: property_value(),478 crate::erc::ERC721TokenEvent::TokenChanged {479 // }).collect::<Vec<_>>();479 token_id: item.into(),480 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;480 }481481 .to_log(T::ContractAddress::get()),482 // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(482 )?;483 // &collection,483 }484 // &owner,484485 // );485 Ok(())486 // }: {486 }487 // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);488489 // property_writer.write_token_properties(490 // item,491 // props.into_iter(),492 // crate::erc::ERC721TokenEvent::TokenChanged {493 // token_id: item.into(),494 // }495 // .to_log(T::ContractAddress::get()),496 // )?497 // }498487499 #[benchmark]488 #[benchmark]500 fn set_token_property_permissions(489 fn set_token_property_permissions(523 Ok(())512 Ok(())524 }513 }525526 #[benchmark]527 fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {528 bench_init! {529 owner: sub; collection: collection(owner);530 owner: cross_from_sub;531 };532 let perms = (0..b)533 .map(|k| PropertyKeyPermission {534 key: property_key(k as usize),535 permission: PropertyPermission {536 mutable: false,537 collection_admin: true,538 token_owner: true,539 },540 })541 .collect::<Vec<_>>();542 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;543 let props = (0..b)544 .map(|k| Property {545 key: property_key(k as usize),546 value: property_value(),547 })548 .collect::<Vec<_>>();549 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;550551 #[block]552 {553 <Pallet<T>>::set_token_properties(554 &collection,555 &owner,556 item,557 props.into_iter(),558 &Unlimited,559 )?;560 }561562 Ok(())563 }564565 // TODO:566 #[benchmark]567 fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {568 // bench_init! {569 // owner: sub; collection: collection(owner);570 // owner: cross_from_sub;571 // };572573 // let perms = (0..b)574 // .map(|k| PropertyKeyPermission {575 // key: property_key(k as usize),576 // permission: PropertyPermission {577 // mutable: false,578 // collection_admin: true,579 // token_owner: true,580 // },581 // })582 // .collect::<Vec<_>>();583 // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;584585 #[block]586 {}587 // let props = (0..b).map(|k| Property {588 // key: property_key(k as usize),589 // value: property_value(),590 // }).collect::<Vec<_>>();591 // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;592593 // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner)594 // let mut property_writer = pallet_common::collection_info_loaded_property_writer(595 // &collection,596 // is_collection_admin,597 // property_permissions,598 // );599600 // #[block]601 // {602 // property_writer.write_token_properties(603 // true,604 // item,605 // props.into_iter(),606 // crate::erc::ERC721TokenEvent::TokenChanged {607 // token_id: item.into(),608 // }609 // .to_log(T::ContractAddress::get()),610 // )?;611 // }612613 Ok(())614 }615616 #[benchmark]617 fn delete_token_properties(618 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,619 ) -> Result<(), BenchmarkError> {620 bench_init! {621 owner: sub; collection: collection(owner);622 owner: cross_from_sub;623 };624 let perms = (0..b)625 .map(|k| PropertyKeyPermission {626 key: property_key(k as usize),627 permission: PropertyPermission {628 mutable: true,629 collection_admin: true,630 token_owner: true,631 },632 })633 .collect::<Vec<_>>();634 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;635 let props = (0..b)636 .map(|k| Property {637 key: property_key(k as usize),638 value: property_value(),639 })640 .collect::<Vec<_>>();641 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;642 <Pallet<T>>::set_token_properties(643 &collection,644 &owner,645 item,646 props.into_iter(),647 &Unlimited,648 )?;649 let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();650651 #[block]652 {653 <Pallet<T>>::delete_token_properties(654 &collection,655 &owner,656 item,657 to_delete.into_iter(),658 &Unlimited,659 )?;660 }661662 Ok(())663 }664514665 #[benchmark]515 #[benchmark]666 fn repartition_item() -> Result<(), BenchmarkError> {516 fn repartition_item() -> Result<(), BenchmarkError> {678 Ok(())528 Ok(())679 }529 }680681 #[benchmark]682 fn token_owner() -> Result<(), BenchmarkError> {683 bench_init! {684 owner: sub; collection: collection(owner);685 sender: cross_from_sub(owner); owner: cross_sub;686 };687 let item = create_max_item(&collection, &sender, [(owner, 100)])?;688689 #[block]690 {691 <Pallet<T>>::token_owner(collection.id, item).unwrap();692 }693694 Ok(())695 }696530697 #[benchmark]531 #[benchmark]698 fn set_allowance_for_all() -> Result<(), BenchmarkError> {532 fn set_allowance_for_all() -> Result<(), BenchmarkError> {pallets/refungible/src/common.rsdiffbeforeafterboth47pub struct CommonWeights<T: Config>(PhantomData<T>);47pub struct CommonWeights<T: Config>(PhantomData<T>);48impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {48impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {49 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {49 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {50 mint_with_props_weight::<T>(50 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(51 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),51 write_token_properties_total_weight::<T, _>(52 data.iter().map(|data| match data {52 data.iter().map(|data| match data {53 up_data_structs::CreateItemData::ReFungible(rft_data) => {53 up_data_structs::CreateItemData::ReFungible(rft_data) => {54 rft_data.properties.len() as u3254 rft_data.properties.len() as u3255 }55 }56 _ => 0,56 _ => 0,57 }),57 }),58 <SelfWeightOf<T>>::write_token_properties,58 )59 ),60 )61 }59 }626063 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {61 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {64 match call {62 match call {65 CreateItemExData::RefungibleMultipleOwners(i) => {63 CreateItemExData::RefungibleMultipleOwners(i) => mint_with_props_weight::<T>(66 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)64 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32),67 .saturating_add(write_token_properties_total_weight::<T, _>(68 [i.properties.len() as u32].into_iter(),65 [i.properties.len() as u32].into_iter(),69 <SelfWeightOf<T>>::write_token_properties,66 ),70 ))71 }72 CreateItemExData::RefungibleMultipleItems(i) => {67 CreateItemExData::RefungibleMultipleItems(i) => mint_with_props_weight::<T>(73 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)68 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32),74 .saturating_add(write_token_properties_total_weight::<T, _>(75 i.iter().map(|d| d.properties.len() as u32),69 i.iter().map(|d| d.properties.len() as u32),76 <SelfWeightOf<T>>::write_token_properties,70 ),77 ))78 }79 _ => Weight::zero(),71 _ => Weight::zero(),80 }72 }81 }73 }138 }130 }139}131}132133pub(crate) fn mint_with_props_weight<T: Config>(134 create_no_data_weight: Weight,135 tokens: impl Iterator<Item = u32> + Clone,136) -> Weight {137 create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(138 tokens,139 <SelfWeightOf<T>>::write_token_properties,140 ))141}140142141fn map_create_data<T: Config>(143fn map_create_data<T: Config>(142 data: up_data_structs::CreateItemData,144 data: up_data_structs::CreateItemData,pallets/refungible/src/erc.rsdiffbeforeafterboth50};50};515152use crate::{52use crate::{53 common::CommonWeights, weights::WeightInfo, AccountBalance, Balance, Config, CreateItemData,53 common::{mint_with_props_weight, CommonWeights},54 weights::WeightInfo,54 Pallet, RefungibleHandle, SelfWeightOf, TokenProperties, TokensMinted, TotalSupply,55 AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,56 TokenProperties, TokensMinted, TotalSupply,661 /// @param tokenUri Token URI that would be stored in the NFT properties663 /// @param tokenUri Token URI that would be stored in the NFT properties662 /// @return uint256 The id of the newly minted token664 /// @return uint256 The id of the newly minted token663 #[solidity(rename_selector = "mintWithTokenURI")]665 #[solidity(rename_selector = "mintWithTokenURI")]664 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]666 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]665 fn mint_with_token_uri(667 fn mint_with_token_uri(666 &mut self,668 &mut self,667 caller: Caller,669 caller: Caller,683 /// @param tokenId ID of the minted RFT685 /// @param tokenId ID of the minted RFT684 /// @param tokenUri Token URI that would be stored in the RFT properties686 /// @param tokenUri Token URI that would be stored in the RFT properties685 #[solidity(hide, rename_selector = "mintWithTokenURI")]687 #[solidity(hide, rename_selector = "mintWithTokenURI")]686 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]688 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]687 fn mint_with_token_uri_check_id(689 fn mint_with_token_uri_check_id(688 &mut self,690 &mut self,689 caller: Caller,691 caller: Caller,1052 }1054 }105310551054 /// @notice Function to mint a token.1056 /// @notice Function to mint a token.1055 /// @param tokenProperties Properties of minted token1057 /// @param tokensData Data of minted token(s)1056 #[weight(if token_properties.len() == 1 {1058 #[weight(if tokens_data.len() == 1 {1059 let token_data = tokens_data.first().unwrap();10601057 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_properties.iter().next().unwrap().owners.len() as u32)1061 mint_with_props_weight::<T>(1062 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_data.owners.len() as u32),1063 [token_data.properties.len() as u32].into_iter(),1064 )1058 } else {1065 } else {1059 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(token_properties.len() as u32)1066 mint_with_props_weight::<T>(1067 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(tokens_data.len() as u32),1060 } + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]1068 tokens_data.iter().map(|d| d.properties.len() as u32),1069 )1070 })]1061 fn mint_bulk_cross(1071 fn mint_bulk_cross(&mut self, caller: Caller, tokens_data: Vec<MintTokenData>) -> Result<bool> {1062 &mut self,1063 caller: Caller,1064 token_properties: Vec<MintTokenData>,1065 ) -> Result<bool> {1066 let caller = T::CrossAccountId::from_eth(caller);1072 let caller = T::CrossAccountId::from_eth(caller);1067 let has_multiple_tokens = token_properties.len() > 1;1073 let has_multiple_tokens = tokens_data.len() > 1;106810741069 let mut create_rft_data = Vec::with_capacity(token_properties.len());1075 let mut create_rft_data = Vec::with_capacity(tokens_data.len());1070 for MintTokenData { owners, properties } in token_properties {1076 for MintTokenData { owners, properties } in tokens_data {1071 let has_multiple_owners = owners.len() > 1;1077 let has_multiple_owners = owners.len() > 1;1072 if has_multiple_tokens & has_multiple_owners {1078 if has_multiple_tokens & has_multiple_owners {1073 return Err(1079 return Err(1108 /// @param to The new owner1114 /// @param to The new owner1109 /// @param tokens array of pairs of token ID and token URI for minted tokens1115 /// @param tokens array of pairs of token ID and token URI for minted tokens1110 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1116 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1111 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]1117 #[weight(1118 mint_with_props_weight::<T>(1119 <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),1120 tokens.iter().map(|_| 1),1121 )1122 )]1112 fn mint_bulk_with_token_uri(1123 fn mint_bulk_with_token_uri(1113 &mut self,1124 &mut self,1162 /// @param to The new owner crossAccountId1173 /// @param to The new owner crossAccountId1163 /// @param properties Properties of minted token1174 /// @param properties Properties of minted token1164 /// @return uint256 The id of the newly minted token1175 /// @return uint256 The id of the newly minted token1165 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]1176 #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]1166 fn mint_cross(1177 fn mint_cross(1167 &mut self,1178 &mut self,1168 caller: Caller,1179 caller: Caller,