git.delta.rocks / unique-network / refs/commits / d76cc13924e4

difftreelog

Merge branch 'develop' into feature/CORE-302-ss58Format

Igor Kozyrev2022-06-08parents: #0362d33 #c557492.patch.diff
in: master

17 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
20use frame_benchmarking::{benchmarks, account};20use frame_benchmarking::{benchmarks, account};
21use up_data_structs::{21use up_data_structs::{
22 CollectionMode, CreateCollectionData, CollectionId, Property, PropertyKey, PropertyValue,22 CollectionMode, CreateCollectionData, CollectionId, Property, PropertyKey, PropertyValue,
23 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,23 CollectionPermissions, NestingRule, MAX_COLLECTION_NAME_LENGTH,
24 OFFCHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, MAX_PROPERTIES_PER_ITEM,24 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, MAX_PROPERTIES_PER_ITEM,
25};25};
26use frame_support::{26use frame_support::{
27 traits::{Currency, Get},27 traits::{Currency, Get},
74}74}
7575
76pub fn create_collection_raw<T: Config, R>(76pub fn create_collection_raw<T: Config, R>(
77 owner: T::AccountId,77 owner: T::CrossAccountId,
78 mode: CollectionMode,78 mode: CollectionMode,
79 handler: impl FnOnce(79 handler: impl FnOnce(
80 T::AccountId,80 T::CrossAccountId,
81 CreateCollectionData<T::AccountId>,81 CreateCollectionData<T::AccountId>,
82 ) -> Result<CollectionId, DispatchError>,82 ) -> Result<CollectionId, DispatchError>,
83 cast: impl FnOnce(CollectionHandle<T>) -> R,83 cast: impl FnOnce(CollectionHandle<T>) -> R,
84) -> Result<R, DispatchError> {84) -> Result<R, DispatchError> {
85 T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());85 <T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());
86 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();86 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
87 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();87 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
88 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();88 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
93 name,93 name,
94 description,94 description,
95 token_prefix,95 token_prefix,
96 permissions: Some(CollectionPermissions {
97 nesting: Some(NestingRule::Permissive),
98 ..Default::default()
99 }),
96 ..Default::default()100 ..Default::default()
97 },101 },
98 )102 )
99 .and_then(CollectionHandle::try_get)103 .and_then(CollectionHandle::try_get)
100 .map(cast)104 .map(cast)
101}105}
102fn create_collection<T: Config>(owner: T::AccountId) -> Result<CollectionHandle<T>, DispatchError> {106fn create_collection<T: Config>(
107 owner: T::CrossAccountId,
108) -> Result<CollectionHandle<T>, DispatchError> {
103 create_collection_raw(109 create_collection_raw(
104 owner,110 owner,
127 bench_init!($($rest)*);133 bench_init!($($rest)*);
128 };134 };
129 ($name:ident: collection($owner:ident); $($rest:tt)*) => {135 ($name:ident: collection($owner:ident); $($rest:tt)*) => {
130 let $name = create_collection::<T>($owner.clone())?;136 let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;
131 bench_init!($($rest)*);137 bench_init!($($rest)*);
132 };138 };
133 ($name:ident: cross; $($rest:tt)*) => {139 ($name:ident: cross; $($rest:tt)*) => {
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1170 }1170 }
1171
1171 pub fn clamp_permissions(1172 pub fn clamp_permissions(
1172 mode: CollectionMode,1173 _mode: CollectionMode,
1173 old_limit: &CollectionPermissions,1174 old_limit: &CollectionPermissions,
1174 mut new_limit: CollectionPermissions,1175 mut new_limit: CollectionPermissions,
1175 ) -> Result<CollectionPermissions, DispatchError> {1176 ) -> Result<CollectionPermissions, DispatchError> {
1205 fn transfer_from() -> Weight;1206 fn transfer_from() -> Weight;
1206 fn burn_from() -> Weight;1207 fn burn_from() -> Weight;
1208
1209 /// Differs from burn_item in case of Fungible and Refungible, as it should burn
1210 /// whole users's balance
1211 ///
1212 /// This method shouldn't be used directly, as it doesn't count breadth price, use `burn_recursively` instead
1213 fn burn_recursively_self_raw() -> Weight;
1214 /// Cost of iterating over `amount` children while burning, without counting child burning itself
1215 ///
1216 /// This method shouldn't be used directly, as it doesn't count depth price, use `burn_recursively` instead
1217 fn burn_recursively_breadth_raw(amount: u32) -> Weight;
1218
1219 fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {
1220 Self::burn_recursively_self_raw()
1221 .saturating_mul(max_selfs.max(1) as u64)
1222 .saturating_add(Self::burn_recursively_breadth_raw(max_breadth))
1223 }
1207}1224}
12081225
1209pub trait CommonCollectionOperations<T: Config> {1226pub trait CommonCollectionOperations<T: Config> {
1233 token: TokenId,1250 token: TokenId,
1234 amount: u128,1251 amount: u128,
1235 ) -> DispatchResultWithPostInfo;1252 ) -> DispatchResultWithPostInfo;
1253 fn burn_item_recursively(
1254 &self,
1255 sender: T::CrossAccountId,
1256 token: TokenId,
1257 self_budget: &dyn Budget,
1258 breadth_budget: &dyn Budget,
1259 ) -> DispatchResultWithPostInfo;
1236 fn set_collection_properties(1260 fn set_collection_properties(
1237 &self,1261 &self,
1238 sender: T::CrossAccountId,1262 sender: T::CrossAccountId,
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
2525
26const SEED: u32 = 1;26const SEED: u32 = 1;
2727
28fn create_collection<T: Config>(owner: T::AccountId) -> Result<FungibleHandle<T>, DispatchError> {28fn create_collection<T: Config>(
29 owner: T::CrossAccountId,
30) -> Result<FungibleHandle<T>, DispatchError> {
29 create_collection_raw(31 create_collection_raw(
30 owner,32 owner,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
1616
17use core::marker::PhantomData;17use core::marker::PhantomData;
1818
19use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};19use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};20use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};
21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
22use pallet_structure::Error as StructureError;
22use sp_runtime::ArithmeticError;23use sp_runtime::ArithmeticError;
23use sp_std::{vec::Vec, vec};24use sp_std::{vec::Vec, vec};
24use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};25use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
92 <SelfWeightOf<T>>::burn_from()93 <SelfWeightOf<T>>::burn_from()
93 }94 }
95
96 fn burn_recursively_self_raw() -> Weight {
97 // Read to get total balance
98 Self::burn_item() + T::DbWeight::get().reads(1)
99 }
100
101 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
102 // Fungible tokens can't have children
103 0
104 }
94}105}
95106
96impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {107impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
170 )181 )
171 }182 }
183
184 fn burn_item_recursively(
185 &self,
186 sender: T::CrossAccountId,
187 token: TokenId,
188 self_budget: &dyn Budget,
189 _breadth_budget: &dyn Budget,
190 ) -> DispatchResultWithPostInfo {
191 // Should not happen?
192 ensure!(
193 token == TokenId::default(),
194 <Error<T>>::FungibleItemsHaveNoId
195 );
196 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
197
198 with_weight(
199 <Pallet<T>>::burn(self, &sender, <Balance<T>>::get((self.id, &sender))),
200 <CommonWeights<T>>::burn_recursively_self_raw(),
201 )
202 }
172203
173 fn transfer(204 fn transfer(
174 &self,205 &self,
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
18use crate::{Pallet, Config, NonfungibleHandle};18use crate::{Pallet, Config, NonfungibleHandle};
1919
20use sp_std::prelude::*;20use sp_std::prelude::*;
21use pallet_common::benchmarking::{create_collection_raw, create_data, property_key, property_value};21use pallet_common::benchmarking::{create_collection_raw, property_key, property_value};
22use frame_benchmarking::{benchmarks, account};22use frame_benchmarking::{benchmarks, account};
23use up_data_structs::{23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, budget::Unlimited};
24 CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, CUSTOM_DATA_LIMIT,
25 budget::Unlimited,
26};
27use pallet_common::bench_init;24use pallet_common::bench_init;
2825
49}46}
5047
51fn create_collection<T: Config>(48fn create_collection<T: Config>(
52 owner: T::AccountId,49 owner: T::CrossAccountId,
53) -> Result<NonfungibleHandle<T>, DispatchError> {50) -> Result<NonfungibleHandle<T>, DispatchError> {
54 create_collection_raw(51 create_collection_raw(
55 owner,52 owner,
96 let item = create_max_item(&collection, &sender, burner.clone())?;93 let item = create_max_item(&collection, &sender, burner.clone())?;
97 }: {<Pallet<T>>::burn(&collection, &burner, item)?}94 }: {<Pallet<T>>::burn(&collection, &burner, item)?}
95
96 burn_recursively_self_raw {
97 bench_init!{
98 owner: sub; collection: collection(owner);
99 sender: cross_from_sub(owner); burner: cross_sub;
100 };
101 let item = create_max_item(&collection, &sender, burner.clone())?;
102 }: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)}
103
104 burn_recursively_breadth_plus_self_plus_self_per_each_raw {
105 let b in 0..200;
106 bench_init!{
107 owner: sub; collection: collection(owner);
108 sender: cross_from_sub(owner); burner: cross_sub;
109 };
110 let item = create_max_item(&collection, &sender, burner.clone())?;
111 for i in 0..b {
112 create_max_item(&collection, &sender, T::CrossTokenAddressMapping::token_to_address(collection.id, item))?;
113 }
114 }: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)}
98115
99 transfer {116 transfer {
100 bench_init!{117 bench_init!{
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
109 <SelfWeightOf<T>>::burn_from()109 <SelfWeightOf<T>>::burn_from()
110 }110 }
111
112 fn burn_recursively_self_raw() -> Weight {
113 <SelfWeightOf<T>>::burn_recursively_self_raw()
114 }
115
116 fn burn_recursively_breadth_raw(amount: u32) -> Weight {
117 <SelfWeightOf<T>>::burn_recursively_breadth_plus_self_plus_self_per_each_raw(amount)
118 .saturating_sub(Self::burn_recursively_self_raw().saturating_mul(amount as u64 + 1))
119 }
111}120}
112121
113fn map_create_data<T: Config>(122fn map_create_data<T: Config>(
264 }273 }
265 }274 }
275
276 fn burn_item_recursively(
277 &self,
278 sender: T::CrossAccountId,
279 token: TokenId,
280 self_budget: &dyn Budget,
281 breadth_budget: &dyn Budget,
282 ) -> DispatchResultWithPostInfo {
283 <Pallet<T>>::burn_recursively(self, &sender, token, self_budget, breadth_budget)
284 }
266285
267 fn transfer(286 fn transfer(
268 &self,287 &self,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
20use evm_coder::ToLog;20use evm_coder::ToLog;
21use frame_support::{BoundedVec, ensure, fail, transactional, storage::with_transaction};21use frame_support::{
22 BoundedVec, ensure, fail, transactional,
23 storage::with_transaction,
24 pallet_prelude::DispatchResultWithPostInfo,
25 pallet_prelude::Weight,
26 weights::{PostDispatchInfo, Pays},
27};
22use up_data_structs::{28use up_data_structs::{
23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,29 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
29 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,35 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
30 eth::collection_id_to_address,36 eth::collection_id_to_address,
31};37};
32use pallet_structure::Pallet as PalletStructure;38use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};39use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
34use sp_core::H160;40use sp_core::H160;
35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};41use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
39use scale_info::TypeInfo;45use scale_info::TypeInfo;
4046
41pub use pallet::*;47pub use pallet::*;
48use weights::WeightInfo;
42#[cfg(feature = "runtime-benchmarks")]49#[cfg(feature = "runtime-benchmarks")]
43pub mod benchmarking;50pub mod benchmarking;
44pub mod common;51pub mod common;
373 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(380 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(
374 collection.id,381 collection.id,
375 token,382 token,
376 sender.clone(),383 token_data.owner.clone(),
377 old_spender,384 old_spender,
378 0,385 0,
379 ));386 ));
396 Ok(())403 Ok(())
397 }404 }
405
406 #[transactional]
407 pub fn burn_recursively(
408 collection: &NonfungibleHandle<T>,
409 sender: &T::CrossAccountId,
410 token: TokenId,
411 self_budget: &dyn Budget,
412 breadth_budget: &dyn Budget,
413 ) -> DispatchResultWithPostInfo {
414 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
415
416 let current_token_account =
417 T::CrossTokenAddressMapping::token_to_address(collection.id, token);
418
419 let mut weight = 0 as Weight;
420
421 // This method is transactional, if user in fact doesn't have permissions to remove token -
422 // tokens removed here will be restored after rejected transaction
423 for ((collection, token), _) in <TokenChildren<T>>::iter_prefix((collection.id, token)) {
424 ensure!(breadth_budget.consume(), <StructureError<T>>::BreadthLimit,);
425 let PostDispatchInfo { actual_weight, .. } =
426 <PalletStructure<T>>::burn_item_recursively(
427 current_token_account.clone(),
428 collection,
429 token,
430 self_budget,
431 breadth_budget,
432 )?;
433 if let Some(actual_weight) = actual_weight {
434 weight = weight.saturating_add(actual_weight);
435 }
436 }
437
438 Self::burn(collection, sender, token)?;
439 DispatchResultWithPostInfo::Ok(PostDispatchInfo {
440 actual_weight: Some(weight + <SelfWeightOf<T>>::burn_item()),
441 pays_fee: Pays::Yes,
442 })
443 }
398444
399 pub fn set_token_property(445 pub fn set_token_property(
400 collection: &NonfungibleHandle<T>,446 collection: &NonfungibleHandle<T>,
964 );1010 );
965 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?1011 ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?
966 }1012 }
1013 NestingRule::Permissive => {}
967 }1014 }
968 Ok(())1015 Ok(())
969 }1016 }
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
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 create_multiple_items_ex(b: u32, ) -> Weight;
38 fn burn_item() -> Weight;38 fn burn_item() -> Weight;
39 fn burn_recursively_self_raw() -> Weight;
40 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;
39 fn transfer() -> Weight;41 fn transfer() -> Weight;
40 fn approve() -> Weight;42 fn approve() -> Weight;
41 fn transfer_from() -> Weight;43 fn transfer_from() -> Weight;
92 .saturating_add(T::DbWeight::get().reads(4 as Weight))94 .saturating_add(T::DbWeight::get().reads(4 as Weight))
93 .saturating_add(T::DbWeight::get().writes(4 as Weight))95 .saturating_add(T::DbWeight::get().writes(4 as Weight))
94 }96 }
9597 // Storage: Nonfungible TokenChildren (r:1 w:0)
98 // Storage: Nonfungible TokenData (r:1 w:1)
99 // Storage: Nonfungible TokensBurnt (r:1 w:1)
100 // Storage: Nonfungible AccountBalance (r:1 w:1)
101 // Storage: Nonfungible Allowance (r:1 w:0)
102 // Storage: Nonfungible Owned (r:0 w:1)
103 // Storage: Nonfungible TokenProperties (r:0 w:1)
104 fn burn_recursively_self_raw() -> Weight {
105 (86_136_000 as Weight)
106 .saturating_add(T::DbWeight::get().reads(5 as Weight))
107 .saturating_add(T::DbWeight::get().writes(5 as Weight))
108 }
109 // Storage: Nonfungible TokenChildren (r:1 w:0)
110 // Storage: Nonfungible TokenData (r:1 w:1)
111 // Storage: Nonfungible TokensBurnt (r:1 w:1)
112 // Storage: Nonfungible AccountBalance (r:1 w:1)
113 // Storage: Nonfungible Allowance (r:1 w:0)
114 // Storage: Nonfungible Owned (r:0 w:1)
115 // Storage: Nonfungible TokenProperties (r:0 w:1)
116 // Storage: Common CollectionById (r:1 w:0)
117 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
118 (0 as Weight)
119 // Standard Error: 42_828_000
120 .saturating_add((381_478_000 as Weight).saturating_mul(b as Weight))
121 .saturating_add(T::DbWeight::get().reads(6 as Weight))
122 .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
123 .saturating_add(T::DbWeight::get().writes(5 as Weight))
124 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
125 }
96 // Storage: Nonfungible TokenData (r:1 w:1)126 // Storage: Nonfungible TokenData (r:1 w:1)
97 // Storage: Nonfungible AccountBalance (r:2 w:2)127 // Storage: Nonfungible AccountBalance (r:2 w:2)
98 // Storage: Nonfungible Allowance (r:1 w:0)128 // Storage: Nonfungible Allowance (r:1 w:0)
204 .saturating_add(RocksDbWeight::get().reads(4 as Weight))234 .saturating_add(RocksDbWeight::get().reads(4 as Weight))
205 .saturating_add(RocksDbWeight::get().writes(4 as Weight))235 .saturating_add(RocksDbWeight::get().writes(4 as Weight))
206 }236 }
207237 // Storage: Nonfungible TokenChildren (r:1 w:0)
238 // Storage: Nonfungible TokenData (r:1 w:1)
239 // Storage: Nonfungible TokensBurnt (r:1 w:1)
240 // Storage: Nonfungible AccountBalance (r:1 w:1)
241 // Storage: Nonfungible Allowance (r:1 w:0)
242 // Storage: Nonfungible Owned (r:0 w:1)
243 // Storage: Nonfungible TokenProperties (r:0 w:1)
244 fn burn_recursively_self_raw() -> Weight {
245 (86_136_000 as Weight)
246 .saturating_add(RocksDbWeight::get().reads(5 as Weight))
247 .saturating_add(RocksDbWeight::get().writes(5 as Weight))
248 }
249 // Storage: Nonfungible TokenChildren (r:1 w:0)
250 // Storage: Nonfungible TokenData (r:1 w:1)
251 // Storage: Nonfungible TokensBurnt (r:1 w:1)
252 // Storage: Nonfungible AccountBalance (r:1 w:1)
253 // Storage: Nonfungible Allowance (r:1 w:0)
254 // Storage: Nonfungible Owned (r:0 w:1)
255 // Storage: Nonfungible TokenProperties (r:0 w:1)
256 // Storage: Common CollectionById (r:1 w:0)
257 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
258 (0 as Weight)
259 // Standard Error: 42_828_000
260 .saturating_add((381_478_000 as Weight).saturating_mul(b as Weight))
261 .saturating_add(RocksDbWeight::get().reads(6 as Weight))
262 .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
263 .saturating_add(RocksDbWeight::get().writes(5 as Weight))
264 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
265 }
208 // Storage: Nonfungible TokenData (r:1 w:1)266 // Storage: Nonfungible TokenData (r:1 w:1)
209 // Storage: Nonfungible AccountBalance (r:2 w:2)267 // Storage: Nonfungible AccountBalance (r:2 w:2)
210 // Storage: Nonfungible Allowance (r:1 w:0)268 // Storage: Nonfungible Allowance (r:1 w:0)
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
50 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))50 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
51}51}
5252
53fn create_collection<T: Config>(owner: T::AccountId) -> Result<RefungibleHandle<T>, DispatchError> {53fn create_collection<T: Config>(
54 owner: T::CrossAccountId,
55) -> Result<RefungibleHandle<T>, DispatchError> {
54 create_collection_raw(56 create_collection_raw(
55 owner,57 owner,
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
17use core::marker::PhantomData;17use core::marker::PhantomData;
1818
19use sp_std::collections::btree_map::BTreeMap;19use sp_std::collections::btree_map::BTreeMap;
20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};20use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
21use up_data_structs::{21use up_data_structs::{
22 CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,22 CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,
23 PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData,23 PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData,
24};24};
25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
26use pallet_structure::Error as StructureError;
26use sp_runtime::DispatchError;27use sp_runtime::DispatchError;
27use sp_std::{vec::Vec, vec};28use sp_std::{vec::Vec, vec};
2829
114 <SelfWeightOf<T>>::burn_from()115 <SelfWeightOf<T>>::burn_from()
115 }116 }
117
118 fn burn_recursively_self_raw() -> Weight {
119 // Read to get total balance
120 Self::burn_item() + T::DbWeight::get().reads(1)
121 }
122 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
123 // Refungible token can't have children
124 0
125 }
116}126}
117127
118fn map_create_data<T: Config>(128fn map_create_data<T: Config>(
205 )215 )
206 }216 }
217
218 fn burn_item_recursively(
219 &self,
220 sender: T::CrossAccountId,
221 token: TokenId,
222 self_budget: &dyn Budget,
223 _breadth_budget: &dyn Budget,
224 ) -> DispatchResultWithPostInfo {
225 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
226 with_weight(
227 <Pallet<T>>::burn(
228 self,
229 &sender,
230 token,
231 <Balance<T>>::get((self.id, token, &sender)),
232 ),
233 <CommonWeights<T>>::burn_recursively_self_raw(),
234 )
235 }
207236
208 fn transfer(237 fn transfer(
209 &self,238 &self,
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
60// Ensure we're `no_std` when compiling for Wasm.60// Ensure we're `no_std` when compiling for Wasm.
61#![cfg_attr(not(feature = "std"), no_std)]61#![cfg_attr(not(feature = "std"), no_std)]
6262
63#[cfg(feature = "runtime-benchmarks")]63// FIXME
64mod benchmarking;64// #[cfg(feature = "runtime-benchmarks")]
65// mod benchmarking;
6566
66pub mod weights;67pub mod weights;
6768
modifiedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
5use up_data_structs::{5use up_data_structs::{
6 CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,6 CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
7};7};
8use pallet_common::Config as CommonConfig;
8use pallet_evm::account::CrossAccountId;9use pallet_evm::account::CrossAccountId;
910
10const SEED: u32 = 1;11const SEED: u32 = 1;
14 let caller: T::AccountId = account("caller", 0, SEED);15 let caller: T::AccountId = account("caller", 0, SEED);
15 let caller_cross = T::CrossAccountId::from_sub(caller.clone());16 let caller_cross = T::CrossAccountId::from_sub(caller.clone());
1617
17 T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());18 <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
18 T::CollectionDispatch::create(caller, CreateCollectionData {19 T::CollectionDispatch::create(caller_cross.clone(), CreateCollectionData {
19 mode: CollectionMode::NFT,20 mode: CollectionMode::NFT,
20 ..Default::default()21 ..Default::default()
21 })?;22 })?;
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
3use pallet_common::CommonCollectionOperations;3use pallet_common::CommonCollectionOperations;
4use sp_std::collections::btree_set::BTreeSet;4use sp_std::collections::btree_set::BTreeSet;
55
6use frame_support::dispatch::{DispatchError, DispatchResult};6use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};
7use frame_support::fail;7use frame_support::fail;
8pub use pallet::*;8pub use pallet::*;
9use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};9use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};
29 OuroborosDetected,29 OuroborosDetected,
30 /// While searched for owner, encountered depth limit30 /// While searched for owner, encountered depth limit
31 DepthLimit,31 DepthLimit,
32 /// While iterating over children, encountered breadth limit
33 BreadthLimit,
32 /// While searched for owner, found token owner by not-yet-existing token34 /// While searched for owner, found token owner by not-yet-existing token
33 TokenNotFound,35 TokenNotFound,
34 }36 }
184 Err(<Error<T>>::DepthLimit.into())186 Err(<Error<T>>::DepthLimit.into())
185 }187 }
188
189 pub fn burn_item_recursively(
190 from: T::CrossAccountId,
191 collection: CollectionId,
192 token: TokenId,
193 self_budget: &dyn Budget,
194 breadth_budget: &dyn Budget,
195 ) -> DispatchResultWithPostInfo {
196 let handle = <CollectionHandle<T>>::try_get(collection)?;
197 let dispatch = T::CollectionDispatch::dispatch(handle);
198 let dispatch = dispatch.as_dyn();
199 dispatch.burn_item_recursively(from.clone(), token, self_budget, breadth_budget)
200 }
186201
187 pub fn check_nesting(202 pub fn check_nesting(
188 from: T::CrossAccountId,203 from: T::CrossAccountId,
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
22use frame_support::traits::{tokens::currency::Currency, Get};22use frame_support::traits::{tokens::currency::Currency, Get};
23use frame_benchmarking::{benchmarks, account};23use frame_benchmarking::{benchmarks, account};
24use sp_runtime::DispatchError;24use sp_runtime::DispatchError;
25use pallet_common::benchmarking::{create_data, create_var_data, create_u16_data};25use pallet_common::{
26 Config as CommonConfig,
27 benchmarking::{create_data, create_u16_data},
28};
2629
27const SEED: u32 = 1;30const SEED: u32 = 1;
2831
29fn create_collection_helper<T: Config>(32fn create_collection_helper<T: Config>(
30 owner: T::AccountId,33 owner: T::AccountId,
31 mode: CollectionMode,34 mode: CollectionMode,
32) -> Result<CollectionId, DispatchError> {35) -> Result<CollectionId, DispatchError> {
33 T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());36 <T as CommonConfig>::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
34 let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();37 let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
35 let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();38 let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
36 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();39 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
54 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();57 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
55 let mode: CollectionMode = CollectionMode::NFT;58 let mode: CollectionMode = CollectionMode::NFT;
56 let caller: T::AccountId = account("caller", 0, SEED);59 let caller: T::AccountId = account("caller", 0, SEED);
57 T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());60 <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
58 }: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)61 }: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)
59 verify {62 verify {
60 assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);63 assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);
78 <Pallet<T>>::add_to_allow_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(allowlist_account.clone()))?;81 <Pallet<T>>::add_to_allow_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(allowlist_account.clone()))?;
79 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))82 }: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))
80
81 set_public_access_mode {
82 let caller: T::AccountId = account("caller", 0, SEED);
83 let collection = create_nft_collection::<T>(caller.clone())?;
84 }: _(RawOrigin::Signed(caller.clone()), collection, AccessMode::AllowList)
85
86 set_mint_permission {
87 let caller: T::AccountId = account("caller", 0, SEED);
88 let collection = create_nft_collection::<T>(caller.clone())?;
89 }: _(RawOrigin::Signed(caller.clone()), collection, true)
9083
91 change_collection_owner {84 change_collection_owner {
92 let caller: T::AccountId = account("caller", 0, SEED);85 let caller: T::AccountId = account("caller", 0, SEED);
145 owner_can_transfer: Some(true),138 owner_can_transfer: Some(true),
146 sponsored_data_rate_limit: None,139 sponsored_data_rate_limit: None,
147 transfers_enabled: Some(true),140 transfers_enabled: Some(true),
148 nesting_rule: None,
149 };141 };
150 }: set_collection_limits(RawOrigin::Signed(caller.clone()), collection, cl)142 }: set_collection_limits(RawOrigin::Signed(caller.clone()), collection, cl)
151}143}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
469 #[derivative(Debug(format_with = "bounded::set_debug"))]469 #[derivative(Debug(format_with = "bounded::set_debug"))]
470 BoundedBTreeSet<CollectionId, ConstU32<16>>,470 BoundedBTreeSet<CollectionId, ConstU32<16>>,
471 ),471 ),
472 /// Used for tests
473 Permissive,
472}474}
473475
474#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]476#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
90 dispatch_weight::<T>() + max_weight_of!(burn_from())90 dispatch_weight::<T>() + max_weight_of!(burn_from())
91 }91 }
92
93 fn burn_recursively_self_raw() -> Weight {
94 max_weight_of!(burn_recursively_self_raw())
95 }
96
97 fn burn_recursively_breadth_raw(amount: u32) -> Weight {
98 max_weight_of!(burn_recursively_breadth_raw(amount))
99 }
92}100}
93101
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
73 CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits,73 CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits,
74 CollectionStats, RpcCollection,74 CollectionStats, RpcCollection,
75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
76 TokenChild,
76};77};
7778
78// use pallet_contracts::weights::WeightInfo;79// use pallet_contracts::weights::WeightInfo;