git.delta.rocks / unique-network / refs/commits / 9ed680cd71d4

difftreelog

feat createMultipleItemsEx call

Yaroslav Bolyukin2022-02-26parent: #73817f4.patch.diff
in: master

16 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
17 TokenId, Weight, WithdrawReasons, CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode,17 TokenId, Weight, WithdrawReasons, CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode,
18 NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,18 NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
19 REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,19 REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,
20 CustomDataLimit, CreateCollectionData, SponsorshipState,20 CustomDataLimit, CreateCollectionData, SponsorshipState, CreateItemExData,
21};21};
22pub use pallet::*;22pub use pallet::*;
23use sp_core::H160;23use sp_core::H160;
624}624}
625625
626/// Worst cases626/// Worst cases
627pub trait CommonWeightInfo {627pub trait CommonWeightInfo<CrossAccountId> {
628 fn create_item() -> Weight;628 fn create_item() -> Weight;
629 fn create_multiple_items(amount: u32) -> Weight;629 fn create_multiple_items(amount: u32) -> Weight;
630 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
630 fn burn_item() -> Weight;631 fn burn_item() -> Weight;
631 fn transfer() -> Weight;632 fn transfer() -> Weight;
632 fn approve() -> Weight;633 fn approve() -> Weight;
648 to: T::CrossAccountId,649 to: T::CrossAccountId,
649 data: Vec<CreateItemData>,650 data: Vec<CreateItemData>,
650 ) -> DispatchResultWithPostInfo;651 ) -> DispatchResultWithPostInfo;
652 fn create_multiple_items_ex(
653 &self,
654 sender: T::CrossAccountId,
655 data: CreateItemExData<T::CrossAccountId>,
656 ) -> DispatchResultWithPostInfo;
651 fn burn_item(657 fn burn_item(
652 &self,658 &self,
653 sender: T::CrossAccountId,659 sender: T::CrossAccountId,
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
4use sp_std::prelude::*;4use sp_std::prelude::*;
5use pallet_common::benchmarking::create_collection_raw;5use pallet_common::benchmarking::create_collection_raw;
6use frame_benchmarking::{benchmarks, account};6use frame_benchmarking::{benchmarks, account};
7use up_data_structs::{CollectionMode};7use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
8use pallet_common::bench_init;8use pallet_common::bench_init;
99
10const SEED: u32 = 1;10const SEED: u32 = 1;
26 };26 };
27 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}27 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}
28
29 create_multiple_items_ex {
30 let b in 0..MAX_ITEMS_PER_BATCH;
31 bench_init!{
32 owner: sub; collection: collection(owner);
33 sender: cross_from_sub(owner);
34 };
35 let data = (0..b).map(|i| {
36 bench_init!(to: cross_sub(i););
37 (to, 200)
38 }).collect::<BTreeMap<_, _>>().try_into().unwrap();
39 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)}
2840
29 burn_item {41 burn_item {
30 bench_init!{42 bench_init!{
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
1use core::marker::PhantomData;1use core::marker::PhantomData;
22
3use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};3use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
4use up_data_structs::TokenId;4use up_data_structs::{TokenId, CreateItemExData};
5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
6use sp_runtime::ArithmeticError;6use sp_runtime::ArithmeticError;
7use sp_std::{vec::Vec, vec};7use sp_std::{vec::Vec, vec};
21 Self::create_item()21 Self::create_item()
22 }22 }
23
24 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
25 match data {
26 CreateItemExData::Fungible(f) => {
27 <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)
28 }
29 _ => 0,
30 }
31 }
2332
24 fn burn_item() -> Weight {33 fn burn_item() -> Weight {
25 <SelfWeightOf<T>>::burn_item()34 <SelfWeightOf<T>>::burn_item()
87 )96 )
88 }97 }
98
99 fn create_multiple_items_ex(
100 &self,
101 sender: <T>::CrossAccountId,
102 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
103 ) -> DispatchResultWithPostInfo {
104 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
105 let data = match data {
106 up_data_structs::CreateItemExData::Fungible(f) => f,
107 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
108 };
109
110 with_weight(
111 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
112 weight,
113 )
114 }
89115
90 fn burn_item(116 fn burn_item(
91 &self,117 &self,
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
392 sender: &T::CrossAccountId,392 sender: &T::CrossAccountId,
393 data: CreateItemData<T>,393 data: CreateItemData<T>,
394 ) -> DispatchResult {394 ) -> DispatchResult {
395 Self::create_multiple_items(collection, sender, vec![data])395 Self::create_multiple_items(collection, sender, [(data.0, data.1)].into_iter().collect())
396 }396 }
397}397}
398398
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
33/// Weight functions needed for pallet_fungible.33/// Weight functions needed for pallet_fungible.
34pub trait WeightInfo {34pub trait WeightInfo {
35 fn create_item() -> Weight;35 fn create_item() -> Weight;
36 fn create_multiple_items_ex(b: u32, ) -> Weight;
36 fn burn_item() -> Weight;37 fn burn_item() -> Weight;
37 fn transfer() -> Weight;38 fn transfer() -> Weight;
38 fn approve() -> Weight;39 fn approve() -> Weight;
50 .saturating_add(T::DbWeight::get().reads(1 as Weight))51 .saturating_add(T::DbWeight::get().reads(1 as Weight))
51 .saturating_add(T::DbWeight::get().writes(2 as Weight))52 .saturating_add(T::DbWeight::get().writes(2 as Weight))
52 }53 }
54 // Storage: Fungible TotalSupply (r:1 w:1)
55 // Storage: Fungible Balance (r:4 w:4)
56 fn create_multiple_items_ex(b: u32, ) -> Weight {
57 (1_055_000 as Weight)
58 // Standard Error: 22_000
59 .saturating_add((5_273_000 as Weight).saturating_mul(b as Weight))
60 .saturating_add(T::DbWeight::get().reads(1 as Weight))
61 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
62 .saturating_add(T::DbWeight::get().writes(1 as Weight))
63 .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))
64 }
53 // Storage: Fungible TotalSupply (r:1 w:1)65 // Storage: Fungible TotalSupply (r:1 w:1)
54 // Storage: Fungible Balance (r:1 w:1)66 // Storage: Fungible Balance (r:1 w:1)
55 fn burn_item() -> Weight {67 fn burn_item() -> Weight {
96 .saturating_add(RocksDbWeight::get().reads(1 as Weight))108 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
97 .saturating_add(RocksDbWeight::get().writes(2 as Weight))109 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
98 }110 }
111 // Storage: Fungible TotalSupply (r:1 w:1)
112 // Storage: Fungible Balance (r:4 w:4)
113 fn create_multiple_items_ex(b: u32, ) -> Weight {
114 (1_055_000 as Weight)
115 // Standard Error: 22_000
116 .saturating_add((5_273_000 as Weight).saturating_mul(b as Weight))
117 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
118 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
119 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
120 .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))
121 }
99 // Storage: Fungible TotalSupply (r:1 w:1)122 // Storage: Fungible TotalSupply (r:1 w:1)
100 // Storage: Fungible Balance (r:1 w:1)123 // Storage: Fungible Balance (r:1 w:1)
101 fn burn_item() -> Weight {124 fn burn_item() -> Weight {
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
56 let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();56 let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();
57 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}57 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
5858
59 create_multiple_items_ex {
60 let b in 0..MAX_ITEMS_PER_BATCH;
61 bench_init!{
62 owner: sub; collection: collection(owner);
63 sender: cross_from_sub(owner);
64 };
65 let data = (0..b).map(|i| {
66 bench_init!(to: cross_sub(i););
67 create_max_item_data::<T>(to)
68 }).collect();
59 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}69 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
6070
61 burn_item {71 burn_item {
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
1use core::marker::PhantomData;1use core::marker::PhantomData;
22
3use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};3use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
4use up_data_structs::{TokenId, CustomDataLimit};4use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData};
5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};5use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
6use sp_runtime::DispatchError;6use sp_runtime::DispatchError;
7use sp_std::vec::Vec;7use sp_std::vec::Vec;
17 <SelfWeightOf<T>>::create_item()17 <SelfWeightOf<T>>::create_item()
18 }18 }
19
20 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
21 match data {
22 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),
23 _ => 0,
24 }
25 }
1926
20 fn create_multiple_items(amount: u32) -> Weight {27 fn create_multiple_items(amount: u32) -> Weight {
21 <SelfWeightOf<T>>::create_multiple_items(amount)28 <SelfWeightOf<T>>::create_multiple_items(amount)
91 )98 )
92 }99 }
100
101 fn create_multiple_items_ex(
102 &self,
103 sender: <T>::CrossAccountId,
104 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
105 ) -> DispatchResultWithPostInfo {
106 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
107 let data = match data {
108 up_data_structs::CreateItemExData::NFT(nft) => nft,
109 _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),
110 };
111
112 with_weight(
113 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
114 weight,
115 )
116 }
93117
94 fn burn_item(118 fn burn_item(
95 &self,119 &self,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
3use erc::ERC721Events;3use erc::ERC721Events;
4use frame_support::{BoundedVec, ensure};4use frame_support::{BoundedVec, ensure};
5use up_data_structs::{AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData};5use up_data_structs::{
6 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
7};
6use pallet_common::{8use pallet_common::{
7 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,9 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,
22pub mod erc;24pub mod erc;
23pub mod weights;25pub mod weights;
2426
25pub struct CreateItemData<T: Config> {27pub type CreateItemData<T> = CreateNftExData<<T as pallet_common::Config>::CrossAccountId>;
26 pub const_data: BoundedVec<u8, CustomDataLimit>,
27 pub variable_data: BoundedVec<u8, CustomDataLimit>,
28 pub owner: T::CrossAccountId,
29}
30pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;28pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
3129
32#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]30#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
34pub trait WeightInfo {34pub trait WeightInfo {
35 fn create_item() -> Weight;35 fn create_item() -> Weight;
36 fn create_multiple_items(b: u32, ) -> Weight;36 fn create_multiple_items(b: u32, ) -> Weight;
37 fn create_multiple_items_ex(b: u32, ) -> Weight;
37 fn burn_item() -> Weight;38 fn burn_item() -> Weight;
38 fn transfer() -> Weight;39 fn transfer() -> Weight;
39 fn approve() -> Weight;40 fn approve() -> Weight;
66 .saturating_add(T::DbWeight::get().writes(2 as Weight))67 .saturating_add(T::DbWeight::get().writes(2 as Weight))
67 .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))68 .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
68 }69 }
70 // Storage: Nonfungible TokensMinted (r:1 w:1)
71 // Storage: Nonfungible AccountBalance (r:4 w:4)
72 // Storage: Nonfungible TokenData (r:0 w:4)
73 // Storage: Nonfungible Owned (r:0 w:4)
74 fn create_multiple_items_ex(b: u32, ) -> Weight {
75 (2_090_000 as Weight)
76 // Standard Error: 10_000
77 .saturating_add((9_230_000 as Weight).saturating_mul(b as Weight))
78 .saturating_add(T::DbWeight::get().reads(1 as Weight))
79 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
80 .saturating_add(T::DbWeight::get().writes(1 as Weight))
81 .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
82 }
69 // Storage: Nonfungible TokenData (r:1 w:1)83 // Storage: Nonfungible TokenData (r:1 w:1)
70 // Storage: Nonfungible TokensBurnt (r:1 w:1)84 // Storage: Nonfungible TokensBurnt (r:1 w:1)
71 // Storage: Nonfungible Allowance (r:1 w:0)85 // Storage: Nonfungible Allowance (r:1 w:0)
140 .saturating_add(RocksDbWeight::get().writes(2 as Weight))154 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
141 .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))155 .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
142 }156 }
157 // Storage: Nonfungible TokensMinted (r:1 w:1)
158 // Storage: Nonfungible AccountBalance (r:4 w:4)
159 // Storage: Nonfungible TokenData (r:0 w:4)
160 // Storage: Nonfungible Owned (r:0 w:4)
161 fn create_multiple_items_ex(b: u32, ) -> Weight {
162 (2_090_000 as Weight)
163 // Standard Error: 10_000
164 .saturating_add((9_230_000 as Weight).saturating_mul(b as Weight))
165 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
166 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
167 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
168 .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
169 }
143 // Storage: Nonfungible TokenData (r:1 w:1)170 // Storage: Nonfungible TokenData (r:1 w:1)
144 // Storage: Nonfungible TokensBurnt (r:1 w:1)171 // Storage: Nonfungible TokensBurnt (r:1 w:1)
145 // Storage: Nonfungible Allowance (r:1 w:0)172 // Storage: Nonfungible Allowance (r:1 w:0)
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
31 sender: &T::CrossAccountId,31 sender: &T::CrossAccountId,
32 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,32 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
33) -> Result<TokenId, DispatchError> {33) -> Result<TokenId, DispatchError> {
34 let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);
34 <Pallet<T>>::create_item(&collection, sender, create_max_item_data(users))?;35 <Pallet<T>>::create_item(&collection, sender, data)?;
35 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))36 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
36}37}
3738
60 let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();61 let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();
61 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}62 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
63
64 create_multiple_items_ex_multiple_items {
65 let b in 0..MAX_ITEMS_PER_BATCH;
66 bench_init!{
67 owner: sub; collection: collection(owner);
68 sender: cross_from_sub(owner);
69 };
70 let data = (0..b).map(|t| {
71 bench_init!(to: cross_sub(t););
72 create_max_item_data([(to, 200)])
73 }).collect();
74 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
75
76 create_multiple_items_ex_multiple_owners {
77 let b in 0..MAX_ITEMS_PER_BATCH;
78 bench_init!{
79 owner: sub; collection: collection(owner);
80 sender: cross_from_sub(owner);
81 };
82 let data = vec![create_max_item_data((0..b).map(|u| {
83 bench_init!(to: cross_sub(u););
84 (to, 200)
85 }))].try_into().unwrap();
86 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
6287
63 // Other user left, token data is kept88 // Other user left, token data is kept
64 burn_item_partial {89 burn_item_partial {
170 sender: cross_from_sub(owner);195 sender: cross_from_sub(owner);
171 };196 };
172 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;197 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;
173 let data = create_data(b as usize);198 let data = create_var_data(b).try_into().unwrap();
174 }: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}199 }: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}
175}200}
176201
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
22
3use sp_std::collections::btree_map::BTreeMap;3use sp_std::collections::btree_map::BTreeMap;
4use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};4use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
5use up_data_structs::{TokenId, CustomDataLimit};5use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData};
6use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
7use sp_runtime::DispatchError;7use sp_runtime::DispatchError;
8use sp_std::vec::Vec;8use sp_std::{vec::Vec, vec};
99
10use crate::{10use crate::{
11 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,11 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
31 <SelfWeightOf<T>>::create_multiple_items(amount)31 <SelfWeightOf<T>>::create_multiple_items(amount)
32 }32 }
33
34 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {
35 match call {
36 CreateItemExData::RefungibleMultipleOwners(i) => {
37 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)
38 }
39 CreateItemExData::RefungibleMultipleItems(i) => {
40 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)
41 }
42 _ => 0,
43 }
44 }
3345
34 fn burn_item() -> Weight {46 fn burn_item() -> Weight {
35 max_weight_of!(burn_item_partial(), burn_item_fully())47 max_weight_of!(burn_item_partial(), burn_item_fully())
69fn map_create_data<T: Config>(81fn map_create_data<T: Config>(
70 data: up_data_structs::CreateItemData,82 data: up_data_structs::CreateItemData,
71 to: &T::CrossAccountId,83 to: &T::CrossAccountId,
72) -> Result<CreateItemData<T>, DispatchError> {84) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {
73 match data {85 match data {
74 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateItemData {86 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {
75 const_data: data.const_data,87 const_data: data.const_data,
76 variable_data: data.variable_data,88 variable_data: data.variable_data,
77 users: {89 users: {
78 let mut out = BTreeMap::new();90 let mut out = BTreeMap::new();
79 out.insert(to.clone(), data.pieces);91 out.insert(to.clone(), data.pieces);
80 out92 out.try_into().expect("limit > 0")
81 },93 },
82 }),94 }),
83 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),95 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),
92 data: up_data_structs::CreateItemData,104 data: up_data_structs::CreateItemData,
93 ) -> DispatchResultWithPostInfo {105 ) -> DispatchResultWithPostInfo {
94 with_weight(106 with_weight(
95 <Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),107 <Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
96 <CommonWeights<T>>::create_item(),108 <CommonWeights<T>>::create_item(),
97 )109 )
98 }110 }
115 )127 )
116 }128 }
129
130 fn create_multiple_items_ex(
131 &self,
132 sender: <T>::CrossAccountId,
133 data: CreateItemExData<T::CrossAccountId>,
134 ) -> DispatchResultWithPostInfo {
135 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
136 let data = match data {
137 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],
138 CreateItemExData::RefungibleMultipleItems(r)
139 if r.iter().all(|i| i.users.len() == 1) =>
140 {
141 r.into_inner()
142 }
143 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),
144 };
145
146 with_weight(
147 <Pallet<T>>::create_multiple_items(self, &sender, data),
148 weight,
149 )
150 }
117151
118 fn burn_item(152 fn burn_item(
119 &self,153 &self,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
3use frame_support::{ensure, BoundedVec};3use frame_support::{ensure, BoundedVec};
4use up_data_structs::{4use up_data_structs::{
5 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId, CreateCollectionData,5 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
6 CreateCollectionData, CreateRefungibleExData,
6};7};
7use pallet_common::{8use pallet_common::{
8 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,9 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
19pub mod common;20pub mod common;
20pub mod erc;21pub mod erc;
21pub mod weights;22pub mod weights;
22pub struct CreateItemData<T: Config> {
23 pub const_data: BoundedVec<u8, CustomDataLimit>,
24 pub variable_data: BoundedVec<u8, CustomDataLimit>,
25 pub users: BTreeMap<T::CrossAccountId, u128>,
26}
27pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;23pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
2824
29#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]25#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]
361 pub fn create_multiple_items(357 pub fn create_multiple_items(
362 collection: &RefungibleHandle<T>,358 collection: &RefungibleHandle<T>,
363 sender: &T::CrossAccountId,359 sender: &T::CrossAccountId,
364 data: Vec<CreateItemData<T>>,360 data: Vec<CreateRefungibleExData<T::CrossAccountId>>,
365 ) -> DispatchResult {361 ) -> DispatchResult {
366 if !collection.is_owner_or_admin(sender) {362 if !collection.is_owner_or_admin(sender) {
367 ensure!(363 ensure!(
606 pub fn create_item(602 pub fn create_item(
607 collection: &RefungibleHandle<T>,603 collection: &RefungibleHandle<T>,
608 sender: &T::CrossAccountId,604 sender: &T::CrossAccountId,
609 data: CreateItemData<T>,605 data: CreateRefungibleExData<T::CrossAccountId>,
610 ) -> DispatchResult {606 ) -> DispatchResult {
611 Self::create_multiple_items(collection, sender, vec![data])607 Self::create_multiple_items(collection, sender, vec![data])
612 }608 }
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
34pub trait WeightInfo {34pub trait WeightInfo {
35 fn create_item() -> Weight;35 fn create_item() -> Weight;
36 fn create_multiple_items(b: u32, ) -> Weight;36 fn create_multiple_items(b: u32, ) -> Weight;
37 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight;
38 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
37 fn burn_item_partial() -> Weight;39 fn burn_item_partial() -> Weight;
38 fn burn_item_fully() -> Weight;40 fn burn_item_fully() -> Weight;
39 fn transfer_normal() -> Weight;41 fn transfer_normal() -> Weight;
77 .saturating_add(T::DbWeight::get().writes(2 as Weight))79 .saturating_add(T::DbWeight::get().writes(2 as Weight))
78 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))80 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
79 }81 }
82 // Storage: Refungible TokensMinted (r:1 w:1)
83 // Storage: Refungible AccountBalance (r:4 w:4)
84 // Storage: Refungible Balance (r:0 w:4)
85 // Storage: Refungible TotalSupply (r:0 w:4)
86 // Storage: Refungible TokenData (r:0 w:4)
87 // Storage: Refungible Owned (r:0 w:4)
88 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {
89 (11_953_000 as Weight)
90 // Standard Error: 27_000
91 .saturating_add((10_775_000 as Weight).saturating_mul(b as Weight))
92 .saturating_add(T::DbWeight::get().reads(1 as Weight))
93 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
94 .saturating_add(T::DbWeight::get().writes(1 as Weight))
95 .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(b as Weight)))
96 }
97 // Storage: Refungible TokensMinted (r:1 w:1)
98 // Storage: Refungible TotalSupply (r:0 w:1)
99 // Storage: Refungible TokenData (r:0 w:1)
100 // Storage: Refungible AccountBalance (r:4 w:4)
101 // Storage: Refungible Balance (r:0 w:4)
102 // Storage: Refungible Owned (r:0 w:4)
103 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {
104 (0 as Weight)
105 // Standard Error: 13_000
106 .saturating_add((8_528_000 as Weight).saturating_mul(b as Weight))
107 .saturating_add(T::DbWeight::get().reads(1 as Weight))
108 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
109 .saturating_add(T::DbWeight::get().writes(3 as Weight))
110 .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
111 }
80 // Storage: Refungible TotalSupply (r:1 w:1)112 // Storage: Refungible TotalSupply (r:1 w:1)
81 // Storage: Refungible Balance (r:1 w:1)113 // Storage: Refungible Balance (r:1 w:1)
82 // Storage: Refungible AccountBalance (r:1 w:1)114 // Storage: Refungible AccountBalance (r:1 w:1)
215 .saturating_add(RocksDbWeight::get().writes(2 as Weight))247 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
216 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))248 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
217 }249 }
250 // Storage: Refungible TokensMinted (r:1 w:1)
251 // Storage: Refungible AccountBalance (r:4 w:4)
252 // Storage: Refungible Balance (r:0 w:4)
253 // Storage: Refungible TotalSupply (r:0 w:4)
254 // Storage: Refungible TokenData (r:0 w:4)
255 // Storage: Refungible Owned (r:0 w:4)
256 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {
257 (11_953_000 as Weight)
258 // Standard Error: 27_000
259 .saturating_add((10_775_000 as Weight).saturating_mul(b as Weight))
260 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
261 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
262 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
263 .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(b as Weight)))
264 }
265 // Storage: Refungible TokensMinted (r:1 w:1)
266 // Storage: Refungible TotalSupply (r:0 w:1)
267 // Storage: Refungible TokenData (r:0 w:1)
268 // Storage: Refungible AccountBalance (r:4 w:4)
269 // Storage: Refungible Balance (r:0 w:4)
270 // Storage: Refungible Owned (r:0 w:4)
271 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {
272 (0 as Weight)
273 // Standard Error: 13_000
274 .saturating_add((8_528_000 as Weight).saturating_mul(b as Weight))
275 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
276 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
277 .saturating_add(RocksDbWeight::get().writes(3 as Weight))
278 .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
279 }
218 // Storage: Refungible TotalSupply (r:1 w:1)280 // Storage: Refungible TotalSupply (r:1 w:1)
219 // Storage: Refungible Balance (r:1 w:1)281 // Storage: Refungible Balance (r:1 w:1)
220 // Storage: Refungible AccountBalance (r:1 w:1)282 // Storage: Refungible AccountBalance (r:1 w:1)
modifiedpallets/unique/src/common.rsdiffbeforeafterboth
5use pallet_fungible::{common::CommonWeights as FungibleWeights};5use pallet_fungible::{common::CommonWeights as FungibleWeights};
6use pallet_nonfungible::{common::CommonWeights as NonfungibleWeights};6use pallet_nonfungible::{common::CommonWeights as NonfungibleWeights};
7use pallet_refungible::{common::CommonWeights as RefungibleWeights};7use pallet_refungible::{common::CommonWeights as RefungibleWeights};
8use up_data_structs::CreateItemExData;
89
9use crate::{Config, dispatch::dispatch_weight};10use crate::{Config, dispatch::dispatch_weight};
1011
17}18}
1819
19pub struct CommonWeights<T: Config>(PhantomData<T>);20pub struct CommonWeights<T: Config>(PhantomData<T>);
20impl<T: Config> CommonWeightInfo for CommonWeights<T> {21impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
21 fn create_item() -> up_data_structs::Weight {22 fn create_item() -> up_data_structs::Weight {
22 dispatch_weight::<T>() + max_weight_of!(create_item())23 dispatch_weight::<T>() + max_weight_of!(create_item())
23 }24 }
26 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(amount))27 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(amount))
27 }28 }
29
30 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
31 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))
32 }
2833
29 fn burn_item() -> Weight {34 fn burn_item() -> Weight {
30 dispatch_weight::<T>() + max_weight_of!(burn_item())35 dispatch_weight::<T>() + max_weight_of!(burn_item())
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
40 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,40 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,
41 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,41 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,
42 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,42 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
43 CreateCollectionData, CustomDataLimit,43 CreateCollectionData, CustomDataLimit, CreateItemExData,
44};44};
45use pallet_common::{45use pallet_common::{
46 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,46 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,
735 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))735 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))
736 }736 }
737
738 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]
739 #[transactional]
740 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
741 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
742
743 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))
744 }
737745
738 // TODO! transaction weight746 // TODO! transaction weight
739747
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]
22
3use core::convert::{TryFrom, TryInto};3use core::{
4 convert::{TryFrom, TryInto},
5 fmt,
6};
7use frame_support::storage::bounded_btree_map::BoundedBTreeMap;
8use sp_std::collections::btree_map::BTreeMap;
49
5#[cfg(feature = "serde")]10#[cfg(feature = "serde")]
6pub use serde::{Serialize, Deserialize};11pub use serde::{Serialize, Deserialize};
525 ReFungible(CreateReFungibleData),530 ReFungible(CreateReFungibleData),
526}531}
532
533#[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}
542
543#[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}
553
554#[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 owner
566 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 owners
571 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),
572}
527573
528impl CreateItemData {574impl CreateItemData {
529 pub fn data_size(&self) -> usize {575 pub fn data_size(&self) -> usize {