difftreelog
Merge pull request #854 from UniqueNetwork/fix/createItemWeight
in: master
15 files changed
Cargo.lockdiffbeforeafterboth578357835784[[package]]5784[[package]]5785name = "pallet-common"5785name = "pallet-common"5786version = "0.1.12"5786version = "0.1.13"5787dependencies = [5787dependencies = [5788 "ethereum 0.14.0",5788 "ethereum 0.14.0",5789 "evm-coder",5789 "evm-coder",634063406341[[package]]6341[[package]]6342name = "pallet-nonfungible"6342name = "pallet-nonfungible"6343version = "0.1.12"6343version = "0.1.13"6344dependencies = [6344dependencies = [6345 "evm-coder",6345 "evm-coder",6346 "frame-benchmarking",6346 "frame-benchmarking",649964996500[[package]]6500[[package]]6501name = "pallet-refungible"6501name = "pallet-refungible"6502version = "0.2.11"6502version = "0.2.12"6503dependencies = [6503dependencies = [6504 "evm-coder",6504 "evm-coder",6505 "frame-benchmarking",6505 "frame-benchmarking",pallets/common/CHANGELOG.mddiffbeforeafterboth445<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->667## [0.1.13] - 2023-01-2089### Changed1011- Behavior of the `CommonWeightInfo::create_item` method.127## [0.1.12] - 2022-11-1613## [0.1.12] - 2022-11-168149### Changed15### Changedpallets/common/Cargo.tomldiffbeforeafterboth2edition = "2021"2edition = "2021"3license = "GPLv3"3license = "GPLv3"4name = "pallet-common"4name = "pallet-common"5version = "0.1.12"5version = "0.1.13"667[dependencies]7[dependencies]8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }pallets/common/src/lib.rsdiffbeforeafterboth53#![cfg_attr(not(feature = "std"), no_std)]53#![cfg_attr(not(feature = "std"), no_std)]54extern crate alloc;54extern crate alloc;555556use core::ops::{Deref, DerefMut};56use core::{57 ops::{Deref, DerefMut},58 slice::from_ref,59};57use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};60use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};58use sp_std::vec::Vec;61use sp_std::vec::Vec;59use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};62use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};1780/// Return weights for various worst-case operations.1783/// Return weights for various worst-case operations.1781pub trait CommonWeightInfo<CrossAccountId> {1784pub trait CommonWeightInfo<CrossAccountId> {1782 /// Weight of item creation.1785 /// Weight of item creation.1783 fn create_item() -> Weight;1786 fn create_item(data: &CreateItemData) -> Weight {1787 Self::create_multiple_items(from_ref(data))1788 }178417891785 /// Weight of items creation.1790 /// Weight of items creation.1786 fn create_multiple_items(amount: &[CreateItemData]) -> Weight;1791 fn create_multiple_items(amount: &[CreateItemData]) -> Weight;pallets/fungible/src/common.rsdiffbeforeafterboth363637pub struct CommonWeights<T: Config>(PhantomData<T>);37pub struct CommonWeights<T: Config>(PhantomData<T>);38impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {38impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {39 fn create_item() -> Weight {40 <SelfWeightOf<T>>::create_item()41 }4243 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {39 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {44 // All items minted for the same user, so it works same as create_item40 // All items minted for the same user, so it works same as create_item45 Self::create_item()41 <SelfWeightOf<T>>::create_item()46 }42 }474348 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {44 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {134 data: up_data_structs::CreateItemData,130 data: up_data_structs::CreateItemData,135 nesting_budget: &dyn Budget,131 nesting_budget: &dyn Budget,136 ) -> DispatchResultWithPostInfo {132 ) -> DispatchResultWithPostInfo {137 match data {133 match &data {138 up_data_structs::CreateItemData::Fungible(data) => with_weight(134 up_data_structs::CreateItemData::Fungible(fungible_data) => with_weight(139 <Pallet<T>>::create_item(self, &sender, (to, data.value), nesting_budget),135 <Pallet<T>>::create_item(self, &sender, (to, fungible_data.value), nesting_budget),140 <CommonWeights<T>>::create_item(),136 <CommonWeights<T>>::create_item(&data),141 ),137 ),142 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),138 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),143 }139 }151 nesting_budget: &dyn Budget,147 nesting_budget: &dyn Budget,152 ) -> DispatchResultWithPostInfo {148 ) -> DispatchResultWithPostInfo {153 let mut sum: u128 = 0;149 let mut sum: u128 = 0;154 for data in data {150 for data in &data {155 match data {151 match &data {156 up_data_structs::CreateItemData::Fungible(data) => {152 up_data_structs::CreateItemData::Fungible(data) => {157 sum = sum153 sum = sum158 .checked_add(data.value)154 .checked_add(data.value)164160165 with_weight(161 with_weight(166 <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),162 <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),167 <CommonWeights<T>>::create_item(),163 <CommonWeights<T>>::create_multiple_items(&data),168 )164 )169 }165 }170166pallets/nonfungible/CHANGELOG.mddiffbeforeafterboth445<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->667## [0.1.13] - 2023-01-2089### Fixed1011- The weight of properties when creating an item.127## [0.1.12] - 2022-12-1613## [0.1.12] - 2022-12-168149### Added15### Addedpallets/nonfungible/Cargo.tomldiffbeforeafterboth2edition = "2021"2edition = "2021"3license = "GPLv3"3license = "GPLv3"4name = "pallet-nonfungible"4name = "pallet-nonfungible"5version = "0.1.12"5version = "0.1.13"667[dependencies]7[dependencies]8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }pallets/nonfungible/src/common.rsdiffbeforeafterboth353536pub struct CommonWeights<T: Config>(PhantomData<T>);36pub struct CommonWeights<T: Config>(PhantomData<T>);37impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {37impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {38 fn create_item() -> Weight {39 <SelfWeightOf<T>>::create_item()40 }4142 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {38 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {43 match data {39 match data {159 data: up_data_structs::CreateItemData,155 data: up_data_structs::CreateItemData,160 nesting_budget: &dyn Budget,156 nesting_budget: &dyn Budget,161 ) -> DispatchResultWithPostInfo {157 ) -> DispatchResultWithPostInfo {158 let weight = <CommonWeights<T>>::create_item(&data);162 with_weight(159 with_weight(163 <Pallet<T>>::create_item(160 <Pallet<T>>::create_item(164 self,161 self,165 &sender,162 &sender,166 map_create_data::<T>(data, &to)?,163 map_create_data::<T>(data, &to)?,167 nesting_budget,164 nesting_budget,168 ),165 ),169 <CommonWeights<T>>::create_item(),166 weight,170 )167 )171 }168 }172169pallets/nonfungible/src/erc.rsdiffbeforeafterboth590 /// @param tokenUri Token URI that would be stored in the NFT properties590 /// @param tokenUri Token URI that would be stored in the NFT properties591 /// @return uint256 The id of the newly minted token591 /// @return uint256 The id of the newly minted token592 #[solidity(rename_selector = "mintWithTokenURI")]592 #[solidity(rename_selector = "mintWithTokenURI")]593 #[weight(<SelfWeightOf<T>>::create_item())]593 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]594 fn mint_with_token_uri(594 fn mint_with_token_uri(595 &mut self,595 &mut self,596 caller: Caller,596 caller: Caller,612 /// @param tokenId ID of the minted NFT612 /// @param tokenId ID of the minted NFT613 /// @param tokenUri Token URI that would be stored in the NFT properties613 /// @param tokenUri Token URI that would be stored in the NFT properties614 #[solidity(hide, rename_selector = "mintWithTokenURI")]614 #[solidity(hide, rename_selector = "mintWithTokenURI")]615 #[weight(<SelfWeightOf<T>>::create_item())]615 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]616 fn mint_with_token_uri_check_id(616 fn mint_with_token_uri_check_id(617 &mut self,617 &mut self,618 caller: Caller,618 caller: Caller,943 /// @param to The new owner943 /// @param to The new owner944 /// @param tokens array of pairs of token ID and token URI for minted tokens944 /// @param tokens array of pairs of token ID and token URI for minted tokens945 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]945 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]946 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]946 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]947 fn mint_bulk_with_token_uri(947 fn mint_bulk_with_token_uri(948 &mut self,948 &mut self,949 caller: Caller,949 caller: Caller,994 /// @param to The new owner crossAccountId994 /// @param to The new owner crossAccountId995 /// @param properties Properties of minted token995 /// @param properties Properties of minted token996 /// @return uint256 The id of the newly minted token996 /// @return uint256 The id of the newly minted token997 #[weight(<SelfWeightOf<T>>::create_item())]997 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]998 fn mint_cross(998 fn mint_cross(999 &mut self,999 &mut self,1000 caller: Caller,1000 caller: Caller,pallets/refungible/CHANGELOG.mddiffbeforeafterboth445<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->667## [0.2.12] - 2023-01-2089### Fixed1011- The weight of properties when creating an item.127## [0.2.11] - 2022-12-1613## [0.2.11] - 2022-12-168149### Added15### Addedpallets/refungible/Cargo.tomldiffbeforeafterboth2edition = "2021"2edition = "2021"3license = "GPLv3"3license = "GPLv3"4name = "pallet-refungible"4name = "pallet-refungible"5version = "0.2.11"5version = "0.2.12"667[dependencies]7[dependencies]8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }8codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.1.2" }pallets/refungible/src/common.rsdiffbeforeafterboth555556pub struct CommonWeights<T: Config>(PhantomData<T>);56pub struct CommonWeights<T: Config>(PhantomData<T>);57impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {57impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {58 fn create_item() -> Weight {59 <SelfWeightOf<T>>::create_item()60 }6162 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {58 fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {63 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(59 <SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(193 data: up_data_structs::CreateItemData,189 data: up_data_structs::CreateItemData,194 nesting_budget: &dyn Budget,190 nesting_budget: &dyn Budget,195 ) -> DispatchResultWithPostInfo {191 ) -> DispatchResultWithPostInfo {192 let weight = <CommonWeights<T>>::create_item(&data);196 with_weight(193 with_weight(197 <Pallet<T>>::create_item(194 <Pallet<T>>::create_item(198 self,195 self,199 &sender,196 &sender,200 map_create_data::<T>(data, &to)?,197 map_create_data::<T>(data, &to)?,201 nesting_budget,198 nesting_budget,202 ),199 ),203 <CommonWeights<T>>::create_item(),200 weight,204 )201 )205 }202 }206203pallets/refungible/src/erc.rsdiffbeforeafterboth629 /// @param tokenUri Token URI that would be stored in the NFT properties629 /// @param tokenUri Token URI that would be stored in the NFT properties630 /// @return uint256 The id of the newly minted token630 /// @return uint256 The id of the newly minted token631 #[solidity(rename_selector = "mintWithTokenURI")]631 #[solidity(rename_selector = "mintWithTokenURI")]632 #[weight(<SelfWeightOf<T>>::create_item())]632 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]633 fn mint_with_token_uri(633 fn mint_with_token_uri(634 &mut self,634 &mut self,635 caller: Caller,635 caller: Caller,651 /// @param tokenId ID of the minted RFT651 /// @param tokenId ID of the minted RFT652 /// @param tokenUri Token URI that would be stored in the RFT properties652 /// @param tokenUri Token URI that would be stored in the RFT properties653 #[solidity(hide, rename_selector = "mintWithTokenURI")]653 #[solidity(hide, rename_selector = "mintWithTokenURI")]654 #[weight(<SelfWeightOf<T>>::create_item())]654 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]655 fn mint_with_token_uri_check_id(655 fn mint_with_token_uri_check_id(656 &mut self,656 &mut self,657 caller: Caller,657 caller: Caller,994 /// @param to The new owner994 /// @param to The new owner995 /// @param tokens array of pairs of token ID and token URI for minted tokens995 /// @param tokens array of pairs of token ID and token URI for minted tokens996 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]996 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]997 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]997 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]998 fn mint_bulk_with_token_uri(998 fn mint_bulk_with_token_uri(999 &mut self,999 &mut self,1000 caller: Caller,1000 caller: Caller,1051 /// @param to The new owner crossAccountId1051 /// @param to The new owner crossAccountId1052 /// @param properties Properties of minted token1052 /// @param properties Properties of minted token1053 /// @return uint256 The id of the newly minted token1053 /// @return uint256 The id of the newly minted token1054 #[weight(<SelfWeightOf<T>>::create_item())]1054 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]1055 fn mint_cross(1055 fn mint_cross(1056 &mut self,1056 &mut self,1057 caller: Caller,1057 caller: Caller,pallets/unique/src/lib.rsdiffbeforeafterboth518 /// * `collection_id`: ID of the collection to which an item would belong.518 /// * `collection_id`: ID of the collection to which an item would belong.519 /// * `owner`: Address of the initial owner of the item.519 /// * `owner`: Address of the initial owner of the item.520 /// * `data`: Token data describing the item to store on chain.520 /// * `data`: Token data describing the item to store on chain.521 #[weight = T::CommonWeightInfo::create_item()]521 #[weight = T::CommonWeightInfo::create_item(&data)]522 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {522 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {523 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);523 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);524 let budget = budget::Value::new(NESTING_BUDGET);524 let budget = budget::Value::new(NESTING_BUDGET);runtime/common/weights.rsdiffbeforeafterboth57where57where58 T: CommonWeightConfigs,58 T: CommonWeightConfigs,59{59{60 fn create_item() -> Weight {60 fn create_item(data: &CreateItemData) -> Weight {61 dispatch_weight::<T>() + max_weight_of!(create_item())61 dispatch_weight::<T>() + max_weight_of!(create_item(data))62 }62 }636364 fn create_multiple_items(data: &[CreateItemData]) -> Weight {64 fn create_multiple_items(data: &[CreateItemData]) -> Weight {