From 9ed680cd71d47dfef4350a58983c48d9a46a72e9 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 26 Feb 2022 17:19:40 +0000 Subject: [PATCH] feat: createMultipleItemsEx call --- --- 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 { fn create_item() -> Weight; fn create_multiple_items(amount: u32) -> Weight; + fn create_multiple_items_ex(cost: &CreateItemExData) -> Weight; fn burn_item() -> Weight; fn transfer() -> Weight; fn approve() -> Weight; @@ -648,6 +649,11 @@ to: T::CrossAccountId, data: Vec, ) -> DispatchResultWithPostInfo; + fn create_multiple_items_ex( + &self, + sender: T::CrossAccountId, + data: CreateItemExData, + ) -> DispatchResultWithPostInfo; fn burn_item( &self, sender: T::CrossAccountId, --- 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 @@ }; }: {>::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::>().try_into().unwrap(); + }: {>::create_multiple_items(&collection, &sender, data)} + burn_item { bench_init!{ owner: sub; collection: collection(owner); --- a/pallets/fungible/src/common.rs +++ b/pallets/fungible/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; +use up_data_structs::{TokenId, CreateItemExData}; use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight}; use sp_runtime::ArithmeticError; use sp_std::{vec::Vec, vec}; @@ -21,6 +21,15 @@ Self::create_item() } + fn create_multiple_items_ex(data: &CreateItemExData) -> Weight { + match data { + CreateItemExData::Fungible(f) => { + >::create_multiple_items_ex(f.len() as u32) + } + _ => 0, + } + } + fn burn_item() -> Weight { >::burn_item() } @@ -87,6 +96,23 @@ ) } + fn create_multiple_items_ex( + &self, + sender: ::CrossAccountId, + data: up_data_structs::CreateItemExData<::CrossAccountId>, + ) -> DispatchResultWithPostInfo { + let weight = >::create_multiple_items_ex(&data); + let data = match data { + up_data_structs::CreateItemExData::Fungible(f) => f, + _ => fail!(>::NotFungibleDataUsedToMintFungibleCollectionToken), + }; + + with_weight( + >::create_multiple_items(self, &sender, data.into_inner()), + weight, + ) + } + fn burn_item( &self, sender: T::CrossAccountId, --- a/pallets/fungible/src/lib.rs +++ b/pallets/fungible/src/lib.rs @@ -392,6 +392,6 @@ sender: &T::CrossAccountId, data: CreateItemData, ) -> DispatchResult { - Self::create_multiple_items(collection, sender, vec![data]) + Self::create_multiple_items(collection, sender, [(data.0, data.1)].into_iter().collect()) } } --- 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) --- 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::(to.clone())).collect(); }: {>::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::(to) + }).collect(); }: {>::create_multiple_items(&collection, &sender, data)?} burn_item { --- 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 @@ >::create_item() } + fn create_multiple_items_ex(data: &CreateItemExData) -> Weight { + match data { + CreateItemExData::NFT(t) => >::create_multiple_items_ex(t.len() as u32), + _ => 0, + } + } + fn create_multiple_items(amount: u32) -> Weight { >::create_multiple_items(amount) } @@ -91,6 +98,23 @@ ) } + fn create_multiple_items_ex( + &self, + sender: ::CrossAccountId, + data: up_data_structs::CreateItemExData<::CrossAccountId>, + ) -> DispatchResultWithPostInfo { + let weight = >::create_multiple_items_ex(&data); + let data = match data { + up_data_structs::CreateItemExData::NFT(nft) => nft, + _ => fail!(Error::::NotNonfungibleDataUsedToMintFungibleCollectionToken), + }; + + with_weight( + >::create_multiple_items(self, &sender, data.into_inner()), + weight, + ) + } + fn burn_item( &self, sender: T::CrossAccountId, --- 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 { - pub const_data: BoundedVec, - pub variable_data: BoundedVec, - pub owner: T::CrossAccountId, -} +pub type CreateItemData = CreateNftExData<::CrossAccountId>; pub(crate) type SelfWeightOf = ::WeightInfo; #[derive(Encode, Decode, TypeInfo, MaxEncodedLen)] --- 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) --- a/pallets/refungible/src/benchmarking.rs +++ b/pallets/refungible/src/benchmarking.rs @@ -31,7 +31,8 @@ sender: &T::CrossAccountId, users: impl IntoIterator, ) -> Result { - >::create_item(&collection, sender, create_max_item_data(users))?; + let data: CreateRefungibleExData = create_max_item_data(users); + >::create_item(&collection, sender, data)?; Ok(TokenId(>::get(&collection.id))) } @@ -60,6 +61,30 @@ let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect(); }: {>::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(); + }: {>::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(); + }: {>::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(); }: {>::set_variable_metadata(&collection, &sender, item, data)?} } --- 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 @@ >::create_multiple_items(amount) } + fn create_multiple_items_ex(call: &CreateItemExData) -> Weight { + match call { + CreateItemExData::RefungibleMultipleOwners(i) => { + >::create_multiple_items_ex_multiple_owners(i.users.len() as u32) + } + CreateItemExData::RefungibleMultipleItems(i) => { + >::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( data: up_data_structs::CreateItemData, to: &T::CrossAccountId, -) -> Result, DispatchError> { +) -> Result, 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!(>::NotRefungibleDataUsedToMintFungibleCollectionToken), @@ -92,7 +104,7 @@ data: up_data_structs::CreateItemData, ) -> DispatchResultWithPostInfo { with_weight( - >::create_item(self, &sender, map_create_data(data, &to)?), + >::create_item(self, &sender, map_create_data::(data, &to)?), >::create_item(), ) } @@ -115,6 +127,28 @@ ) } + fn create_multiple_items_ex( + &self, + sender: ::CrossAccountId, + data: CreateItemExData, + ) -> DispatchResultWithPostInfo { + let weight = >::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!(>::NotRefungibleDataUsedToMintFungibleCollectionToken), + }; + + with_weight( + >::create_multiple_items(self, &sender, data), + weight, + ) + } + fn burn_item( &self, sender: T::CrossAccountId, --- 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 { - pub const_data: BoundedVec, - pub variable_data: BoundedVec, - pub users: BTreeMap, -} pub(crate) type SelfWeightOf = ::WeightInfo; #[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)] @@ -361,7 +357,7 @@ pub fn create_multiple_items( collection: &RefungibleHandle, sender: &T::CrossAccountId, - data: Vec>, + data: Vec>, ) -> DispatchResult { if !collection.is_owner_or_admin(sender) { ensure!( @@ -606,7 +602,7 @@ pub fn create_item( collection: &RefungibleHandle, sender: &T::CrossAccountId, - data: CreateItemData, + data: CreateRefungibleExData, ) -> DispatchResult { Self::create_multiple_items(collection, sender, vec![data]) } --- 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) --- 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(PhantomData); -impl CommonWeightInfo for CommonWeights { +impl CommonWeightInfo for CommonWeights { fn create_item() -> up_data_structs::Weight { dispatch_weight::() + max_weight_of!(create_item()) } @@ -26,6 +27,10 @@ dispatch_weight::() + max_weight_of!(create_multiple_items(amount)) } + fn create_multiple_items_ex(data: &CreateItemExData) -> Weight { + dispatch_weight::() + max_weight_of!(create_multiple_items_ex(data)) + } + fn burn_item() -> Weight { dispatch_weight::() + max_weight_of!(burn_item()) } --- 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::(collection_id, |d| d.create_multiple_items(sender, owner, items_data)) } + #[weight = >::create_multiple_items_ex(&data)] + #[transactional] + pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData) -> DispatchResultWithPostInfo { + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + + dispatch_call::(collection_id, |d| d.create_multiple_items_ex(sender, data)) + } + // TODO! transaction weight /// Set transfers_enabled value for particular collection --- 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 { + #[derivative(Debug(format_with = "bounded_debug"))] + pub const_data: BoundedVec, + #[derivative(Debug(format_with = "bounded_debug"))] + pub variable_data: BoundedVec, + pub owner: CrossAccountId, +} + +#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)] +#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))] +pub struct CreateRefungibleExData { + #[derivative(Debug(format_with = "bounded_debug"))] + pub const_data: BoundedVec, + #[derivative(Debug(format_with = "bounded_debug"))] + pub variable_data: BoundedVec, + #[derivative(Debug(format_with = "bounded_map_debug"))] + pub users: BoundedBTreeMap>, +} + +#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)] +#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))] +pub enum CreateItemExData { + NFT( + #[derivative(Debug(format_with = "bounded_debug"))] + BoundedVec, ConstU32>, + ), + Fungible( + #[derivative(Debug(format_with = "bounded_map_debug"))] + BoundedBTreeMap>, + ), + /// Many tokens, each may have only one owner + RefungibleMultipleItems( + #[derivative(Debug(format_with = "bounded_debug"))] + BoundedVec, ConstU32>, + ), + /// Single token, which may have many owners + RefungibleMultipleOwners(CreateRefungibleExData), +} + impl CreateItemData { pub fn data_size(&self) -> usize { match self { -- gitstuff