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.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.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use core::convert::{TryFrom, TryInto};45#[cfg(feature = "serde")]6pub use serde::{Serialize, Deserialize};78use sp_core::U256;9use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};10use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};11pub use frame_support::{12 BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,13 dispatch::DispatchResult,14 ensure, fail, parameter_types,15 traits::{16 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,17 Randomness, IsSubType, WithdrawReasons,18 },19 weights::{20 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},21 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,22 WeightToFeePolynomial, DispatchClass,23 },24 StorageValue, transactional,25 pallet_prelude::ConstU32,26};27use derivative::Derivative;28use scale_info::TypeInfo;2930mod migration;3132pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;33pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;34pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;3536pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {37 100_00038} else {39 1040};41pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {42 100_00043} else {44 1045};46pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {47 204848} else {49 1050};51pub const COLLECTION_ADMINS_LIMIT: u32 = 5;52pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;53pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {54 1_000_00055} else {56 1057};5859// Timeouts for item types in passed blocks60pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;61pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;62pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;6364pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;6566// Schema limits67pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;68pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;69pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;7071pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;72pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;73pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;7475/// How much items can be created per single76/// create_many call77pub const MAX_ITEMS_PER_BATCH: u32 = 200;7879pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;8081#[derive(82 Encode,83 Decode,84 PartialEq,85 Eq,86 PartialOrd,87 Ord,88 Clone,89 Copy,90 Debug,91 Default,92 TypeInfo,93 MaxEncodedLen,94)]95#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]96pub struct CollectionId(pub u32);97impl EncodeLike<u32> for CollectionId {}98impl EncodeLike<CollectionId> for u32 {}99100#[derive(101 Encode,102 Decode,103 PartialEq,104 Eq,105 PartialOrd,106 Ord,107 Clone,108 Copy,109 Debug,110 Default,111 TypeInfo,112 MaxEncodedLen,113)]114#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]115pub struct TokenId(pub u32);116impl EncodeLike<u32> for TokenId {}117impl EncodeLike<TokenId> for u32 {}118119impl TokenId {120 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {121 self.0122 .checked_add(1)123 .ok_or(ArithmeticError::Overflow)124 .map(Self)125 }126}127128impl From<TokenId> for U256 {129 fn from(t: TokenId) -> Self {130 t.0.into()131 }132}133134impl TryFrom<U256> for TokenId {135 type Error = &'static str;136137 fn try_from(value: U256) -> Result<Self, Self::Error> {138 Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))139 }140}141142pub struct OverflowError;143impl From<OverflowError> for &'static str {144 fn from(_: OverflowError) -> Self {145 "overflow occured"146 }147}148149pub type DecimalPoints = u8;150151#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]152#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]153pub enum CollectionMode {154 NFT,155 // decimal points156 Fungible(DecimalPoints),157 ReFungible,158}159160impl CollectionMode {161 pub fn id(&self) -> u8 {162 match self {163 CollectionMode::NFT => 1,164 CollectionMode::Fungible(_) => 2,165 CollectionMode::ReFungible => 3,166 }167 }168}169170pub trait SponsoringResolve<AccountId, Call> {171 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;172}173174#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]175#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]176pub enum AccessMode {177 Normal,178 AllowList,179}180impl Default for AccessMode {181 fn default() -> Self {182 Self::Normal183 }184}185186#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]187#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]188pub enum SchemaVersion {189 ImageURL,190 Unique,191}192impl Default for SchemaVersion {193 fn default() -> Self {194 Self::ImageURL195 }196}197198#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]199#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]200pub struct Ownership<AccountId> {201 pub owner: AccountId,202 pub fraction: u128,203}204205#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]206#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]207pub enum SponsorshipState<AccountId> {208 /// The fees are applied to the transaction sender209 Disabled,210 Unconfirmed(AccountId),211 /// Transactions are sponsored by specified account212 Confirmed(AccountId),213}214215impl<AccountId> SponsorshipState<AccountId> {216 pub fn sponsor(&self) -> Option<&AccountId> {217 match self {218 Self::Confirmed(sponsor) => Some(sponsor),219 _ => None,220 }221 }222223 pub fn pending_sponsor(&self) -> Option<&AccountId> {224 match self {225 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),226 _ => None,227 }228 }229230 pub fn confirmed(&self) -> bool {231 matches!(self, Self::Confirmed(_))232 }233}234235impl<T> Default for SponsorshipState<T> {236 fn default() -> Self {237 Self::Disabled238 }239}240241#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]242#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]243pub struct Collection<AccountId> {244 pub owner: AccountId,245 pub mode: CollectionMode,246 pub access: AccessMode,247 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]248 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,249 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]250 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,251 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]252 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,253 pub mint_mode: bool,254 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]255 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,256 pub schema_version: SchemaVersion,257 pub sponsorship: SponsorshipState<AccountId>,258 pub limits: CollectionLimits, // Collection private restrictions259 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]260 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,261 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]262 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,263 pub meta_update_permission: MetaUpdatePermission,264}265266#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Debug, Derivative, MaxEncodedLen)]267#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]268#[derivative(Default(bound = ""))]269pub struct CreateCollectionData<AccountId> {270 #[derivative(Default(value = "CollectionMode::NFT"))]271 pub mode: CollectionMode,272 pub access: Option<AccessMode>,273 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]274 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,275 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]276 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,277 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]278 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,279 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]280 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,281 pub schema_version: Option<SchemaVersion>,282 pub pending_sponsor: Option<AccountId>,283 pub limits: Option<CollectionLimits>,284 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]285 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,286 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]287 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,288 pub meta_update_permission: Option<MetaUpdatePermission>,289}290291#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]292#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]293pub struct NftItemType<AccountId> {294 pub owner: AccountId,295 pub const_data: Vec<u8>,296 pub variable_data: Vec<u8>,297}298299#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]300#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]301pub struct FungibleItemType {302 pub value: u128,303}304305#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]306#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]307pub struct ReFungibleItemType<AccountId> {308 pub owner: Vec<Ownership<AccountId>>,309 pub const_data: Vec<u8>,310 pub variable_data: Vec<u8>,311}312313/// All fields are wrapped in `Option`s, where None means chain default314#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]315#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]316pub struct CollectionLimits {317 pub account_token_ownership_limit: Option<u32>,318 pub sponsored_data_size: Option<u32>,319 /// None - setVariableMetadata is not sponsored320 /// Some(v) - setVariableMetadata is sponsored321 /// if there is v block between txs322 pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,323 pub token_limit: Option<u32>,324325 // Timeouts for item types in passed blocks326 pub sponsor_transfer_timeout: Option<u32>,327 pub sponsor_approve_timeout: Option<u32>,328 pub owner_can_transfer: Option<bool>,329 pub owner_can_destroy: Option<bool>,330 pub transfers_enabled: Option<bool>,331}332333impl CollectionLimits {334 pub fn account_token_ownership_limit(&self) -> u32 {335 self.account_token_ownership_limit336 .unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)337 .min(MAX_TOKEN_OWNERSHIP)338 }339 pub fn sponsored_data_size(&self) -> u32 {340 self.sponsored_data_size341 .unwrap_or(CUSTOM_DATA_LIMIT)342 .min(CUSTOM_DATA_LIMIT)343 }344 pub fn token_limit(&self) -> u32 {345 self.token_limit346 .unwrap_or(COLLECTION_TOKEN_LIMIT)347 .min(COLLECTION_TOKEN_LIMIT)348 }349 pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {350 self.sponsor_transfer_timeout351 .unwrap_or(default)352 .min(MAX_SPONSOR_TIMEOUT)353 }354 pub fn sponsor_approve_timeout(&self) -> u32 {355 self.sponsor_approve_timeout356 .unwrap_or(SPONSOR_APPROVE_TIMEOUT)357 .min(MAX_SPONSOR_TIMEOUT)358 }359 pub fn owner_can_transfer(&self) -> bool {360 self.owner_can_transfer.unwrap_or(true)361 }362 pub fn owner_can_destroy(&self) -> bool {363 self.owner_can_destroy.unwrap_or(true)364 }365 pub fn transfers_enabled(&self) -> bool {366 self.transfers_enabled.unwrap_or(true)367 }368 pub fn sponsored_data_rate_limit(&self) -> Option<u32> {369 match self370 .sponsored_data_rate_limit371 .unwrap_or(SponsoringRateLimit::SponsoringDisabled)372 {373 SponsoringRateLimit::SponsoringDisabled => None,374 SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),375 }376 }377}378379#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]380#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]381pub enum SponsoringRateLimit {382 SponsoringDisabled,383 Blocks(u32),384}385386/// BoundedVec doesn't supports serde387#[cfg(feature = "serde1")]388mod bounded_serde {389 use core::convert::TryFrom;390 use frame_support::{BoundedVec, traits::Get};391 use serde::{392 ser::{self, Serialize},393 de::{self, Deserialize, Error},394 };395 use sp_std::vec::Vec;396397 pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>398 where399 D: ser::Serializer,400 V: Serialize,401 {402 (value as &Vec<_>).serialize(serializer)403 }404405 pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>406 where407 D: de::Deserializer<'de>,408 V: de::Deserialize<'de>,409 S: Get<u32>,410 {411 // TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?412 let vec = <Vec<V>>::deserialize(deserializer)?;413 let len = vec.len();414 TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))415 }416}417418fn bounded_debug<V, S>(v: &BoundedVec<V, S>, f: &mut fmt::Formatter) -> Result<(), fmt::Error>419where420 V: fmt::Debug,421{422 use core::fmt::Debug;423 (&v as &Vec<V>).fmt(f)424}425426#[cfg(feature = "serde1")]427#[allow(dead_code)]428mod bounded_map_serde {429 use core::convert::TryFrom;430 use sp_std::collections::btree_map::BTreeMap;431 use frame_support::{traits::Get, storage::bounded_btree_map::BoundedBTreeMap};432 use serde::{433 ser::{self, Serialize},434 de::{self, Deserialize, Error},435 };436 pub fn serialize<D, K, V, S>(437 value: &BoundedBTreeMap<K, V, S>,438 serializer: D,439 ) -> Result<D::Ok, D::Error>440 where441 D: ser::Serializer,442 K: Serialize + Ord,443 V: Serialize,444 {445 (value as &BTreeMap<_, _>).serialize(serializer)446 }447448 pub fn deserialize<'de, D, K, V, S>(449 deserializer: D,450 ) -> Result<BoundedBTreeMap<K, V, S>, D::Error>451 where452 D: de::Deserializer<'de>,453 K: de::Deserialize<'de> + Ord,454 V: de::Deserialize<'de>,455 S: Get<u32>,456 {457 let map = <BTreeMap<K, V>>::deserialize(deserializer)?;458 let len = map.len();459 TryFrom::try_from(map).map_err(|_| D::Error::invalid_length(len, &"lesser size"))460 }461}462463fn bounded_map_debug<K, V, S>(464 v: &BoundedBTreeMap<K, V, S>,465 f: &mut fmt::Formatter,466) -> Result<(), fmt::Error>467where468 K: fmt::Debug + Ord,469 V: fmt::Debug,470{471 use core::fmt::Debug;472 (&v as &BTreeMap<K, V>).fmt(f)473}474475#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]476#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]477#[derivative(Debug)]478pub struct CreateNftData {479 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]480 #[derivative(Debug(format_with = "bounded_debug"))]481 pub const_data: BoundedVec<u8, CustomDataLimit>,482 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]483 #[derivative(Debug(format_with = "bounded_debug"))]484 pub variable_data: BoundedVec<u8, CustomDataLimit>,485}486487#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]488#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]489pub struct CreateFungibleData {490 pub value: u128,491}492493#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]494#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]495#[derivative(Debug)]496pub struct CreateReFungibleData {497 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]498 #[derivative(Debug(format_with = "bounded_debug"))]499 pub const_data: BoundedVec<u8, CustomDataLimit>,500 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]501 #[derivative(Debug(format_with = "bounded_debug"))]502 pub variable_data: BoundedVec<u8, CustomDataLimit>,503 pub pieces: u128,504}505506#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]507#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]508pub enum MetaUpdatePermission {509 ItemOwner,510 Admin,511 None,512}513514impl Default for MetaUpdatePermission {515 fn default() -> Self {516 Self::ItemOwner517 }518}519520#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]521#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]522pub enum CreateItemData {523 NFT(CreateNftData),524 Fungible(CreateFungibleData),525 ReFungible(CreateReFungibleData),526}527528impl CreateItemData {529 pub fn data_size(&self) -> usize {530 match self {531 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),532 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),533 _ => 0,534 }535 }536}537538impl From<CreateNftData> for CreateItemData {539 fn from(item: CreateNftData) -> Self {540 CreateItemData::NFT(item)541 }542}543544impl From<CreateReFungibleData> for CreateItemData {545 fn from(item: CreateReFungibleData) -> Self {546 CreateItemData::ReFungible(item)547 }548}549550impl From<CreateFungibleData> for CreateItemData {551 fn from(item: CreateFungibleData) -> Self {552 CreateItemData::Fungible(item)553 }554}555556#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]557#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]558pub struct CollectionStats {559 pub created: u32,560 pub destroyed: u32,561 pub alive: u32,562}1#![cfg_attr(not(feature = "std"), no_std)]23use core::{4 convert::{TryFrom, TryInto},5 fmt,6};7use frame_support::storage::bounded_btree_map::BoundedBTreeMap;8use sp_std::collections::btree_map::BTreeMap;910#[cfg(feature = "serde")]11pub use serde::{Serialize, Deserialize};1213use sp_core::U256;14use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};15use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};16pub use frame_support::{17 BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,18 dispatch::DispatchResult,19 ensure, fail, parameter_types,20 traits::{21 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,22 Randomness, IsSubType, WithdrawReasons,23 },24 weights::{25 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},26 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,27 WeightToFeePolynomial, DispatchClass,28 },29 StorageValue, transactional,30 pallet_prelude::ConstU32,31};32use derivative::Derivative;33use scale_info::TypeInfo;3435mod migration;3637pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;38pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;39pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;4041pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {42 100_00043} else {44 1045};46pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {47 100_00048} else {49 1050};51pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {52 204853} else {54 1055};56pub const COLLECTION_ADMINS_LIMIT: u32 = 5;57pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;58pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {59 1_000_00060} else {61 1062};6364// Timeouts for item types in passed blocks65pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;66pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;67pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;6869pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;7071// Schema limits72pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;73pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;74pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;7576pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;77pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;78pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;7980/// How much items can be created per single81/// create_many call82pub const MAX_ITEMS_PER_BATCH: u32 = 200;8384pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;8586#[derive(87 Encode,88 Decode,89 PartialEq,90 Eq,91 PartialOrd,92 Ord,93 Clone,94 Copy,95 Debug,96 Default,97 TypeInfo,98 MaxEncodedLen,99)]100#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]101pub struct CollectionId(pub u32);102impl EncodeLike<u32> for CollectionId {}103impl EncodeLike<CollectionId> for u32 {}104105#[derive(106 Encode,107 Decode,108 PartialEq,109 Eq,110 PartialOrd,111 Ord,112 Clone,113 Copy,114 Debug,115 Default,116 TypeInfo,117 MaxEncodedLen,118)]119#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]120pub struct TokenId(pub u32);121impl EncodeLike<u32> for TokenId {}122impl EncodeLike<TokenId> for u32 {}123124impl TokenId {125 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {126 self.0127 .checked_add(1)128 .ok_or(ArithmeticError::Overflow)129 .map(Self)130 }131}132133impl From<TokenId> for U256 {134 fn from(t: TokenId) -> Self {135 t.0.into()136 }137}138139impl TryFrom<U256> for TokenId {140 type Error = &'static str;141142 fn try_from(value: U256) -> Result<Self, Self::Error> {143 Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))144 }145}146147pub struct OverflowError;148impl From<OverflowError> for &'static str {149 fn from(_: OverflowError) -> Self {150 "overflow occured"151 }152}153154pub type DecimalPoints = u8;155156#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]157#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]158pub enum CollectionMode {159 NFT,160 // decimal points161 Fungible(DecimalPoints),162 ReFungible,163}164165impl CollectionMode {166 pub fn id(&self) -> u8 {167 match self {168 CollectionMode::NFT => 1,169 CollectionMode::Fungible(_) => 2,170 CollectionMode::ReFungible => 3,171 }172 }173}174175pub trait SponsoringResolve<AccountId, Call> {176 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;177}178179#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]180#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]181pub enum AccessMode {182 Normal,183 AllowList,184}185impl Default for AccessMode {186 fn default() -> Self {187 Self::Normal188 }189}190191#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]192#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]193pub enum SchemaVersion {194 ImageURL,195 Unique,196}197impl Default for SchemaVersion {198 fn default() -> Self {199 Self::ImageURL200 }201}202203#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]204#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]205pub struct Ownership<AccountId> {206 pub owner: AccountId,207 pub fraction: u128,208}209210#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]211#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]212pub enum SponsorshipState<AccountId> {213 /// The fees are applied to the transaction sender214 Disabled,215 Unconfirmed(AccountId),216 /// Transactions are sponsored by specified account217 Confirmed(AccountId),218}219220impl<AccountId> SponsorshipState<AccountId> {221 pub fn sponsor(&self) -> Option<&AccountId> {222 match self {223 Self::Confirmed(sponsor) => Some(sponsor),224 _ => None,225 }226 }227228 pub fn pending_sponsor(&self) -> Option<&AccountId> {229 match self {230 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),231 _ => None,232 }233 }234235 pub fn confirmed(&self) -> bool {236 matches!(self, Self::Confirmed(_))237 }238}239240impl<T> Default for SponsorshipState<T> {241 fn default() -> Self {242 Self::Disabled243 }244}245246#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]247#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]248pub struct Collection<AccountId> {249 pub owner: AccountId,250 pub mode: CollectionMode,251 pub access: AccessMode,252 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]253 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,254 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]255 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,256 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]257 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,258 pub mint_mode: bool,259 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]260 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,261 pub schema_version: SchemaVersion,262 pub sponsorship: SponsorshipState<AccountId>,263 pub limits: CollectionLimits, // Collection private restrictions264 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]265 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,266 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]267 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,268 pub meta_update_permission: MetaUpdatePermission,269}270271#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Debug, Derivative, MaxEncodedLen)]272#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]273#[derivative(Default(bound = ""))]274pub struct CreateCollectionData<AccountId> {275 #[derivative(Default(value = "CollectionMode::NFT"))]276 pub mode: CollectionMode,277 pub access: Option<AccessMode>,278 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]279 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,280 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]281 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,282 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]283 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,284 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]285 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,286 pub schema_version: Option<SchemaVersion>,287 pub pending_sponsor: Option<AccountId>,288 pub limits: Option<CollectionLimits>,289 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]290 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,291 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]292 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,293 pub meta_update_permission: Option<MetaUpdatePermission>,294}295296#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]297#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]298pub struct NftItemType<AccountId> {299 pub owner: AccountId,300 pub const_data: Vec<u8>,301 pub variable_data: Vec<u8>,302}303304#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]305#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]306pub struct FungibleItemType {307 pub value: u128,308}309310#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]311#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]312pub struct ReFungibleItemType<AccountId> {313 pub owner: Vec<Ownership<AccountId>>,314 pub const_data: Vec<u8>,315 pub variable_data: Vec<u8>,316}317318/// All fields are wrapped in `Option`s, where None means chain default319#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]320#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]321pub struct CollectionLimits {322 pub account_token_ownership_limit: Option<u32>,323 pub sponsored_data_size: Option<u32>,324 /// None - setVariableMetadata is not sponsored325 /// Some(v) - setVariableMetadata is sponsored326 /// if there is v block between txs327 pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,328 pub token_limit: Option<u32>,329330 // Timeouts for item types in passed blocks331 pub sponsor_transfer_timeout: Option<u32>,332 pub sponsor_approve_timeout: Option<u32>,333 pub owner_can_transfer: Option<bool>,334 pub owner_can_destroy: Option<bool>,335 pub transfers_enabled: Option<bool>,336}337338impl CollectionLimits {339 pub fn account_token_ownership_limit(&self) -> u32 {340 self.account_token_ownership_limit341 .unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)342 .min(MAX_TOKEN_OWNERSHIP)343 }344 pub fn sponsored_data_size(&self) -> u32 {345 self.sponsored_data_size346 .unwrap_or(CUSTOM_DATA_LIMIT)347 .min(CUSTOM_DATA_LIMIT)348 }349 pub fn token_limit(&self) -> u32 {350 self.token_limit351 .unwrap_or(COLLECTION_TOKEN_LIMIT)352 .min(COLLECTION_TOKEN_LIMIT)353 }354 pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {355 self.sponsor_transfer_timeout356 .unwrap_or(default)357 .min(MAX_SPONSOR_TIMEOUT)358 }359 pub fn sponsor_approve_timeout(&self) -> u32 {360 self.sponsor_approve_timeout361 .unwrap_or(SPONSOR_APPROVE_TIMEOUT)362 .min(MAX_SPONSOR_TIMEOUT)363 }364 pub fn owner_can_transfer(&self) -> bool {365 self.owner_can_transfer.unwrap_or(true)366 }367 pub fn owner_can_destroy(&self) -> bool {368 self.owner_can_destroy.unwrap_or(true)369 }370 pub fn transfers_enabled(&self) -> bool {371 self.transfers_enabled.unwrap_or(true)372 }373 pub fn sponsored_data_rate_limit(&self) -> Option<u32> {374 match self375 .sponsored_data_rate_limit376 .unwrap_or(SponsoringRateLimit::SponsoringDisabled)377 {378 SponsoringRateLimit::SponsoringDisabled => None,379 SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),380 }381 }382}383384#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]385#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]386pub enum SponsoringRateLimit {387 SponsoringDisabled,388 Blocks(u32),389}390391/// BoundedVec doesn't supports serde392#[cfg(feature = "serde1")]393mod bounded_serde {394 use core::convert::TryFrom;395 use frame_support::{BoundedVec, traits::Get};396 use serde::{397 ser::{self, Serialize},398 de::{self, Deserialize, Error},399 };400 use sp_std::vec::Vec;401402 pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>403 where404 D: ser::Serializer,405 V: Serialize,406 {407 (value as &Vec<_>).serialize(serializer)408 }409410 pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>411 where412 D: de::Deserializer<'de>,413 V: de::Deserialize<'de>,414 S: Get<u32>,415 {416 // TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?417 let vec = <Vec<V>>::deserialize(deserializer)?;418 let len = vec.len();419 TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))420 }421}422423fn bounded_debug<V, S>(v: &BoundedVec<V, S>, f: &mut fmt::Formatter) -> Result<(), fmt::Error>424where425 V: fmt::Debug,426{427 use core::fmt::Debug;428 (&v as &Vec<V>).fmt(f)429}430431#[cfg(feature = "serde1")]432#[allow(dead_code)]433mod bounded_map_serde {434 use core::convert::TryFrom;435 use sp_std::collections::btree_map::BTreeMap;436 use frame_support::{traits::Get, storage::bounded_btree_map::BoundedBTreeMap};437 use serde::{438 ser::{self, Serialize},439 de::{self, Deserialize, Error},440 };441 pub fn serialize<D, K, V, S>(442 value: &BoundedBTreeMap<K, V, S>,443 serializer: D,444 ) -> Result<D::Ok, D::Error>445 where446 D: ser::Serializer,447 K: Serialize + Ord,448 V: Serialize,449 {450 (value as &BTreeMap<_, _>).serialize(serializer)451 }452453 pub fn deserialize<'de, D, K, V, S>(454 deserializer: D,455 ) -> Result<BoundedBTreeMap<K, V, S>, D::Error>456 where457 D: de::Deserializer<'de>,458 K: de::Deserialize<'de> + Ord,459 V: de::Deserialize<'de>,460 S: Get<u32>,461 {462 let map = <BTreeMap<K, V>>::deserialize(deserializer)?;463 let len = map.len();464 TryFrom::try_from(map).map_err(|_| D::Error::invalid_length(len, &"lesser size"))465 }466}467468fn bounded_map_debug<K, V, S>(469 v: &BoundedBTreeMap<K, V, S>,470 f: &mut fmt::Formatter,471) -> Result<(), fmt::Error>472where473 K: fmt::Debug + Ord,474 V: fmt::Debug,475{476 use core::fmt::Debug;477 (&v as &BTreeMap<K, V>).fmt(f)478}479480#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]481#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]482#[derivative(Debug)]483pub struct CreateNftData {484 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]485 #[derivative(Debug(format_with = "bounded_debug"))]486 pub const_data: BoundedVec<u8, CustomDataLimit>,487 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]488 #[derivative(Debug(format_with = "bounded_debug"))]489 pub variable_data: BoundedVec<u8, CustomDataLimit>,490}491492#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]493#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]494pub struct CreateFungibleData {495 pub value: u128,496}497498#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]499#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]500#[derivative(Debug)]501pub struct CreateReFungibleData {502 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]503 #[derivative(Debug(format_with = "bounded_debug"))]504 pub const_data: BoundedVec<u8, CustomDataLimit>,505 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]506 #[derivative(Debug(format_with = "bounded_debug"))]507 pub variable_data: BoundedVec<u8, CustomDataLimit>,508 pub pieces: u128,509}510511#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]512#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]513pub enum MetaUpdatePermission {514 ItemOwner,515 Admin,516 None,517}518519impl Default for MetaUpdatePermission {520 fn default() -> Self {521 Self::ItemOwner522 }523}524525#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]526#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]527pub enum CreateItemData {528 NFT(CreateNftData),529 Fungible(CreateFungibleData),530 ReFungible(CreateReFungibleData),531}532533#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]534#[derivative(Debug)]535pub struct CreateNftExData<CrossAccountId> {536 #[derivative(Debug(format_with = "bounded_debug"))]537 pub const_data: BoundedVec<u8, CustomDataLimit>,538 #[derivative(Debug(format_with = "bounded_debug"))]539 pub variable_data: BoundedVec<u8, CustomDataLimit>,540 pub owner: CrossAccountId,541}542543#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]544#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]545pub struct CreateRefungibleExData<CrossAccountId> {546 #[derivative(Debug(format_with = "bounded_debug"))]547 pub const_data: BoundedVec<u8, CustomDataLimit>,548 #[derivative(Debug(format_with = "bounded_debug"))]549 pub variable_data: BoundedVec<u8, CustomDataLimit>,550 #[derivative(Debug(format_with = "bounded_map_debug"))]551 pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,552}553554#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]555#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]556pub enum CreateItemExData<CrossAccountId> {557 NFT(558 #[derivative(Debug(format_with = "bounded_debug"))]559 BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,560 ),561 Fungible(562 #[derivative(Debug(format_with = "bounded_map_debug"))]563 BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,564 ),565 /// Many tokens, each may have only one owner566 RefungibleMultipleItems(567 #[derivative(Debug(format_with = "bounded_debug"))]568 BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,569 ),570 /// Single token, which may have many owners571 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),572}573574impl CreateItemData {575 pub fn data_size(&self) -> usize {576 match self {577 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),578 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),579 _ => 0,580 }581 }582}583584impl From<CreateNftData> for CreateItemData {585 fn from(item: CreateNftData) -> Self {586 CreateItemData::NFT(item)587 }588}589590impl From<CreateReFungibleData> for CreateItemData {591 fn from(item: CreateReFungibleData) -> Self {592 CreateItemData::ReFungible(item)593 }594}595596impl From<CreateFungibleData> for CreateItemData {597 fn from(item: CreateFungibleData) -> Self {598 CreateItemData::Fungible(item)599 }600}601602#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]603#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]604pub struct CollectionStats {605 pub created: u32,606 pub destroyed: u32,607 pub alive: u32,608}