difftreelog
fix EVM mint with properties, minor improvements
in: master
9 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use core::convert::TryInto;2021use frame_benchmarking::{account, v2::*};22use frame_support::{23 pallet_prelude::ConstU32,24 traits::{fungible::Balanced, tokens::Precision, Get, Imbalance},25 BoundedVec,26};27use pallet_evm::account::CrossAccountId;28use sp_runtime::{traits::Zero, DispatchError};29use sp_std::{vec, vec::Vec};30use up_data_structs::{31 AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,32 NestingPermissions, PropertiesPermissionMap, Property, PropertyKey, PropertyValue,33 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM,34 MAX_TOKEN_PREFIX_LENGTH,35};3637use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};3839const SEED: u32 = 1;4041pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {42 create_var_data::<S>(S)43}44pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {45 (0..S)46 .map(|v| (v & 0xffff) as u16)47 .collect::<Vec<_>>()48 .try_into()49 .unwrap()50}51pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {52 assert!(size <= S, "size ({size}) should be less within bound ({S})",);53 (0..size)54 .map(|v| (v & 0xff) as u8)55 .collect::<Vec<_>>()56 .try_into()57 .unwrap()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}7576pub fn create_collection_raw<T: Config, R>(77 owner: T::CrossAccountId,78 mode: CollectionMode,79 handler: impl FnOnce(80 T::CrossAccountId,81 CreateCollectionData<T::CrossAccountId>,82 ) -> Result<CollectionId, DispatchError>,83 cast: impl FnOnce(CollectionHandle<T>) -> R,84) -> Result<R, DispatchError> {85 let imbalance = <T as Config>::Currency::deposit(86 owner.as_sub(),87 T::CollectionCreationPrice::get(),88 Precision::Exact,89 )?;90 debug_assert!(imbalance.peek().is_zero());91 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();92 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();93 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();94 handler(95 owner,96 CreateCollectionData {97 mode,98 name,99 description,100 token_prefix,101 permissions: Some(CollectionPermissions {102 nesting: Some(NestingPermissions {103 token_owner: false,104 collection_admin: false,105 restricted: None,106 #[cfg(feature = "runtime-benchmarks")]107 permissive: true,108 }),109 mint_mode: Some(true),110 ..Default::default()111 }),112 ..Default::default()113 },114 )115 .and_then(CollectionHandle::try_get)116 .map(cast)117}118fn create_collection<T: Config>(119 owner: T::CrossAccountId,120) -> Result<CollectionHandle<T>, DispatchError> {121 create_collection_raw(122 owner,123 CollectionMode::NFT,124 |owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),125 |h| h,126 )127}128129/// Helper macros, which handles all benchmarking preparation in semi-declarative way130///131/// `name` is a substrate account132/// - name: sub[(id)]133/// `name` is a collection with owner `owner`134/// - name: collection(owner)135/// `name` is a cross account based on substrate136/// - name: cross_sub[(id)]137/// `name` is a cross account, which maps to substrate account `name`138/// - name: cross_from_sub139/// `name` is a cross account, which maps to substrate account `other_name`140/// - name: cross_from_sub(other_name)141#[macro_export]142macro_rules! bench_init {143 ($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {144 let $name: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);145 bench_init!($($rest)*);146 };147 ($name:ident: collection($owner:ident); $($rest:tt)*) => {148 let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;149 bench_init!($($rest)*);150 };151 ($name:ident: cross; $($rest:tt)*) => {152 let $name = T::CrossAccountId::from_sub($name);153 bench_init!($($rest)*);154 };155 ($name:ident: cross_sub $(($id:expr))?; $($rest:tt)*) => {156 let account: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);157 let $name = T::CrossAccountId::from_sub(account);158 bench_init!($($rest)*);159 };160 ($name:ident: cross_from_sub; $($rest:tt)*) => {161 let $name = T::CrossAccountId::from_sub($name);162 bench_init!($($rest)*);163 };164 ($name:ident: cross_from_sub($from:ident); $($rest:tt)*) => {165 let $name = T::CrossAccountId::from_sub($from);166 bench_init!($($rest)*);167 };168 () => {}169}170171#[benchmarks]172mod benchmarks {173 use super::*;174175 #[benchmark]176 fn set_collection_properties(177 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,178 ) -> Result<(), BenchmarkError> {179 bench_init! {180 owner: sub; collection: collection(owner);181 owner: cross_from_sub;182 };183 let props = (0..b)184 .map(|p| Property {185 key: property_key(p as usize),186 value: property_value(),187 })188 .collect::<Vec<_>>();189190 #[block]191 {192 <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;193 }194195 Ok(())196 }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 }222223 #[benchmark]224 fn check_accesslist() -> Result<(), BenchmarkError> {225 bench_init! {226 owner: sub; collection: collection(owner);227 sender: cross_from_sub(owner);228 };229230 let mut collection_handle = <CollectionHandle<T>>::try_get(collection.id)?;231 <Pallet<T>>::update_permissions(232 &sender,233 &mut collection_handle,234 CollectionPermissions {235 access: Some(AccessMode::AllowList),236 ..Default::default()237 },238 )?;239240 <Pallet<T>>::toggle_allowlist(&collection, &sender, &sender, true)?;241242 assert_eq!(243 collection_handle.permissions.access(),244 AccessMode::AllowList245 );246247 #[block]248 {249 collection_handle.check_allowlist(&sender)?;250 }251252 Ok(())253 }254255 #[benchmark]256 fn init_token_properties_common() -> Result<(), BenchmarkError> {257 bench_init! {258 owner: sub; collection: collection(owner);259 sender: sub;260 sender: cross_from_sub(sender);261 };262263 #[block]264 {265 <BenchmarkPropertyWriter<T>>::load_collection_info(&&collection, &sender);266 }267268 Ok(())269 }270}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use core::convert::TryInto;2021use frame_benchmarking::{account, v2::*};22use frame_support::{23 pallet_prelude::ConstU32,24 traits::{fungible::Balanced, tokens::Precision, Get, Imbalance},25 BoundedVec,26};27use pallet_evm::account::CrossAccountId;28use sp_runtime::{traits::Zero, DispatchError};29use sp_std::{vec, vec::Vec};30use up_data_structs::{31 AccessMode, CollectionId, CollectionMode, CollectionPermissions, CreateCollectionData,32 NestingPermissions, Property, PropertyKey, PropertyValue, MAX_COLLECTION_DESCRIPTION_LENGTH,33 MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM, MAX_TOKEN_PREFIX_LENGTH,34};3536use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};3738const SEED: u32 = 1;3940pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {41 create_var_data::<S>(S)42}43pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {44 (0..S)45 .map(|v| (v & 0xffff) as u16)46 .collect::<Vec<_>>()47 .try_into()48 .unwrap()49}50pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {51 assert!(size <= S, "size ({size}) should be less within bound ({S})",);52 (0..size)53 .map(|v| (v & 0xff) as u8)54 .collect::<Vec<_>>()55 .try_into()56 .unwrap()57}58pub fn property_key(id: usize) -> PropertyKey {59 #[cfg(not(feature = "std"))]60 use alloc::string::ToString;61 let mut data = create_data();62 // No DerefMut available for .fill63 for i in 0..data.len() {64 data[i] = b'0';65 }66 let bytes = id.to_string();67 let len = data.len();68 data[len - bytes.len()..].copy_from_slice(bytes.as_bytes());69 data70}71pub fn property_value() -> PropertyValue {72 create_data()73}7475pub fn create_collection_raw<T: Config, R>(76 owner: T::CrossAccountId,77 mode: CollectionMode,78 handler: impl FnOnce(79 T::CrossAccountId,80 CreateCollectionData<T::CrossAccountId>,81 ) -> Result<CollectionId, DispatchError>,82 cast: impl FnOnce(CollectionHandle<T>) -> R,83) -> Result<R, DispatchError> {84 let imbalance = <T as Config>::Currency::deposit(85 owner.as_sub(),86 T::CollectionCreationPrice::get(),87 Precision::Exact,88 )?;89 debug_assert!(imbalance.peek().is_zero());90 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();91 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();92 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();93 handler(94 owner,95 CreateCollectionData {96 mode,97 name,98 description,99 token_prefix,100 permissions: Some(CollectionPermissions {101 nesting: Some(NestingPermissions {102 token_owner: false,103 collection_admin: false,104 restricted: None,105 #[cfg(feature = "runtime-benchmarks")]106 permissive: true,107 }),108 mint_mode: Some(true),109 ..Default::default()110 }),111 ..Default::default()112 },113 )114 .and_then(CollectionHandle::try_get)115 .map(cast)116}117fn create_collection<T: Config>(118 owner: T::CrossAccountId,119) -> Result<CollectionHandle<T>, DispatchError> {120 create_collection_raw(121 owner,122 CollectionMode::NFT,123 |owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),124 |h| h,125 )126}127128/// Helper macros, which handles all benchmarking preparation in semi-declarative way129///130/// `name` is a substrate account131/// - name: sub[(id)]132/// `name` is a collection with owner `owner`133/// - name: collection(owner)134/// `name` is a cross account based on substrate135/// - name: cross_sub[(id)]136/// `name` is a cross account, which maps to substrate account `name`137/// - name: cross_from_sub138/// `name` is a cross account, which maps to substrate account `other_name`139/// - name: cross_from_sub(other_name)140#[macro_export]141macro_rules! bench_init {142 ($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {143 let $name: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);144 bench_init!($($rest)*);145 };146 ($name:ident: collection($owner:ident); $($rest:tt)*) => {147 let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;148 bench_init!($($rest)*);149 };150 ($name:ident: cross; $($rest:tt)*) => {151 let $name = T::CrossAccountId::from_sub($name);152 bench_init!($($rest)*);153 };154 ($name:ident: cross_sub $(($id:expr))?; $($rest:tt)*) => {155 let account: T::AccountId = account(stringify!($name), 0 $(+ $id)?, SEED);156 let $name = T::CrossAccountId::from_sub(account);157 bench_init!($($rest)*);158 };159 ($name:ident: cross_from_sub; $($rest:tt)*) => {160 let $name = T::CrossAccountId::from_sub($name);161 bench_init!($($rest)*);162 };163 ($name:ident: cross_from_sub($from:ident); $($rest:tt)*) => {164 let $name = T::CrossAccountId::from_sub($from);165 bench_init!($($rest)*);166 };167 () => {}168}169170#[benchmarks]171mod benchmarks {172 use super::*;173174 #[benchmark]175 fn set_collection_properties(176 b: Linear<0, MAX_PROPERTIES_PER_ITEM>,177 ) -> Result<(), BenchmarkError> {178 bench_init! {179 owner: sub; collection: collection(owner);180 owner: cross_from_sub;181 };182 let props = (0..b)183 .map(|p| Property {184 key: property_key(p as usize),185 value: property_value(),186 })187 .collect::<Vec<_>>();188189 #[block]190 {191 <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;192 }193194 Ok(())195 }196197 #[benchmark]198 fn check_accesslist() -> Result<(), BenchmarkError> {199 bench_init! {200 owner: sub; collection: collection(owner);201 sender: cross_from_sub(owner);202 };203204 let mut collection_handle = <CollectionHandle<T>>::try_get(collection.id)?;205 <Pallet<T>>::update_permissions(206 &sender,207 &mut collection_handle,208 CollectionPermissions {209 access: Some(AccessMode::AllowList),210 ..Default::default()211 },212 )?;213214 <Pallet<T>>::toggle_allowlist(&collection, &sender, &sender, true)?;215216 assert_eq!(217 collection_handle.permissions.access(),218 AccessMode::AllowList219 );220221 #[block]222 {223 collection_handle.check_allowlist(&sender)?;224 }225226 Ok(())227 }228229 #[benchmark]230 fn property_writer_load_collection_info() -> Result<(), BenchmarkError> {231 bench_init! {232 owner: sub; collection: collection(owner);233 sender: sub;234 sender: cross_from_sub(sender);235 };236237 #[block]238 {239 <BenchmarkPropertyWriter<T>>::load_collection_info(&&collection, &sender);240 }241242 Ok(())243 }244}pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -126,7 +126,7 @@
///
/// @param key Property key.
#[solidity(hide)]
- #[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
+ #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
fn delete_collection_property(&mut self, caller: Caller, key: String) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
@@ -139,7 +139,7 @@
/// Delete collection properties.
///
/// @param keys Properties keys.
- #[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
+ #[weight(<SelfWeightOf<T>>::set_collection_properties(keys.len() as u32))]
fn delete_collection_properties(&mut self, caller: Caller, keys: Vec<String>) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let keys = keys
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2626,8 +2626,8 @@
impl<T: Config> BenchmarkPropertyWriter<T> {
/// Creates a [`PropertyWriter`] for benchmarking tokens properties writing.
pub fn new<'a, Handle>(
- collection: &Handle,
- collection_lazy_info: PropertyWriterLazyCollectionInfo,
+ collection: &'a Handle,
+ collection_lazy_info: PropertyWriterLazyCollectionInfo<'a>,
) -> PropertyWriter<'a, Self, T, Handle>
where
Handle: CommonCollectionOperations<T> + Deref<Target = CollectionHandle<T>>,
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -18,7 +18,6 @@
use pallet_common::{
bench_init,
benchmarking::{create_collection_raw, property_key, property_value},
- CommonCollectionOperations,
};
use sp_std::prelude::*;
use up_data_structs::{
@@ -131,53 +130,12 @@
#[block]
{
<Pallet<T>>::burn(&collection, &burner, item)?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn burn_recursively_self_raw() -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- sender: cross_from_sub(owner); burner: cross_sub;
- };
- let item = create_max_item(&collection, &sender, burner.clone())?;
-
- #[block]
- {
- <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;
}
Ok(())
}
#[benchmark]
- fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(
- b: Linear<0, 200>,
- ) -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- sender: cross_from_sub(owner); burner: cross_sub;
- };
- let item = create_max_item(&collection, &sender, burner.clone())?;
- for _ in 0..b {
- create_max_item(
- &collection,
- &sender,
- T::CrossTokenAddressMapping::token_to_address(collection.id, item),
- )?;
- }
-
- #[block]
- {
- <Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?;
- }
-
- Ok(())
- }
-
- #[benchmark]
fn transfer_raw() -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
@@ -262,116 +220,34 @@
{
<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?;
}
- }
- // set_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
- // let perms = (0..b).map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // }).collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- // let props = (0..b).map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // }).collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, owner.clone())?;
- // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}
-
- // load_token_properties {
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let item = create_max_item(&collection, &owner, owner.clone())?;
- // }: {
- // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(
- // &collection,
- // item,
- // )
- // }
-
- // write_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
+ Ok(())
+ }
- // let perms = (0..b).map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // }).collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- // let props = (0..b).map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // }).collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, owner.clone())?;
-
- // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(
- // &collection,
- // &owner,
- // );
- // }: {
- // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
-
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?
- // }
-
#[benchmark]
- fn set_token_property_permissions(
- b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
- ) -> Result<(), BenchmarkError> {
+ fn load_token_properties() -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
- let perms = (0..b)
- .map(|k| PropertyKeyPermission {
- key: property_key(k as usize),
- permission: PropertyPermission {
- mutable: false,
- collection_admin: false,
- token_owner: false,
- },
- })
- .collect::<Vec<_>>();
+ let item = create_max_item(&collection, &owner, owner.clone())?;
+
#[block]
{
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
+ pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);
}
Ok(())
}
#[benchmark]
- fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
+ fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
+
let perms = (0..b)
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
@@ -391,71 +267,29 @@
.collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
+ let lazy_collection_info =
+ pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);
+
#[block]
{
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
+ let mut property_writer =
+ pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
+
+ property_writer.write_token_properties(
item,
props.into_iter(),
- &Unlimited,
+ crate::erc::ERC721TokenEvent::TokenChanged {
+ token_id: item.into(),
+ }
+ .to_log(T::ContractAddress::get()),
)?;
}
Ok(())
}
- // TODO:
#[benchmark]
- fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
- // bench_init! {
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let perms = (0..b)
- // .map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // })
- // .collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- #[block]
- {}
- // let props = (0..b)
- // .map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // })
- // .collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, owner.clone())?;
-
- // let (is_collection_admin, property_permissions) =
- // load_is_admin_and_property_permissions(&collection, &owner);
- // #[block]
- // {
- // let mut property_writer =
- // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
-
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?;
- // }
-
- Ok(())
- }
-
- #[benchmark]
- fn delete_token_properties(
+ fn set_token_property_permissions(
b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
) -> Result<(), BenchmarkError> {
bench_init! {
@@ -466,54 +300,16 @@
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
permission: PropertyPermission {
- mutable: true,
- collection_admin: true,
- token_owner: true,
+ mutable: false,
+ collection_admin: false,
+ token_owner: false,
},
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b)
- .map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
})
.collect::<Vec<_>>();
- let item = create_max_item(&collection, &owner, owner.clone())?;
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
- item,
- props.into_iter(),
- &Unlimited,
- )?;
- let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
#[block]
{
- <Pallet<T>>::delete_token_properties(
- &collection,
- &owner,
- item,
- to_delete.into_iter(),
- &Unlimited,
- )?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn token_owner() -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- owner: cross_from_sub;
- };
- let item = create_max_item(&collection, &owner, owner.clone())?;
-
- #[block]
- {
- collection.token_owner(item).unwrap();
+ <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
}
Ok(())
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -39,24 +39,21 @@
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
match data {
- CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- t.iter().map(|t| t.properties.len() as u32),
- <SelfWeightOf<T>>::write_token_properties,
- )),
+ CreateItemExData::NFT(t) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),
+ t.iter().map(|t| t.properties.len() as u32),
+ ),
_ => Weight::zero(),
}
}
fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {
- <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(
- write_token_properties_total_weight::<T, _>(
- data.iter().map(|t| match t {
- up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,
- _ => 0,
- }),
- <SelfWeightOf<T>>::write_token_properties,
- ),
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),
+ data.iter().map(|t| match t {
+ up_data_structs::CreateItemData::NFT(n) => n.properties.len() as u32,
+ _ => 0,
+ }),
)
}
@@ -113,6 +110,16 @@
}
}
+pub(crate) fn mint_with_props_weight<T: Config>(
+ create_no_data_weight: Weight,
+ tokens: impl Iterator<Item = u32> + Clone,
+) -> Weight {
+ create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(
+ tokens,
+ <SelfWeightOf<T>>::write_token_properties,
+ ))
+}
+
fn map_create_data<T: Config>(
data: up_data_structs::CreateItemData,
to: &T::CrossAccountId,
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -49,8 +49,10 @@
};
use crate::{
- common::CommonWeights, weights::WeightInfo, AccountBalance, Config, CreateItemData,
- NonfungibleHandle, Pallet, SelfWeightOf, TokenData, TokenProperties, TokensMinted,
+ common::{mint_with_props_weight, CommonWeights},
+ weights::WeightInfo,
+ AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, SelfWeightOf, TokenData,
+ TokenProperties, TokensMinted,
};
/// Nft events.
@@ -620,7 +622,7 @@
/// @param tokenUri Token URI that would be stored in the NFT properties
/// @return uint256 The id of the newly minted token
#[solidity(rename_selector = "mintWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri(
&mut self,
caller: Caller,
@@ -642,7 +644,7 @@
/// @param tokenId ID of the minted NFT
/// @param tokenUri Token URI that would be stored in the NFT properties
#[solidity(hide, rename_selector = "mintWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri_check_id(
&mut self,
caller: Caller,
@@ -974,7 +976,12 @@
/// @notice Function to mint a token.
/// @param data Array of pairs of token owner and token's properties for minted token
- #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex(data.len() as u32),
+ data.iter().map(|d| d.properties.len() as u32),
+ )
+ )]
fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -1008,7 +1015,12 @@
/// @param to The new owner
/// @param tokens array of pairs of token ID and token URI for minted tokens
#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),
+ tokens.iter().map(|_| 1),
+ )
+ )]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
@@ -1056,7 +1068,7 @@
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]
fn mint_cross(
&mut self,
caller: Caller,
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -421,114 +421,30 @@
Ok(())
}
- // set_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
- // let perms = (0..b).map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // }).collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- // let props = (0..b).map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // }).collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- // }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), &Unlimited)?}
-
- // load_token_properties {
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- // }: {
- // pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(
- // &collection,
- // item,
- // )
- // }
-
- // write_token_properties {
- // let b in 0..MAX_PROPERTIES_PER_ITEM;
- // bench_init!{
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let perms = (0..b).map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // }).collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- // let props = (0..b).map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // }).collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
-
- // let lazy_collection_info = pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(
- // &collection,
- // &owner,
- // );
- // }: {
- // let mut property_writer = pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
-
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?
- // }
-
#[benchmark]
- fn set_token_property_permissions(
- b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
- ) -> Result<(), BenchmarkError> {
+ fn load_token_properties() -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
- let perms = (0..b)
- .map(|k| PropertyKeyPermission {
- key: property_key(k as usize),
- permission: PropertyPermission {
- mutable: false,
- collection_admin: false,
- token_owner: false,
- },
- })
- .collect::<Vec<_>>();
+ let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
+
#[block]
{
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
+ pallet_common::BenchmarkPropertyWriter::<T>::load_token_properties(&collection, item);
}
Ok(())
}
#[benchmark]
- fn set_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
+ fn write_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
+
let perms = (0..b)
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
@@ -548,73 +464,29 @@
.collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
+ let lazy_collection_info =
+ pallet_common::BenchmarkPropertyWriter::<T>::load_collection_info(&collection, &owner);
+
#[block]
{
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
+ let mut property_writer =
+ pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
+
+ property_writer.write_token_properties(
item,
props.into_iter(),
- &Unlimited,
+ crate::erc::ERC721TokenEvent::TokenChanged {
+ token_id: item.into(),
+ }
+ .to_log(T::ContractAddress::get()),
)?;
}
Ok(())
}
- // TODO:
#[benchmark]
- fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
- // bench_init! {
- // owner: sub; collection: collection(owner);
- // owner: cross_from_sub;
- // };
-
- // let perms = (0..b)
- // .map(|k| PropertyKeyPermission {
- // key: property_key(k as usize),
- // permission: PropertyPermission {
- // mutable: false,
- // collection_admin: true,
- // token_owner: true,
- // },
- // })
- // .collect::<Vec<_>>();
- // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
-
- #[block]
- {}
- // let props = (0..b).map(|k| Property {
- // key: property_key(k as usize),
- // value: property_value(),
- // }).collect::<Vec<_>>();
- // let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
-
- // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner)
- // let mut property_writer = pallet_common::collection_info_loaded_property_writer(
- // &collection,
- // is_collection_admin,
- // property_permissions,
- // );
-
- // #[block]
- // {
- // property_writer.write_token_properties(
- // true,
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?;
- // }
-
- Ok(())
- }
-
- #[benchmark]
- fn delete_token_properties(
+ fn set_token_property_permissions(
b: Linear<0, MAX_PROPERTIES_PER_ITEM>,
) -> Result<(), BenchmarkError> {
bench_init! {
@@ -625,38 +497,16 @@
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
permission: PropertyPermission {
- mutable: true,
- collection_admin: true,
- token_owner: true,
+ mutable: false,
+ collection_admin: false,
+ token_owner: false,
},
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b)
- .map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
})
.collect::<Vec<_>>();
- let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- <Pallet<T>>::set_token_properties(
- &collection,
- &owner,
- item,
- props.into_iter(),
- &Unlimited,
- )?;
- let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
#[block]
{
- <Pallet<T>>::delete_token_properties(
- &collection,
- &owner,
- item,
- to_delete.into_iter(),
- &Unlimited,
- )?;
+ <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
}
Ok(())
@@ -673,22 +523,6 @@
#[block]
{
<Pallet<T>>::repartition(&collection, &owner, item, 200)?;
- }
-
- Ok(())
- }
-
- #[benchmark]
- fn token_owner() -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- sender: cross_from_sub(owner); owner: cross_sub;
- };
- let item = create_max_item(&collection, &sender, [(owner, 100)])?;
-
- #[block]
- {
- <Pallet<T>>::token_owner(collection.id, item).unwrap();
}
Ok(())
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -47,35 +47,27 @@
pub struct CommonWeights<T: Config>(PhantomData<T>);
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {
- <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(
- write_token_properties_total_weight::<T, _>(
- data.iter().map(|data| match data {
- up_data_structs::CreateItemData::ReFungible(rft_data) => {
- rft_data.properties.len() as u32
- }
- _ => 0,
- }),
- <SelfWeightOf<T>>::write_token_properties,
- ),
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(data.len() as u32),
+ data.iter().map(|data| match data {
+ up_data_structs::CreateItemData::ReFungible(rft_data) => {
+ rft_data.properties.len() as u32
+ }
+ _ => 0,
+ }),
)
}
fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {
match call {
- CreateItemExData::RefungibleMultipleOwners(i) => {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- [i.properties.len() as u32].into_iter(),
- <SelfWeightOf<T>>::write_token_properties,
- ))
- }
- CreateItemExData::RefungibleMultipleItems(i) => {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)
- .saturating_add(write_token_properties_total_weight::<T, _>(
- i.iter().map(|d| d.properties.len() as u32),
- <SelfWeightOf<T>>::write_token_properties,
- ))
- }
+ CreateItemExData::RefungibleMultipleOwners(i) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32),
+ [i.properties.len() as u32].into_iter(),
+ ),
+ CreateItemExData::RefungibleMultipleItems(i) => mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32),
+ i.iter().map(|d| d.properties.len() as u32),
+ ),
_ => Weight::zero(),
}
}
@@ -138,6 +130,16 @@
}
}
+pub(crate) fn mint_with_props_weight<T: Config>(
+ create_no_data_weight: Weight,
+ tokens: impl Iterator<Item = u32> + Clone,
+) -> Weight {
+ create_no_data_weight.saturating_add(write_token_properties_total_weight::<T, _>(
+ tokens,
+ <SelfWeightOf<T>>::write_token_properties,
+ ))
+}
+
fn map_create_data<T: Config>(
data: up_data_structs::CreateItemData,
to: &T::CrossAccountId,
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -50,8 +50,10 @@
};
use crate::{
- common::CommonWeights, weights::WeightInfo, AccountBalance, Balance, Config, CreateItemData,
- Pallet, RefungibleHandle, SelfWeightOf, TokenProperties, TokensMinted, TotalSupply,
+ common::{mint_with_props_weight, CommonWeights},
+ weights::WeightInfo,
+ AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,
+ TokenProperties, TokensMinted, TotalSupply,
};
frontier_contract! {
@@ -661,7 +663,7 @@
/// @param tokenUri Token URI that would be stored in the NFT properties
/// @return uint256 The id of the newly minted token
#[solidity(rename_selector = "mintWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri(
&mut self,
caller: Caller,
@@ -683,7 +685,7 @@
/// @param tokenId ID of the minted RFT
/// @param tokenUri Token URI that would be stored in the RFT properties
#[solidity(hide, rename_selector = "mintWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [1].into_iter()))]
fn mint_with_token_uri_check_id(
&mut self,
caller: Caller,
@@ -1052,22 +1054,26 @@
}
/// @notice Function to mint a token.
- /// @param tokenProperties Properties of minted token
- #[weight(if token_properties.len() == 1 {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_properties.iter().next().unwrap().owners.len() as u32)
+ /// @param tokensData Data of minted token(s)
+ #[weight(if tokens_data.len() == 1 {
+ let token_data = tokens_data.first().unwrap();
+
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_data.owners.len() as u32),
+ [token_data.properties.len() as u32].into_iter(),
+ )
} else {
- <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(token_properties.len() as u32)
- } + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]
- fn mint_bulk_cross(
- &mut self,
- caller: Caller,
- token_properties: Vec<MintTokenData>,
- ) -> Result<bool> {
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(tokens_data.len() as u32),
+ tokens_data.iter().map(|d| d.properties.len() as u32),
+ )
+ })]
+ fn mint_bulk_cross(&mut self, caller: Caller, tokens_data: Vec<MintTokenData>) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
- let has_multiple_tokens = token_properties.len() > 1;
+ let has_multiple_tokens = tokens_data.len() > 1;
- let mut create_rft_data = Vec::with_capacity(token_properties.len());
- for MintTokenData { owners, properties } in token_properties {
+ let mut create_rft_data = Vec::with_capacity(tokens_data.len());
+ for MintTokenData { owners, properties } in tokens_data {
let has_multiple_owners = owners.len() > 1;
if has_multiple_tokens & has_multiple_owners {
return Err(
@@ -1108,7 +1114,12 @@
/// @param to The new owner
/// @param tokens array of pairs of token ID and token URI for minted tokens
#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(
+ mint_with_props_weight::<T>(
+ <SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32),
+ tokens.iter().map(|_| 1),
+ )
+ )]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
@@ -1162,7 +1173,7 @@
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
- #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]
+ #[weight(mint_with_props_weight::<T>(<SelfWeightOf<T>>::create_item(), [properties.len() as u32].into_iter()))]
fn mint_cross(
&mut self,
caller: Caller,