git.delta.rocks / unique-network / refs/commits / e1dae1b1f780

difftreelog

path: add weights for RFT CommonCollectionOperations

Trubnikov Sergey2022-07-20parent: #45f4f7d.patch.diff
in: master

1 file changed

modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
20use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};20use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
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, CreateItemData,23 PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData, CollectionPropertiesVec,
24};24};
25use pallet_common::{25use pallet_common::{
26 CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,26 CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
44 };44 };
45}45}
46
47fn properties_weight<T: Config>(properties: &CollectionPropertiesVec) -> u64 {
48 if properties.len() > 0 {
49 <CommonWeights<T>>::set_token_properties(properties.len() as u32)
50 } else {
51 0
52 }
53}
4654
47pub struct CommonWeights<T: Config>(PhantomData<T>);55pub struct CommonWeights<T: Config>(PhantomData<T>);
48impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {56impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
5260
53 fn create_multiple_items(data: &[CreateItemData]) -> Weight {61 fn create_multiple_items(data: &[CreateItemData]) -> Weight {
54 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32)62 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32)
63 + data
64 .iter()
65 .map(|data| match data {
66 CreateItemData::ReFungible(rft_data) => {
67 properties_weight::<T>(&rft_data.properties)
68 }
69 _ => 0,
70 })
71 .sum::<u64>()
55 }72 }
5673
57 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {74 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {
58 match call {75 match call {
59 CreateItemExData::RefungibleMultipleOwners(i) => {76 CreateItemExData::RefungibleMultipleOwners(i) => {
60 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)77 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)
78 + properties_weight::<T>(&i.properties)
61 }79 }
62 CreateItemExData::RefungibleMultipleItems(i) => {80 CreateItemExData::RefungibleMultipleItems(i) => {
63 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)81 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)
82 + i.iter()
83 .map(|d| properties_weight::<T>(&d.properties))
84 .sum::<u64>()
64 }85 }
65 _ => 0,86 _ => 0,
66 }87 }