From e1dae1b1f78067f684a3d701d04d66ebd0e25146 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Wed, 20 Jul 2022 12:23:47 +0000 Subject: [PATCH] path: add weights for RFT CommonCollectionOperations --- --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -20,7 +20,7 @@ use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get}; use up_data_structs::{ CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property, - PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData, + PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData, CollectionPropertiesVec, }; use pallet_common::{ CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight, @@ -44,6 +44,14 @@ }; } +fn properties_weight(properties: &CollectionPropertiesVec) -> u64 { + if properties.len() > 0 { + >::set_token_properties(properties.len() as u32) + } else { + 0 + } +} + pub struct CommonWeights(PhantomData); impl CommonWeightInfo for CommonWeights { fn create_item() -> Weight { @@ -52,15 +60,28 @@ fn create_multiple_items(data: &[CreateItemData]) -> Weight { >::create_multiple_items(data.len() as u32) + + data + .iter() + .map(|data| match data { + CreateItemData::ReFungible(rft_data) => { + properties_weight::(&rft_data.properties) + } + _ => 0, + }) + .sum::() } fn create_multiple_items_ex(call: &CreateItemExData) -> Weight { match call { CreateItemExData::RefungibleMultipleOwners(i) => { >::create_multiple_items_ex_multiple_owners(i.users.len() as u32) + + properties_weight::(&i.properties) } CreateItemExData::RefungibleMultipleItems(i) => { >::create_multiple_items_ex_multiple_items(i.len() as u32) + + i.iter() + .map(|d| properties_weight::(&d.properties)) + .sum::() } _ => 0, } -- gitstuff