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.rsdiffbeforeafterboth--- 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<T::CrossAccountId>) -> Weight {
+ match data {
+ CreateItemExData::Fungible(f) => {
+ <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)
+ }
+ _ => 0,
+ }
+ }
+
fn burn_item() -> Weight {
<SelfWeightOf<T>>::burn_item()
}
@@ -87,6 +96,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::Fungible(f) => f,
+ _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
+ };
+
+ with_weight(
+ <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
+ weight,
+ )
+ }
+
fn burn_item(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};6use pallet_common::{7 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::collections::btree_map::BTreeMap;1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28 use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29 use up_data_structs::CollectionId;30 use super::weights::WeightInfo;3132 #[pallet::error]33 pub enum Error<T> {34 /// Not Fungible item data used to mint in Fungible collection.35 NotFungibleDataUsedToMintFungibleCollectionToken,36 /// Not default id passed as TokenId argument37 FungibleItemsHaveNoId,38 /// Tried to set data for fungible item39 FungibleItemsDontHaveData,40 }4142 #[pallet::config]43 pub trait Config: frame_system::Config + pallet_common::Config {44 type WeightInfo: WeightInfo;45 }4647 #[pallet::pallet]48 #[pallet::generate_store(pub(super) trait Store)]49 pub struct Pallet<T>(_);5051 #[pallet::storage]52 pub type TotalSupply<T: Config> =53 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455 #[pallet::storage]56 pub type Balance<T: Config> = StorageNMap<57 Key = (58 Key<Twox64Concat, CollectionId>,59 Key<Blake2_128Concat, T::CrossAccountId>,60 ),61 Value = u128,62 QueryKind = ValueQuery,63 >;6465 #[pallet::storage]66 pub type Allowance<T: Config> = StorageNMap<67 Key = (68 Key<Twox64Concat, CollectionId>,69 Key<Blake2_128, T::CrossAccountId>,70 Key<Blake2_128Concat, T::CrossAccountId>,71 ),72 Value = u128,73 QueryKind = ValueQuery,74 >;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80 Self(inner)81 }82 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83 self.084 }85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88 self.0.recorder()89 }90 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91 self.0.into_recorder()92 }93}94impl<T: Config> Deref for FungibleHandle<T> {95 type Target = pallet_common::CollectionHandle<T>;9697 fn deref(&self) -> &Self::Target {98 &self.099 }100}101102impl<T: Config> Pallet<T> {103 pub fn init_collection(104 owner: T::AccountId,105 data: CreateCollectionData<T::AccountId>,106 ) -> Result<CollectionId, DispatchError> {107 <PalletCommon<T>>::init_collection(owner, data)108 }109 pub fn destroy_collection(110 collection: FungibleHandle<T>,111 sender: &T::CrossAccountId,112 ) -> DispatchResult {113 let id = collection.id;114115 // =========116117 PalletCommon::destroy_collection(collection.0, sender)?;118119 <TotalSupply<T>>::remove(id);120 <Balance<T>>::remove_prefix((id,), None);121 <Allowance<T>>::remove_prefix((id,), None);122 Ok(())123 }124125 pub fn burn(126 collection: &FungibleHandle<T>,127 owner: &T::CrossAccountId,128 amount: u128,129 ) -> DispatchResult {130 let total_supply = <TotalSupply<T>>::get(collection.id)131 .checked_sub(amount)132 .ok_or(<CommonError<T>>::TokenValueTooLow)?;133134 let balance = <Balance<T>>::get((collection.id, owner))135 .checked_sub(amount)136 .ok_or(<CommonError<T>>::TokenValueTooLow)?;137138 if collection.access == AccessMode::AllowList {139 collection.check_allowlist(owner)?;140 }141142 // =========143144 if balance == 0 {145 <Balance<T>>::remove((collection.id, owner));146 } else {147 <Balance<T>>::insert((collection.id, owner), balance);148 }149 <TotalSupply<T>>::insert(collection.id, total_supply);150151 collection.log_mirrored(ERC20Events::Transfer {152 from: *owner.as_eth(),153 to: H160::default(),154 value: amount.into(),155 });156 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(157 collection.id,158 TokenId::default(),159 owner.clone(),160 amount,161 ));162 Ok(())163 }164165 pub fn transfer(166 collection: &FungibleHandle<T>,167 from: &T::CrossAccountId,168 to: &T::CrossAccountId,169 amount: u128,170 ) -> DispatchResult {171 ensure!(172 collection.limits.transfers_enabled(),173 <CommonError<T>>::TransferNotAllowed,174 );175176 if collection.access == AccessMode::AllowList {177 collection.check_allowlist(from)?;178 collection.check_allowlist(to)?;179 }180 <PalletCommon<T>>::ensure_correct_receiver(to)?;181182 let balance_from = <Balance<T>>::get((collection.id, from))183 .checked_sub(amount)184 .ok_or(<CommonError<T>>::TokenValueTooLow)?;185 let balance_to = if from != to {186 Some(187 <Balance<T>>::get((collection.id, to))188 .checked_add(amount)189 .ok_or(ArithmeticError::Overflow)?,190 )191 } else {192 None193 };194195 // =========196197 if let Some(balance_to) = balance_to {198 // from != to199 if balance_from == 0 {200 <Balance<T>>::remove((collection.id, from));201 } else {202 <Balance<T>>::insert((collection.id, from), balance_from);203 }204 <Balance<T>>::insert((collection.id, to), balance_to);205 }206207 collection.log_mirrored(ERC20Events::Transfer {208 from: *from.as_eth(),209 to: *to.as_eth(),210 value: amount.into(),211 });212 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(213 collection.id,214 TokenId::default(),215 from.clone(),216 to.clone(),217 amount,218 ));219 Ok(())220 }221222 pub fn create_multiple_items(223 collection: &FungibleHandle<T>,224 sender: &T::CrossAccountId,225 data: BTreeMap<T::CrossAccountId, u128>,226 ) -> DispatchResult {227 if !collection.is_owner_or_admin(sender) {228 ensure!(229 collection.mint_mode,230 <CommonError<T>>::PublicMintingNotAllowed231 );232 collection.check_allowlist(sender)?;233234 for (owner, _) in data.iter() {235 collection.check_allowlist(owner)?;236 }237 }238239 let total_supply = data240 .iter()241 .map(|(_, v)| *v)242 .try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {243 acc.checked_add(v)244 })245 .ok_or(ArithmeticError::Overflow)?;246247 let mut balances = data;248 for (k, v) in balances.iter_mut() {249 *v = <Balance<T>>::get((collection.id, &k))250 .checked_add(*v)251 .ok_or(ArithmeticError::Overflow)?;252 }253254 // =========255256 <TotalSupply<T>>::insert(collection.id, total_supply);257 for (user, amount) in balances {258 <Balance<T>>::insert((collection.id, &user), amount);259260 collection.log_mirrored(ERC20Events::Transfer {261 from: H160::default(),262 to: *user.as_eth(),263 value: amount.into(),264 });265 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(266 collection.id,267 TokenId::default(),268 user.clone(),269 amount,270 ));271 }272273 Ok(())274 }275276 fn set_allowance_unchecked(277 collection: &FungibleHandle<T>,278 owner: &T::CrossAccountId,279 spender: &T::CrossAccountId,280 amount: u128,281 ) {282 if amount == 0 {283 <Allowance<T>>::remove((collection.id, owner, spender));284 } else {285 <Allowance<T>>::insert((collection.id, owner, spender), amount);286 }287288 collection.log_mirrored(ERC20Events::Approval {289 owner: *owner.as_eth(),290 spender: *spender.as_eth(),291 value: amount.into(),292 });293 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(294 collection.id,295 TokenId(0),296 owner.clone(),297 spender.clone(),298 amount,299 ));300 }301302 pub fn set_allowance(303 collection: &FungibleHandle<T>,304 owner: &T::CrossAccountId,305 spender: &T::CrossAccountId,306 amount: u128,307 ) -> DispatchResult {308 if collection.access == AccessMode::AllowList {309 collection.check_allowlist(owner)?;310 collection.check_allowlist(spender)?;311 }312313 if <Balance<T>>::get((collection.id, owner)) < amount {314 ensure!(315 collection.ignores_owned_amount(owner),316 <CommonError<T>>::CantApproveMoreThanOwned317 );318 }319320 // =========321322 Self::set_allowance_unchecked(collection, owner, spender, amount);323 Ok(())324 }325326 pub fn transfer_from(327 collection: &FungibleHandle<T>,328 spender: &T::CrossAccountId,329 from: &T::CrossAccountId,330 to: &T::CrossAccountId,331 amount: u128,332 ) -> DispatchResult {333 if spender.conv_eq(from) {334 return Self::transfer(collection, from, to, amount);335 }336 if collection.access == AccessMode::AllowList {337 // `from`, `to` checked in [`transfer`]338 collection.check_allowlist(spender)?;339 }340341 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);342 if allowance.is_none() {343 ensure!(344 collection.ignores_allowance(spender),345 <CommonError<T>>::ApprovedValueTooLow346 );347 }348349 // =========350351 Self::transfer(collection, from, to, amount)?;352 if let Some(allowance) = allowance {353 Self::set_allowance_unchecked(collection, from, spender, allowance);354 }355 Ok(())356 }357358 pub fn burn_from(359 collection: &FungibleHandle<T>,360 spender: &T::CrossAccountId,361 from: &T::CrossAccountId,362 amount: u128,363 ) -> DispatchResult {364 if spender.conv_eq(from) {365 return Self::burn(collection, from, amount);366 }367 if collection.access == AccessMode::AllowList {368 // `from` checked in [`burn`]369 collection.check_allowlist(spender)?;370 }371372 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);373 if allowance.is_none() {374 ensure!(375 collection.ignores_allowance(spender),376 <CommonError<T>>::ApprovedValueTooLow377 );378 }379380 // =========381382 Self::burn(collection, from, amount)?;383 if let Some(allowance) = allowance {384 Self::set_allowance_unchecked(collection, from, spender, allowance);385 }386 Ok(())387 }388389 /// Delegated to `create_multiple_items`390 pub fn create_item(391 collection: &FungibleHandle<T>,392 sender: &T::CrossAccountId,393 data: CreateItemData<T>,394 ) -> DispatchResult {395 Self::create_multiple_items(collection, sender, vec![data])396 }397}1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};6use pallet_common::{7 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::collections::btree_map::BTreeMap;1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28 use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29 use up_data_structs::CollectionId;30 use super::weights::WeightInfo;3132 #[pallet::error]33 pub enum Error<T> {34 /// Not Fungible item data used to mint in Fungible collection.35 NotFungibleDataUsedToMintFungibleCollectionToken,36 /// Not default id passed as TokenId argument37 FungibleItemsHaveNoId,38 /// Tried to set data for fungible item39 FungibleItemsDontHaveData,40 }4142 #[pallet::config]43 pub trait Config: frame_system::Config + pallet_common::Config {44 type WeightInfo: WeightInfo;45 }4647 #[pallet::pallet]48 #[pallet::generate_store(pub(super) trait Store)]49 pub struct Pallet<T>(_);5051 #[pallet::storage]52 pub type TotalSupply<T: Config> =53 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455 #[pallet::storage]56 pub type Balance<T: Config> = StorageNMap<57 Key = (58 Key<Twox64Concat, CollectionId>,59 Key<Blake2_128Concat, T::CrossAccountId>,60 ),61 Value = u128,62 QueryKind = ValueQuery,63 >;6465 #[pallet::storage]66 pub type Allowance<T: Config> = StorageNMap<67 Key = (68 Key<Twox64Concat, CollectionId>,69 Key<Blake2_128, T::CrossAccountId>,70 Key<Blake2_128Concat, T::CrossAccountId>,71 ),72 Value = u128,73 QueryKind = ValueQuery,74 >;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80 Self(inner)81 }82 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83 self.084 }85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88 self.0.recorder()89 }90 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91 self.0.into_recorder()92 }93}94impl<T: Config> Deref for FungibleHandle<T> {95 type Target = pallet_common::CollectionHandle<T>;9697 fn deref(&self) -> &Self::Target {98 &self.099 }100}101102impl<T: Config> Pallet<T> {103 pub fn init_collection(104 owner: T::AccountId,105 data: CreateCollectionData<T::AccountId>,106 ) -> Result<CollectionId, DispatchError> {107 <PalletCommon<T>>::init_collection(owner, data)108 }109 pub fn destroy_collection(110 collection: FungibleHandle<T>,111 sender: &T::CrossAccountId,112 ) -> DispatchResult {113 let id = collection.id;114115 // =========116117 PalletCommon::destroy_collection(collection.0, sender)?;118119 <TotalSupply<T>>::remove(id);120 <Balance<T>>::remove_prefix((id,), None);121 <Allowance<T>>::remove_prefix((id,), None);122 Ok(())123 }124125 pub fn burn(126 collection: &FungibleHandle<T>,127 owner: &T::CrossAccountId,128 amount: u128,129 ) -> DispatchResult {130 let total_supply = <TotalSupply<T>>::get(collection.id)131 .checked_sub(amount)132 .ok_or(<CommonError<T>>::TokenValueTooLow)?;133134 let balance = <Balance<T>>::get((collection.id, owner))135 .checked_sub(amount)136 .ok_or(<CommonError<T>>::TokenValueTooLow)?;137138 if collection.access == AccessMode::AllowList {139 collection.check_allowlist(owner)?;140 }141142 // =========143144 if balance == 0 {145 <Balance<T>>::remove((collection.id, owner));146 } else {147 <Balance<T>>::insert((collection.id, owner), balance);148 }149 <TotalSupply<T>>::insert(collection.id, total_supply);150151 collection.log_mirrored(ERC20Events::Transfer {152 from: *owner.as_eth(),153 to: H160::default(),154 value: amount.into(),155 });156 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(157 collection.id,158 TokenId::default(),159 owner.clone(),160 amount,161 ));162 Ok(())163 }164165 pub fn transfer(166 collection: &FungibleHandle<T>,167 from: &T::CrossAccountId,168 to: &T::CrossAccountId,169 amount: u128,170 ) -> DispatchResult {171 ensure!(172 collection.limits.transfers_enabled(),173 <CommonError<T>>::TransferNotAllowed,174 );175176 if collection.access == AccessMode::AllowList {177 collection.check_allowlist(from)?;178 collection.check_allowlist(to)?;179 }180 <PalletCommon<T>>::ensure_correct_receiver(to)?;181182 let balance_from = <Balance<T>>::get((collection.id, from))183 .checked_sub(amount)184 .ok_or(<CommonError<T>>::TokenValueTooLow)?;185 let balance_to = if from != to {186 Some(187 <Balance<T>>::get((collection.id, to))188 .checked_add(amount)189 .ok_or(ArithmeticError::Overflow)?,190 )191 } else {192 None193 };194195 // =========196197 if let Some(balance_to) = balance_to {198 // from != to199 if balance_from == 0 {200 <Balance<T>>::remove((collection.id, from));201 } else {202 <Balance<T>>::insert((collection.id, from), balance_from);203 }204 <Balance<T>>::insert((collection.id, to), balance_to);205 }206207 collection.log_mirrored(ERC20Events::Transfer {208 from: *from.as_eth(),209 to: *to.as_eth(),210 value: amount.into(),211 });212 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(213 collection.id,214 TokenId::default(),215 from.clone(),216 to.clone(),217 amount,218 ));219 Ok(())220 }221222 pub fn create_multiple_items(223 collection: &FungibleHandle<T>,224 sender: &T::CrossAccountId,225 data: BTreeMap<T::CrossAccountId, u128>,226 ) -> DispatchResult {227 if !collection.is_owner_or_admin(sender) {228 ensure!(229 collection.mint_mode,230 <CommonError<T>>::PublicMintingNotAllowed231 );232 collection.check_allowlist(sender)?;233234 for (owner, _) in data.iter() {235 collection.check_allowlist(owner)?;236 }237 }238239 let total_supply = data240 .iter()241 .map(|(_, v)| *v)242 .try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {243 acc.checked_add(v)244 })245 .ok_or(ArithmeticError::Overflow)?;246247 let mut balances = data;248 for (k, v) in balances.iter_mut() {249 *v = <Balance<T>>::get((collection.id, &k))250 .checked_add(*v)251 .ok_or(ArithmeticError::Overflow)?;252 }253254 // =========255256 <TotalSupply<T>>::insert(collection.id, total_supply);257 for (user, amount) in balances {258 <Balance<T>>::insert((collection.id, &user), amount);259260 collection.log_mirrored(ERC20Events::Transfer {261 from: H160::default(),262 to: *user.as_eth(),263 value: amount.into(),264 });265 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(266 collection.id,267 TokenId::default(),268 user.clone(),269 amount,270 ));271 }272273 Ok(())274 }275276 fn set_allowance_unchecked(277 collection: &FungibleHandle<T>,278 owner: &T::CrossAccountId,279 spender: &T::CrossAccountId,280 amount: u128,281 ) {282 if amount == 0 {283 <Allowance<T>>::remove((collection.id, owner, spender));284 } else {285 <Allowance<T>>::insert((collection.id, owner, spender), amount);286 }287288 collection.log_mirrored(ERC20Events::Approval {289 owner: *owner.as_eth(),290 spender: *spender.as_eth(),291 value: amount.into(),292 });293 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(294 collection.id,295 TokenId(0),296 owner.clone(),297 spender.clone(),298 amount,299 ));300 }301302 pub fn set_allowance(303 collection: &FungibleHandle<T>,304 owner: &T::CrossAccountId,305 spender: &T::CrossAccountId,306 amount: u128,307 ) -> DispatchResult {308 if collection.access == AccessMode::AllowList {309 collection.check_allowlist(owner)?;310 collection.check_allowlist(spender)?;311 }312313 if <Balance<T>>::get((collection.id, owner)) < amount {314 ensure!(315 collection.ignores_owned_amount(owner),316 <CommonError<T>>::CantApproveMoreThanOwned317 );318 }319320 // =========321322 Self::set_allowance_unchecked(collection, owner, spender, amount);323 Ok(())324 }325326 pub fn transfer_from(327 collection: &FungibleHandle<T>,328 spender: &T::CrossAccountId,329 from: &T::CrossAccountId,330 to: &T::CrossAccountId,331 amount: u128,332 ) -> DispatchResult {333 if spender.conv_eq(from) {334 return Self::transfer(collection, from, to, amount);335 }336 if collection.access == AccessMode::AllowList {337 // `from`, `to` checked in [`transfer`]338 collection.check_allowlist(spender)?;339 }340341 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);342 if allowance.is_none() {343 ensure!(344 collection.ignores_allowance(spender),345 <CommonError<T>>::ApprovedValueTooLow346 );347 }348349 // =========350351 Self::transfer(collection, from, to, amount)?;352 if let Some(allowance) = allowance {353 Self::set_allowance_unchecked(collection, from, spender, allowance);354 }355 Ok(())356 }357358 pub fn burn_from(359 collection: &FungibleHandle<T>,360 spender: &T::CrossAccountId,361 from: &T::CrossAccountId,362 amount: u128,363 ) -> DispatchResult {364 if spender.conv_eq(from) {365 return Self::burn(collection, from, amount);366 }367 if collection.access == AccessMode::AllowList {368 // `from` checked in [`burn`]369 collection.check_allowlist(spender)?;370 }371372 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);373 if allowance.is_none() {374 ensure!(375 collection.ignores_allowance(spender),376 <CommonError<T>>::ApprovedValueTooLow377 );378 }379380 // =========381382 Self::burn(collection, from, amount)?;383 if let Some(allowance) = allowance {384 Self::set_allowance_unchecked(collection, from, spender, allowance);385 }386 Ok(())387 }388389 /// Delegated to `create_multiple_items`390 pub fn create_item(391 collection: &FungibleHandle<T>,392 sender: &T::CrossAccountId,393 data: CreateItemData<T>,394 ) -> DispatchResult {395 Self::create_multiple_items(collection, sender, [(data.0, data.1)].into_iter().collect())396 }397}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 {