difftreelog
feat createMultipleItemsEx call
in: master
16 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -17,7 +17,7 @@
TokenId, Weight, WithdrawReasons, CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode,
NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,
- CustomDataLimit, CreateCollectionData, SponsorshipState,
+ CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData,
};
pub use pallet::*;
use sp_core::H160;
@@ -624,9 +624,10 @@
}
/// Worst cases
-pub trait CommonWeightInfo {
+pub trait CommonWeightInfo<CrossAccountId> {
fn create_item() -> Weight;
fn create_multiple_items(amount: u32) -> Weight;
+ fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
@@ -648,6 +649,11 @@
to: T::CrossAccountId,
data: Vec<CreateItemData>,
) -> DispatchResultWithPostInfo;
+ fn create_multiple_items_ex(
+ &self,
+ sender: T::CrossAccountId,
+ data: CreateItemExData<T::CrossAccountId>,
+ ) -> DispatchResultWithPostInfo;
fn burn_item(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -4,7 +4,7 @@
use sp_std::prelude::*;
use pallet_common::benchmarking::create_collection_raw;
use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
use pallet_common::bench_init;
const SEED: u32 = 1;
@@ -26,6 +26,18 @@
};
}: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}
+ create_multiple_items_ex {
+ let b in 0..MAX_ITEMS_PER_BATCH;
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ sender: cross_from_sub(owner);
+ };
+ let data = (0..b).map(|i| {
+ bench_init!(to: cross_sub(i););
+ (to, 200)
+ }).collect::<BTreeMap<_, _>>().try_into().unwrap();
+ }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)}
+
burn_item {
bench_init!{
owner: sub; collection: collection(owner);
pallets/fungible/src/common.rsdiffbeforeafterboth1use core::marker::PhantomData;23use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};4use up_data_structs::TokenId;5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};6use sp_runtime::ArithmeticError;7use sp_std::{vec::Vec, vec};8use up_data_structs::CustomDataLimit;910use crate::{11 Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,12};1314pub struct CommonWeights<T: Config>(PhantomData<T>);15impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {16 fn create_item() -> Weight {17 <SelfWeightOf<T>>::create_item()18 }1920 fn create_multiple_items(_amount: u32) -> Weight {21 Self::create_item()22 }2324 fn burn_item() -> Weight {25 <SelfWeightOf<T>>::burn_item()26 }2728 fn transfer() -> Weight {29 <SelfWeightOf<T>>::transfer()30 }3132 fn approve() -> Weight {33 <SelfWeightOf<T>>::approve()34 }3536 fn transfer_from() -> Weight {37 <SelfWeightOf<T>>::transfer_from()38 }3940 fn burn_from() -> Weight {41 <SelfWeightOf<T>>::burn_from()42 }4344 fn set_variable_metadata(_bytes: u32) -> Weight {45 // Error46 047 }48}4950impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {51 fn create_item(52 &self,53 sender: T::CrossAccountId,54 to: T::CrossAccountId,55 data: up_data_structs::CreateItemData,56 ) -> DispatchResultWithPostInfo {57 match data {58 up_data_structs::CreateItemData::Fungible(data) => with_weight(59 <Pallet<T>>::create_item(self, &sender, (to, data.value)),60 <CommonWeights<T>>::create_item(),61 ),62 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),63 }64 }6566 fn create_multiple_items(67 &self,68 sender: T::CrossAccountId,69 to: T::CrossAccountId,70 data: Vec<up_data_structs::CreateItemData>,71 ) -> DispatchResultWithPostInfo {72 let mut sum: u128 = 0;73 for data in data {74 match data {75 up_data_structs::CreateItemData::Fungible(data) => {76 sum = sum77 .checked_add(data.value)78 .ok_or(ArithmeticError::Overflow)?;79 }80 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),81 }82 }8384 with_weight(85 <Pallet<T>>::create_item(self, &sender, (to, sum)),86 <CommonWeights<T>>::create_item(),87 )88 }8990 fn burn_item(91 &self,92 sender: T::CrossAccountId,93 token: TokenId,94 amount: u128,95 ) -> DispatchResultWithPostInfo {96 ensure!(97 token == TokenId::default(),98 <Error<T>>::FungibleItemsHaveNoId99 );100101 with_weight(102 <Pallet<T>>::burn(self, &sender, amount),103 <CommonWeights<T>>::burn_item(),104 )105 }106107 fn transfer(108 &self,109 from: T::CrossAccountId,110 to: T::CrossAccountId,111 token: TokenId,112 amount: u128,113 ) -> DispatchResultWithPostInfo {114 ensure!(115 token == TokenId::default(),116 <Error<T>>::FungibleItemsHaveNoId117 );118119 with_weight(120 <Pallet<T>>::transfer(self, &from, &to, amount),121 <CommonWeights<T>>::transfer(),122 )123 }124125 fn approve(126 &self,127 sender: T::CrossAccountId,128 spender: T::CrossAccountId,129 token: TokenId,130 amount: u128,131 ) -> DispatchResultWithPostInfo {132 ensure!(133 token == TokenId::default(),134 <Error<T>>::FungibleItemsHaveNoId135 );136137 with_weight(138 <Pallet<T>>::set_allowance(self, &sender, &spender, amount),139 <CommonWeights<T>>::approve(),140 )141 }142143 fn transfer_from(144 &self,145 sender: T::CrossAccountId,146 from: T::CrossAccountId,147 to: T::CrossAccountId,148 token: TokenId,149 amount: u128,150 ) -> DispatchResultWithPostInfo {151 ensure!(152 token == TokenId::default(),153 <Error<T>>::FungibleItemsHaveNoId154 );155156 with_weight(157 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount),158 <CommonWeights<T>>::transfer_from(),159 )160 }161162 fn burn_from(163 &self,164 sender: T::CrossAccountId,165 from: T::CrossAccountId,166 token: TokenId,167 amount: u128,168 ) -> DispatchResultWithPostInfo {169 ensure!(170 token == TokenId::default(),171 <Error<T>>::FungibleItemsHaveNoId172 );173174 with_weight(175 <Pallet<T>>::burn_from(self, &sender, &from, amount),176 <CommonWeights<T>>::burn_from(),177 )178 }179180 fn set_variable_metadata(181 &self,182 _sender: T::CrossAccountId,183 _token: TokenId,184 _data: BoundedVec<u8, CustomDataLimit>,185 ) -> DispatchResultWithPostInfo {186 fail!(<Error<T>>::FungibleItemsDontHaveData)187 }188189 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {190 if <Balance<T>>::get((self.id, account)) != 0 {191 vec![TokenId::default()]192 } else {193 vec![]194 }195 }196197 fn token_exists(&self, token: TokenId) -> bool {198 token == TokenId::default()199 }200201 fn last_token_id(&self) -> TokenId {202 TokenId::default()203 }204205 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {206 None207 }208 fn const_metadata(&self, _token: TokenId) -> Vec<u8> {209 Vec::new()210 }211 fn variable_metadata(&self, _token: TokenId) -> Vec<u8> {212 Vec::new()213 }214215 fn collection_tokens(&self) -> u32 {216 1217 }218219 fn account_balance(&self, account: T::CrossAccountId) -> u32 {220 if <Balance<T>>::get((self.id, account)) != 0 {221 1222 } else {223 0224 }225 }226227 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {228 if token != TokenId::default() {229 return 0;230 }231 <Balance<T>>::get((self.id, account))232 }233234 fn allowance(235 &self,236 sender: T::CrossAccountId,237 spender: T::CrossAccountId,238 token: TokenId,239 ) -> u128 {240 if token != TokenId::default() {241 return 0;242 }243 <Allowance<T>>::get((self.id, sender, spender))244 }245}1use core::marker::PhantomData;23use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};4use up_data_structs::{TokenId, CreateItemExData};5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};6use sp_runtime::ArithmeticError;7use sp_std::{vec::Vec, vec};8use up_data_structs::CustomDataLimit;910use crate::{11 Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,12};1314pub struct CommonWeights<T: Config>(PhantomData<T>);15impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {16 fn create_item() -> Weight {17 <SelfWeightOf<T>>::create_item()18 }1920 fn create_multiple_items(_amount: u32) -> Weight {21 Self::create_item()22 }2324 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {25 match data {26 CreateItemExData::Fungible(f) => {27 <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)28 }29 _ => 0,30 }31 }3233 fn burn_item() -> Weight {34 <SelfWeightOf<T>>::burn_item()35 }3637 fn transfer() -> Weight {38 <SelfWeightOf<T>>::transfer()39 }4041 fn approve() -> Weight {42 <SelfWeightOf<T>>::approve()43 }4445 fn transfer_from() -> Weight {46 <SelfWeightOf<T>>::transfer_from()47 }4849 fn burn_from() -> Weight {50 <SelfWeightOf<T>>::burn_from()51 }5253 fn set_variable_metadata(_bytes: u32) -> Weight {54 // Error55 056 }57}5859impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {60 fn create_item(61 &self,62 sender: T::CrossAccountId,63 to: T::CrossAccountId,64 data: up_data_structs::CreateItemData,65 ) -> DispatchResultWithPostInfo {66 match data {67 up_data_structs::CreateItemData::Fungible(data) => with_weight(68 <Pallet<T>>::create_item(self, &sender, (to, data.value)),69 <CommonWeights<T>>::create_item(),70 ),71 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),72 }73 }7475 fn create_multiple_items(76 &self,77 sender: T::CrossAccountId,78 to: T::CrossAccountId,79 data: Vec<up_data_structs::CreateItemData>,80 ) -> DispatchResultWithPostInfo {81 let mut sum: u128 = 0;82 for data in data {83 match data {84 up_data_structs::CreateItemData::Fungible(data) => {85 sum = sum86 .checked_add(data.value)87 .ok_or(ArithmeticError::Overflow)?;88 }89 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),90 }91 }9293 with_weight(94 <Pallet<T>>::create_item(self, &sender, (to, sum)),95 <CommonWeights<T>>::create_item(),96 )97 }9899 fn create_multiple_items_ex(100 &self,101 sender: <T>::CrossAccountId,102 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,103 ) -> DispatchResultWithPostInfo {104 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);105 let data = match data {106 up_data_structs::CreateItemExData::Fungible(f) => f,107 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),108 };109110 with_weight(111 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),112 weight,113 )114 }115116 fn burn_item(117 &self,118 sender: T::CrossAccountId,119 token: TokenId,120 amount: u128,121 ) -> DispatchResultWithPostInfo {122 ensure!(123 token == TokenId::default(),124 <Error<T>>::FungibleItemsHaveNoId125 );126127 with_weight(128 <Pallet<T>>::burn(self, &sender, amount),129 <CommonWeights<T>>::burn_item(),130 )131 }132133 fn transfer(134 &self,135 from: T::CrossAccountId,136 to: T::CrossAccountId,137 token: TokenId,138 amount: u128,139 ) -> DispatchResultWithPostInfo {140 ensure!(141 token == TokenId::default(),142 <Error<T>>::FungibleItemsHaveNoId143 );144145 with_weight(146 <Pallet<T>>::transfer(self, &from, &to, amount),147 <CommonWeights<T>>::transfer(),148 )149 }150151 fn approve(152 &self,153 sender: T::CrossAccountId,154 spender: T::CrossAccountId,155 token: TokenId,156 amount: u128,157 ) -> DispatchResultWithPostInfo {158 ensure!(159 token == TokenId::default(),160 <Error<T>>::FungibleItemsHaveNoId161 );162163 with_weight(164 <Pallet<T>>::set_allowance(self, &sender, &spender, amount),165 <CommonWeights<T>>::approve(),166 )167 }168169 fn transfer_from(170 &self,171 sender: T::CrossAccountId,172 from: T::CrossAccountId,173 to: T::CrossAccountId,174 token: TokenId,175 amount: u128,176 ) -> DispatchResultWithPostInfo {177 ensure!(178 token == TokenId::default(),179 <Error<T>>::FungibleItemsHaveNoId180 );181182 with_weight(183 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount),184 <CommonWeights<T>>::transfer_from(),185 )186 }187188 fn burn_from(189 &self,190 sender: T::CrossAccountId,191 from: T::CrossAccountId,192 token: TokenId,193 amount: u128,194 ) -> DispatchResultWithPostInfo {195 ensure!(196 token == TokenId::default(),197 <Error<T>>::FungibleItemsHaveNoId198 );199200 with_weight(201 <Pallet<T>>::burn_from(self, &sender, &from, amount),202 <CommonWeights<T>>::burn_from(),203 )204 }205206 fn set_variable_metadata(207 &self,208 _sender: T::CrossAccountId,209 _token: TokenId,210 _data: BoundedVec<u8, CustomDataLimit>,211 ) -> DispatchResultWithPostInfo {212 fail!(<Error<T>>::FungibleItemsDontHaveData)213 }214215 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {216 if <Balance<T>>::get((self.id, account)) != 0 {217 vec![TokenId::default()]218 } else {219 vec![]220 }221 }222223 fn token_exists(&self, token: TokenId) -> bool {224 token == TokenId::default()225 }226227 fn last_token_id(&self) -> TokenId {228 TokenId::default()229 }230231 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {232 None233 }234 fn const_metadata(&self, _token: TokenId) -> Vec<u8> {235 Vec::new()236 }237 fn variable_metadata(&self, _token: TokenId) -> Vec<u8> {238 Vec::new()239 }240241 fn collection_tokens(&self) -> u32 {242 1243 }244245 fn account_balance(&self, account: T::CrossAccountId) -> u32 {246 if <Balance<T>>::get((self.id, account)) != 0 {247 1248 } else {249 0250 }251 }252253 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {254 if token != TokenId::default() {255 return 0;256 }257 <Balance<T>>::get((self.id, account))258 }259260 fn allowance(261 &self,262 sender: T::CrossAccountId,263 spender: T::CrossAccountId,264 token: TokenId,265 ) -> u128 {266 if token != TokenId::default() {267 return 0;268 }269 <Allowance<T>>::get((self.id, sender, spender))270 }271}pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -392,6 +392,6 @@
sender: &T::CrossAccountId,
data: CreateItemData<T>,
) -> DispatchResult {
- Self::create_multiple_items(collection, sender, vec![data])
+ Self::create_multiple_items(collection, sender, [(data.0, data.1)].into_iter().collect())
}
}
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -33,6 +33,7 @@
/// Weight functions needed for pallet_fungible.
pub trait WeightInfo {
fn create_item() -> Weight;
+ fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
@@ -51,6 +52,17 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:4 w:4)
+ fn create_multiple_items_ex(b: u32, ) -> Weight {
+ (1_055_000 as Weight)
+ // Standard Error: 22_000
+ .saturating_add((5_273_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(T::DbWeight::get().reads(1 as Weight))
+ .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(T::DbWeight::get().writes(1 as Weight))
+ .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))
+ }
+ // Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_item() -> Weight {
(14_096_000 as Weight)
@@ -97,6 +109,17 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:4 w:4)
+ fn create_multiple_items_ex(b: u32, ) -> Weight {
+ (1_055_000 as Weight)
+ // Standard Error: 22_000
+ .saturating_add((5_273_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(RocksDbWeight::get().reads(1 as Weight))
+ .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(RocksDbWeight::get().writes(1 as Weight))
+ .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))
+ }
+ // Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_item() -> Weight {
(14_096_000 as Weight)
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -56,6 +56,16 @@
let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+ create_multiple_items_ex {
+ let b in 0..MAX_ITEMS_PER_BATCH;
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ sender: cross_from_sub(owner);
+ };
+ let data = (0..b).map(|i| {
+ bench_init!(to: cross_sub(i););
+ create_max_item_data::<T>(to)
+ }).collect();
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
burn_item {
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -1,7 +1,7 @@
use core::marker::PhantomData;
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
-use up_data_structs::{TokenId, CustomDataLimit};
+use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
use sp_std::vec::Vec;
@@ -17,6 +17,13 @@
<SelfWeightOf<T>>::create_item()
}
+ 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),
+ _ => 0,
+ }
+ }
+
fn create_multiple_items(amount: u32) -> Weight {
<SelfWeightOf<T>>::create_multiple_items(amount)
}
@@ -91,6 +98,23 @@
)
}
+ fn create_multiple_items_ex(
+ &self,
+ sender: <T>::CrossAccountId,
+ data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
+ let data = match data {
+ up_data_structs::CreateItemExData::NFT(nft) => nft,
+ _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),
+ };
+
+ with_weight(
+ <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
+ weight,
+ )
+ }
+
fn burn_item(
&self,
sender: T::CrossAccountId,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -2,7 +2,9 @@
use erc::ERC721Events;
use frame_support::{BoundedVec, ensure};
-use up_data_structs::{AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData};
+use up_data_structs::{
+ AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
+};
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,
};
@@ -22,11 +24,7 @@
pub mod erc;
pub mod weights;
-pub struct CreateItemData<T: Config> {
- pub const_data: BoundedVec<u8, CustomDataLimit>,
- pub variable_data: BoundedVec<u8, CustomDataLimit>,
- pub owner: T::CrossAccountId,
-}
+pub type CreateItemData<T> = CreateNftExData<<T as pallet_common::Config>::CrossAccountId>;
pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -34,6 +34,7 @@
pub trait WeightInfo {
fn create_item() -> Weight;
fn create_multiple_items(b: u32, ) -> Weight;
+ fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
@@ -66,6 +67,19 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
}
+ // Storage: Nonfungible TokensMinted (r:1 w:1)
+ // Storage: Nonfungible AccountBalance (r:4 w:4)
+ // Storage: Nonfungible TokenData (r:0 w:4)
+ // Storage: Nonfungible Owned (r:0 w:4)
+ fn create_multiple_items_ex(b: u32, ) -> Weight {
+ (2_090_000 as Weight)
+ // Standard Error: 10_000
+ .saturating_add((9_230_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(T::DbWeight::get().reads(1 as Weight))
+ .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(T::DbWeight::get().writes(1 as Weight))
+ .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible TokensBurnt (r:1 w:1)
// Storage: Nonfungible Allowance (r:1 w:0)
@@ -140,6 +154,19 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
}
+ // Storage: Nonfungible TokensMinted (r:1 w:1)
+ // Storage: Nonfungible AccountBalance (r:4 w:4)
+ // Storage: Nonfungible TokenData (r:0 w:4)
+ // Storage: Nonfungible Owned (r:0 w:4)
+ fn create_multiple_items_ex(b: u32, ) -> Weight {
+ (2_090_000 as Weight)
+ // Standard Error: 10_000
+ .saturating_add((9_230_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(RocksDbWeight::get().reads(1 as Weight))
+ .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(RocksDbWeight::get().writes(1 as Weight))
+ .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible TokensBurnt (r:1 w:1)
// Storage: Nonfungible Allowance (r:1 w:0)
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -31,7 +31,8 @@
sender: &T::CrossAccountId,
users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
) -> Result<TokenId, DispatchError> {
- <Pallet<T>>::create_item(&collection, sender, create_max_item_data(users))?;
+ let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);
+ <Pallet<T>>::create_item(&collection, sender, data)?;
Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
}
@@ -60,6 +61,30 @@
let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+ create_multiple_items_ex_multiple_items {
+ let b in 0..MAX_ITEMS_PER_BATCH;
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ sender: cross_from_sub(owner);
+ };
+ let data = (0..b).map(|t| {
+ bench_init!(to: cross_sub(t););
+ create_max_item_data([(to, 200)])
+ }).collect();
+ }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+
+ create_multiple_items_ex_multiple_owners {
+ let b in 0..MAX_ITEMS_PER_BATCH;
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ sender: cross_from_sub(owner);
+ };
+ let data = vec![create_max_item_data((0..b).map(|u| {
+ bench_init!(to: cross_sub(u););
+ (to, 200)
+ }))].try_into().unwrap();
+ }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+
// Other user left, token data is kept
burn_item_partial {
bench_init!{
@@ -170,6 +195,6 @@
sender: cross_from_sub(owner);
};
let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;
- let data = create_data(b as usize);
+ let data = create_var_data(b).try_into().unwrap();
}: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}
}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -2,10 +2,10 @@
use sp_std::collections::btree_map::BTreeMap;
use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
-use up_data_structs::{TokenId, CustomDataLimit};
+use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
-use sp_std::vec::Vec;
+use sp_std::{vec::Vec, vec};
use crate::{
AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
@@ -31,6 +31,18 @@
<SelfWeightOf<T>>::create_multiple_items(amount)
}
+ 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)
+ }
+ CreateItemExData::RefungibleMultipleItems(i) => {
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)
+ }
+ _ => 0,
+ }
+ }
+
fn burn_item() -> Weight {
max_weight_of!(burn_item_partial(), burn_item_fully())
}
@@ -69,15 +81,15 @@
fn map_create_data<T: Config>(
data: up_data_structs::CreateItemData,
to: &T::CrossAccountId,
-) -> Result<CreateItemData<T>, DispatchError> {
+) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {
match data {
- up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateItemData {
+ up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {
const_data: data.const_data,
variable_data: data.variable_data,
users: {
let mut out = BTreeMap::new();
out.insert(to.clone(), data.pieces);
- out
+ out.try_into().expect("limit > 0")
},
}),
_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),
@@ -92,7 +104,7 @@
data: up_data_structs::CreateItemData,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),
+ <Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
<CommonWeights<T>>::create_item(),
)
}
@@ -115,6 +127,28 @@
)
}
+ fn create_multiple_items_ex(
+ &self,
+ sender: <T>::CrossAccountId,
+ data: CreateItemExData<T::CrossAccountId>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
+ let data = match data {
+ CreateItemExData::RefungibleMultipleOwners(r) => vec![r],
+ CreateItemExData::RefungibleMultipleItems(r)
+ if r.iter().all(|i| i.users.len() == 1) =>
+ {
+ r.into_inner()
+ }
+ _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),
+ };
+
+ with_weight(
+ <Pallet<T>>::create_multiple_items(self, &sender, data),
+ weight,
+ )
+ }
+
fn burn_item(
&self,
sender: T::CrossAccountId,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -2,7 +2,8 @@
use frame_support::{ensure, BoundedVec};
use up_data_structs::{
- AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId, CreateCollectionData,
+ AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
+ CreateCollectionData, CreateRefungibleExData,
};
use pallet_common::{
Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
@@ -19,11 +20,6 @@
pub mod common;
pub mod erc;
pub mod weights;
-pub struct CreateItemData<T: Config> {
- pub const_data: BoundedVec<u8, CustomDataLimit>,
- pub variable_data: BoundedVec<u8, CustomDataLimit>,
- pub users: BTreeMap<T::CrossAccountId, u128>,
-}
pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]
@@ -361,7 +357,7 @@
pub fn create_multiple_items(
collection: &RefungibleHandle<T>,
sender: &T::CrossAccountId,
- data: Vec<CreateItemData<T>>,
+ data: Vec<CreateRefungibleExData<T::CrossAccountId>>,
) -> DispatchResult {
if !collection.is_owner_or_admin(sender) {
ensure!(
@@ -606,7 +602,7 @@
pub fn create_item(
collection: &RefungibleHandle<T>,
sender: &T::CrossAccountId,
- data: CreateItemData<T>,
+ data: CreateRefungibleExData<T::CrossAccountId>,
) -> DispatchResult {
Self::create_multiple_items(collection, sender, vec![data])
}
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -34,6 +34,8 @@
pub trait WeightInfo {
fn create_item() -> Weight;
fn create_multiple_items(b: u32, ) -> Weight;
+ fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight;
+ fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
fn burn_item_partial() -> Weight;
fn burn_item_fully() -> Weight;
fn transfer_normal() -> Weight;
@@ -77,6 +79,36 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
}
+ // Storage: Refungible TokensMinted (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:4 w:4)
+ // Storage: Refungible Balance (r:0 w:4)
+ // Storage: Refungible TotalSupply (r:0 w:4)
+ // Storage: Refungible TokenData (r:0 w:4)
+ // Storage: Refungible Owned (r:0 w:4)
+ fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {
+ (11_953_000 as Weight)
+ // Standard Error: 27_000
+ .saturating_add((10_775_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(T::DbWeight::get().reads(1 as Weight))
+ .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(T::DbWeight::get().writes(1 as Weight))
+ .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(b as Weight)))
+ }
+ // Storage: Refungible TokensMinted (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:0 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible AccountBalance (r:4 w:4)
+ // Storage: Refungible Balance (r:0 w:4)
+ // Storage: Refungible Owned (r:0 w:4)
+ fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {
+ (0 as Weight)
+ // Standard Error: 13_000
+ .saturating_add((8_528_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(T::DbWeight::get().reads(1 as Weight))
+ .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(T::DbWeight::get().writes(3 as Weight))
+ .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+ }
// Storage: Refungible TotalSupply (r:1 w:1)
// Storage: Refungible Balance (r:1 w:1)
// Storage: Refungible AccountBalance (r:1 w:1)
@@ -215,6 +247,36 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
.saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
}
+ // Storage: Refungible TokensMinted (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:4 w:4)
+ // Storage: Refungible Balance (r:0 w:4)
+ // Storage: Refungible TotalSupply (r:0 w:4)
+ // Storage: Refungible TokenData (r:0 w:4)
+ // Storage: Refungible Owned (r:0 w:4)
+ fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {
+ (11_953_000 as Weight)
+ // Standard Error: 27_000
+ .saturating_add((10_775_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(RocksDbWeight::get().reads(1 as Weight))
+ .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(RocksDbWeight::get().writes(1 as Weight))
+ .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(b as Weight)))
+ }
+ // Storage: Refungible TokensMinted (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:0 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible AccountBalance (r:4 w:4)
+ // Storage: Refungible Balance (r:0 w:4)
+ // Storage: Refungible Owned (r:0 w:4)
+ fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {
+ (0 as Weight)
+ // Standard Error: 13_000
+ .saturating_add((8_528_000 as Weight).saturating_mul(b as Weight))
+ .saturating_add(RocksDbWeight::get().reads(1 as Weight))
+ .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(RocksDbWeight::get().writes(3 as Weight))
+ .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+ }
// Storage: Refungible TotalSupply (r:1 w:1)
// Storage: Refungible Balance (r:1 w:1)
// Storage: Refungible AccountBalance (r:1 w:1)
pallets/unique/src/common.rsdiffbeforeafterboth--- a/pallets/unique/src/common.rs
+++ b/pallets/unique/src/common.rs
@@ -5,6 +5,7 @@
use pallet_fungible::{common::CommonWeights as FungibleWeights};
use pallet_nonfungible::{common::CommonWeights as NonfungibleWeights};
use pallet_refungible::{common::CommonWeights as RefungibleWeights};
+use up_data_structs::CreateItemExData;
use crate::{Config, dispatch::dispatch_weight};
@@ -17,7 +18,7 @@
}
pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
fn create_item() -> up_data_structs::Weight {
dispatch_weight::<T>() + max_weight_of!(create_item())
}
@@ -26,6 +27,10 @@
dispatch_weight::<T>() + max_weight_of!(create_multiple_items(amount))
}
+ fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))
+ }
+
fn burn_item() -> Weight {
dispatch_weight::<T>() + max_weight_of!(burn_item())
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -40,7 +40,7 @@
OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,
MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,
CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
- CreateCollectionData, CustomDataLimit,
+ CreateCollectionData, CustomDataLimit, CreateItemExData,
};
use pallet_common::{
account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,
@@ -735,6 +735,14 @@
dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))
}
+ #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]
+ #[transactional]
+ pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))
+ }
+
// TODO! transaction weight
/// Set transfers_enabled value for particular collection
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -1,6 +1,11 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use core::convert::{TryFrom, TryInto};
+use core::{
+ convert::{TryFrom, TryInto},
+ fmt,
+};
+use frame_support::storage::bounded_btree_map::BoundedBTreeMap;
+use sp_std::collections::btree_map::BTreeMap;
#[cfg(feature = "serde")]
pub use serde::{Serialize, Deserialize};
@@ -525,6 +530,47 @@
ReFungible(CreateReFungibleData),
}
+#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
+#[derivative(Debug)]
+pub struct CreateNftExData<CrossAccountId> {
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ pub const_data: BoundedVec<u8, CustomDataLimit>,
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ pub variable_data: BoundedVec<u8, CustomDataLimit>,
+ pub owner: CrossAccountId,
+}
+
+#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
+#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
+pub struct CreateRefungibleExData<CrossAccountId> {
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ pub const_data: BoundedVec<u8, CustomDataLimit>,
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ pub variable_data: BoundedVec<u8, CustomDataLimit>,
+ #[derivative(Debug(format_with = "bounded_map_debug"))]
+ pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
+}
+
+#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
+#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
+pub enum CreateItemExData<CrossAccountId> {
+ NFT(
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,
+ ),
+ Fungible(
+ #[derivative(Debug(format_with = "bounded_map_debug"))]
+ BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
+ ),
+ /// Many tokens, each may have only one owner
+ RefungibleMultipleItems(
+ #[derivative(Debug(format_with = "bounded_debug"))]
+ BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,
+ ),
+ /// Single token, which may have many owners
+ RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),
+}
+
impl CreateItemData {
pub fn data_size(&self) -> usize {
match self {