difftreelog
Merge branch 'develop' into feature/docker-base-img
in: master
11 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -176,7 +176,7 @@
key: property_key(p as usize),
value: property_value(),
}).collect::<Vec<_>>();
- }: {<Pallet<T>>::set_collection_properties(&collection, &owner, props)?}
+ }: {<Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?}
delete_collection_properties {
let b in 0..MAX_PROPERTIES_PER_ITEM;
@@ -188,7 +188,7 @@
key: property_key(p as usize),
value: property_value(),
}).collect::<Vec<_>>();
- <Pallet<T>>::set_collection_properties(&collection, &owner, props)?;
+ <Pallet<T>>::set_collection_properties(&collection, &owner, props.into_iter())?;
let to_delete = (0..b).map(|p| property_key(p as usize)).collect::<Vec<_>>();
- }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete)?}
+ }: {<Pallet<T>>::delete_collection_properties(&collection, &owner, to_delete.into_iter())?}
}
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -125,7 +125,7 @@
.map(eth::Property::try_into)
.collect::<Result<Vec<_>>>()?;
- <Pallet<T>>::set_collection_properties(self, &caller, properties)
+ <Pallet<T>>::set_collection_properties(self, &caller, properties.into_iter())
.map_err(dispatch_to_evm::<T>)
}
@@ -158,7 +158,8 @@
})
.collect::<Result<Vec<_>>>()?;
- <Pallet<T>>::delete_collection_properties(self, &caller, keys).map_err(dispatch_to_evm::<T>)
+ <Pallet<T>>::delete_collection_properties(self, &caller, keys.into_iter())
+ .map_err(dispatch_to_evm::<T>)
}
/// Get collection property.
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1198,6 +1198,58 @@
Ok(())
}
+ /// This function sets or removes a collection properties according to
+ /// `properties_updates` contents:
+ /// * sets a property under the <key> with the value provided `(<key>, Some(<value>))`
+ /// * removes a property under the <key> if the value is `None` `(<key>, None)`.
+ ///
+ /// This function fires an event for each property change.
+ /// In case of an error, all the changes (including the events) will be reverted
+ /// since the function is transactional.
+ #[transactional]
+ fn modify_collection_properties(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
+ ) -> DispatchResult {
+ collection.check_is_owner_or_admin(sender)?;
+
+ let mut stored_properties = <CollectionProperties<T>>::get(collection.id);
+
+ for (key, value) in properties_updates {
+ match value {
+ Some(value) => {
+ stored_properties
+ .try_set(key.clone(), value)
+ .map_err(<Error<T>>::from)?;
+
+ Self::deposit_event(Event::CollectionPropertySet(collection.id, key));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+ }
+ None => {
+ stored_properties.remove(&key).map_err(<Error<T>>::from)?;
+
+ Self::deposit_event(Event::CollectionPropertyDeleted(collection.id, key));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+ }
+ }
+ }
+
+ <CollectionProperties<T>>::set(collection.id, stored_properties);
+
+ Ok(())
+ }
+
/// Set collection property.
///
/// * `collection` - Collection handler.
@@ -1208,23 +1260,7 @@
sender: &T::CrossAccountId,
property: Property,
) -> DispatchResult {
- collection.check_is_owner_or_admin(sender)?;
-
- CollectionProperties::<T>::try_mutate(collection.id, |properties| {
- let property = property.clone();
- properties.try_set(property.key, property.value)
- })
- .map_err(<Error<T>>::from)?;
-
- Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));
- <PalletEvm<T>>::deposit_log(
- erc::CollectionHelpersEvents::CollectionChanged {
- collection_id: eth::collection_id_to_address(collection.id),
- }
- .to_log(T::ContractAddress::get()),
- );
-
- Ok(())
+ Self::set_collection_properties(collection, sender, [property].into_iter())
}
/// Set a scoped collection property, where the scope is a special prefix
@@ -1270,17 +1306,16 @@
/// * `collection` - Collection handler.
/// * `sender` - The owner or administrator of the collection.
/// * `properties` - The properties to set.
- #[transactional]
pub fn set_collection_properties(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- properties: Vec<Property>,
+ properties: impl Iterator<Item = Property>,
) -> DispatchResult {
- for property in properties {
- Self::set_collection_property(collection, sender, property)?;
- }
-
- Ok(())
+ Self::modify_collection_properties(
+ collection,
+ sender,
+ properties.map(|property| (property.key, Some(property.value))),
+ )
}
/// Delete collection property.
@@ -1293,25 +1328,7 @@
sender: &T::CrossAccountId,
property_key: PropertyKey,
) -> DispatchResult {
- collection.check_is_owner_or_admin(sender)?;
-
- CollectionProperties::<T>::try_mutate(collection.id, |properties| {
- properties.remove(&property_key)
- })
- .map_err(<Error<T>>::from)?;
-
- Self::deposit_event(Event::CollectionPropertyDeleted(
- collection.id,
- property_key,
- ));
- <PalletEvm<T>>::deposit_log(
- erc::CollectionHelpersEvents::CollectionChanged {
- collection_id: eth::collection_id_to_address(collection.id),
- }
- .to_log(T::ContractAddress::get()),
- );
-
- Ok(())
+ Self::delete_collection_properties(collection, sender, [property_key].into_iter())
}
/// Delete collection properties.
@@ -1319,17 +1336,12 @@
/// * `collection` - Collection handler.
/// * `sender` - The owner or administrator of the collection.
/// * `properties` - The properties to delete.
- #[transactional]
pub fn delete_collection_properties(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- property_keys: Vec<PropertyKey>,
+ property_keys: impl Iterator<Item = PropertyKey>,
) -> DispatchResult {
- for key in property_keys {
- Self::delete_collection_property(collection, sender, key)?;
- }
-
- Ok(())
+ Self::modify_collection_properties(collection, sender, property_keys.map(|key| (key, None)))
}
/// Set collection propetry permission without any checks.
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -266,7 +266,7 @@
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
- <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
}
/// Delete properties of the collection, associated with the provided keys.
@@ -275,7 +275,11 @@
sender: &T::CrossAccountId,
property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ <PalletCommon<T>>::delete_collection_properties(
+ collection,
+ sender,
+ property_keys.into_iter(),
+ )
}
/// Checks if collection has tokens. Return `true` if it has.
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -577,20 +577,29 @@
})
}
- /// Batch operation to add, edit or remove properties for the token
+ /// A batch operation to add, edit or remove properties for a token.
+ /// It sets or removes a token's properties according to
+ /// `properties_updates` contents:
+ /// * sets a property under the <key> with the value provided `(<key>, Some(<value>))`
+ /// * removes a property under the <key> if the value is `None` `(<key>, None)`.
///
- /// All affected properties should have mutable permission and sender should have
- /// permission to edit those properties.
- ///
- /// - `nesting_budget`: Limit for searching parents in depth to check ownership.
+ /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
/// - `is_token_create`: Indicates that method is called during token initialization.
/// Allows to bypass ownership check.
+ ///
+ /// All affected properties should have `mutable` permission
+ /// to be **deleted** or to be **set more than once**,
+ /// and the sender should have permission to edit those properties.
+ ///
+ /// This function fires an event for each property change.
+ /// In case of an error, all the changes (including the events) will be reverted
+ /// since the function is transactional.
#[transactional]
fn modify_token_properties(
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
token_id: TokenId,
- properties: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
+ properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
is_token_create: bool,
nesting_budget: &dyn Budget,
) -> DispatchResult {
@@ -614,15 +623,16 @@
})
};
- for (key, value) in properties {
- let permission = <PalletCommon<T>>::property_permissions(collection.id)
+ let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
+ let permissions = <PalletCommon<T>>::property_permissions(collection.id);
+
+ for (key, value) in properties_updates {
+ let permission = permissions
.get(&key)
.cloned()
.unwrap_or_else(PropertyPermission::none);
- let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
- .get(&key)
- .is_some();
+ let is_property_exists = stored_properties.get(&key).is_some();
match permission {
PropertyPermission { mutable: false, .. } if is_property_exists => {
@@ -649,10 +659,9 @@
match value {
Some(value) => {
- <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.try_set(key.clone(), value)
- })
- .map_err(<CommonError<T>>::from)?;
+ stored_properties
+ .try_set(key.clone(), value)
+ .map_err(<CommonError<T>>::from)?;
<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
collection.id,
@@ -661,10 +670,9 @@
));
}
None => {
- <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.remove(&key)
- })
- .map_err(<CommonError<T>>::from)?;
+ stored_properties
+ .remove(&key)
+ .map_err(<CommonError<T>>::from)?;
<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
collection.id,
@@ -683,6 +691,8 @@
);
}
+ <TokenProperties<T>>::set((collection.id, token_id), stored_properties);
+
Ok(())
}
@@ -784,7 +794,7 @@
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
- <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
}
/// Remove properties from the collection
@@ -793,7 +803,11 @@
sender: &T::CrossAccountId,
property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ <PalletCommon<T>>::delete_collection_properties(
+ collection,
+ sender,
+ property_keys.into_iter(),
+ )
}
/// Set property permissions for the token.
pallets/nonfungible/src/weights.rsdiffbeforeafterboth1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_nonfungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-12-26, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-nonfungible15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/nonfungible/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_nonfungible.36pub trait WeightInfo {37 fn create_item() -> Weight;38 fn create_multiple_items(b: u32, ) -> Weight;39 fn create_multiple_items_ex(b: u32, ) -> Weight;40 fn burn_item() -> Weight;41 fn burn_recursively_self_raw() -> Weight;42 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;43 fn transfer() -> Weight;44 fn approve() -> Weight;45 fn approve_from() -> Weight;46 fn transfer_from() -> Weight;47 fn burn_from() -> Weight;48 fn set_token_property_permissions(b: u32, ) -> Weight;49 fn set_token_properties(b: u32, ) -> Weight;50 fn delete_token_properties(b: u32, ) -> Weight;51 fn token_owner() -> Weight;52 fn set_allowance_for_all() -> Weight;53 fn allowance_for_all() -> Weight;54 fn repair_item() -> Weight;55}5657/// Weights for pallet_nonfungible using the Substrate node and recommended hardware.58pub struct SubstrateWeight<T>(PhantomData<T>);59impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {60 // Storage: Nonfungible TokensMinted (r:1 w:1)61 // Storage: Nonfungible AccountBalance (r:1 w:1)62 // Storage: Nonfungible TokenData (r:0 w:1)63 // Storage: Nonfungible Owned (r:0 w:1)64 fn create_item() -> Weight {65 Weight::from_ref_time(26_377_000 as u64)66 .saturating_add(T::DbWeight::get().reads(2 as u64))67 .saturating_add(T::DbWeight::get().writes(4 as u64))68 }69 // Storage: Nonfungible TokensMinted (r:1 w:1)70 // Storage: Nonfungible AccountBalance (r:1 w:1)71 // Storage: Nonfungible TokenData (r:0 w:4)72 // Storage: Nonfungible Owned (r:0 w:4)73 fn create_multiple_items(b: u32, ) -> Weight {74 Weight::from_ref_time(20_059_186 as u64)75 // Standard Error: 4_73576 .saturating_add(Weight::from_ref_time(4_856_306 as u64).saturating_mul(b as u64))77 .saturating_add(T::DbWeight::get().reads(2 as u64))78 .saturating_add(T::DbWeight::get().writes(2 as u64))79 .saturating_add(T::DbWeight::get().writes((2 as u64).saturating_mul(b as u64)))80 }81 // Storage: Nonfungible TokensMinted (r:1 w:1)82 // Storage: Nonfungible AccountBalance (r:4 w:4)83 // Storage: Nonfungible TokenData (r:0 w:4)84 // Storage: Nonfungible Owned (r:0 w:4)85 fn create_multiple_items_ex(b: u32, ) -> Weight {86 Weight::from_ref_time(16_365_581 as u64)87 // Standard Error: 9_71188 .saturating_add(Weight::from_ref_time(6_681_940 as u64).saturating_mul(b as u64))89 .saturating_add(T::DbWeight::get().reads(1 as u64))90 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))91 .saturating_add(T::DbWeight::get().writes(1 as u64))92 .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64)))93 }94 // Storage: Nonfungible TokenData (r:1 w:1)95 // Storage: Nonfungible TokenChildren (r:1 w:0)96 // Storage: Nonfungible TokensBurnt (r:1 w:1)97 // Storage: Nonfungible AccountBalance (r:1 w:1)98 // Storage: Nonfungible Allowance (r:1 w:0)99 // Storage: Nonfungible Owned (r:0 w:1)100 // Storage: Nonfungible TokenProperties (r:0 w:1)101 fn burn_item() -> Weight {102 Weight::from_ref_time(33_502_000 as u64)103 .saturating_add(T::DbWeight::get().reads(5 as u64))104 .saturating_add(T::DbWeight::get().writes(5 as u64))105 }106 // Storage: Nonfungible TokenChildren (r:1 w:0)107 // Storage: Nonfungible TokenData (r:1 w:1)108 // Storage: Nonfungible TokensBurnt (r:1 w:1)109 // Storage: Nonfungible AccountBalance (r:1 w:1)110 // Storage: Nonfungible Allowance (r:1 w:0)111 // Storage: Nonfungible Owned (r:0 w:1)112 // Storage: Nonfungible TokenProperties (r:0 w:1)113 fn burn_recursively_self_raw() -> Weight {114 Weight::from_ref_time(43_255_000 as u64)115 .saturating_add(T::DbWeight::get().reads(5 as u64))116 .saturating_add(T::DbWeight::get().writes(5 as u64))117 }118 // Storage: Nonfungible TokenChildren (r:1 w:0)119 // Storage: Nonfungible TokenData (r:1 w:1)120 // Storage: Nonfungible TokensBurnt (r:1 w:1)121 // Storage: Nonfungible AccountBalance (r:1 w:1)122 // Storage: Nonfungible Allowance (r:1 w:0)123 // Storage: Nonfungible Owned (r:0 w:1)124 // Storage: Nonfungible TokenProperties (r:0 w:1)125 // Storage: Common CollectionById (r:1 w:0)126 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {127 Weight::from_ref_time(42_992_000 as u64)128 // Standard Error: 1_010_119129 .saturating_add(Weight::from_ref_time(209_972_755 as u64).saturating_mul(b as u64))130 .saturating_add(T::DbWeight::get().reads(7 as u64))131 .saturating_add(T::DbWeight::get().reads((4 as u64).saturating_mul(b as u64)))132 .saturating_add(T::DbWeight::get().writes(6 as u64))133 .saturating_add(T::DbWeight::get().writes((4 as u64).saturating_mul(b as u64)))134 }135 // Storage: Nonfungible TokenData (r:1 w:1)136 // Storage: Nonfungible AccountBalance (r:2 w:2)137 // Storage: Nonfungible Allowance (r:1 w:0)138 // Storage: Nonfungible Owned (r:0 w:2)139 fn transfer() -> Weight {140 Weight::from_ref_time(31_239_000 as u64)141 .saturating_add(T::DbWeight::get().reads(4 as u64))142 .saturating_add(T::DbWeight::get().writes(5 as u64))143 }144 // Storage: Nonfungible TokenData (r:1 w:0)145 // Storage: Nonfungible Allowance (r:1 w:1)146 fn approve() -> Weight {147 Weight::from_ref_time(21_985_000 as u64)148 .saturating_add(T::DbWeight::get().reads(2 as u64))149 .saturating_add(T::DbWeight::get().writes(1 as u64))150 }151 // Storage: Nonfungible TokenData (r:1 w:0)152 // Storage: Nonfungible Allowance (r:1 w:1)153 fn approve_from() -> Weight {154 Weight::from_ref_time(18_965_000 as u64)155 .saturating_add(T::DbWeight::get().reads(2 as u64))156 .saturating_add(T::DbWeight::get().writes(1 as u64))157 }158 // Storage: Nonfungible Allowance (r:1 w:1)159 // Storage: Nonfungible TokenData (r:1 w:1)160 // Storage: Nonfungible AccountBalance (r:2 w:2)161 // Storage: Nonfungible Owned (r:0 w:2)162 fn transfer_from() -> Weight {163 Weight::from_ref_time(36_382_000 as u64)164 .saturating_add(T::DbWeight::get().reads(4 as u64))165 .saturating_add(T::DbWeight::get().writes(6 as u64))166 }167 // Storage: Nonfungible Allowance (r:1 w:1)168 // Storage: Nonfungible TokenData (r:1 w:1)169 // Storage: Nonfungible TokenChildren (r:1 w:0)170 // Storage: Nonfungible TokensBurnt (r:1 w:1)171 // Storage: Nonfungible AccountBalance (r:1 w:1)172 // Storage: Nonfungible Owned (r:0 w:1)173 // Storage: Nonfungible TokenProperties (r:0 w:1)174 fn burn_from() -> Weight {175 Weight::from_ref_time(42_046_000 as u64)176 .saturating_add(T::DbWeight::get().reads(5 as u64))177 .saturating_add(T::DbWeight::get().writes(6 as u64))178 }179 // Storage: Common CollectionPropertyPermissions (r:1 w:1)180 fn set_token_property_permissions(b: u32, ) -> Weight {181 Weight::from_ref_time(5_543_000 as u64)182 // Standard Error: 40_525183 .saturating_add(Weight::from_ref_time(12_126_787 as u64).saturating_mul(b as u64))184 .saturating_add(T::DbWeight::get().reads(1 as u64))185 .saturating_add(T::DbWeight::get().writes(1 as u64))186 }187 // Storage: Common CollectionPropertyPermissions (r:1 w:0)188 // Storage: Nonfungible TokenProperties (r:1 w:1)189 fn set_token_properties(b: u32, ) -> Weight {190 Weight::from_ref_time(4_361_000 as u64)191 // Standard Error: 5_349_868192 .saturating_add(Weight::from_ref_time(637_246_356 as u64).saturating_mul(b as u64))193 .saturating_add(T::DbWeight::get().reads(2 as u64))194 .saturating_add(T::DbWeight::get().writes(1 as u64))195 }196 // Storage: Common CollectionPropertyPermissions (r:1 w:0)197 // Storage: Nonfungible TokenProperties (r:1 w:1)198 fn delete_token_properties(b: u32, ) -> Weight {199 Weight::from_ref_time(4_489_000 as u64)200 // Standard Error: 5_738_954201 .saturating_add(Weight::from_ref_time(689_912_822 as u64).saturating_mul(b as u64))202 .saturating_add(T::DbWeight::get().reads(2 as u64))203 .saturating_add(T::DbWeight::get().writes(1 as u64))204 }205 // Storage: Nonfungible TokenData (r:1 w:0)206 fn token_owner() -> Weight {207 Weight::from_ref_time(6_881_000 as u64)208 .saturating_add(T::DbWeight::get().reads(1 as u64))209 }210 // Storage: Nonfungible CollectionAllowance (r:0 w:1)211 fn set_allowance_for_all() -> Weight {212 Weight::from_ref_time(16_223_000 as u64)213 .saturating_add(T::DbWeight::get().writes(1 as u64))214 }215 // Storage: Nonfungible CollectionAllowance (r:1 w:0)216 fn allowance_for_all() -> Weight {217 Weight::from_ref_time(5_639_000 as u64)218 .saturating_add(T::DbWeight::get().reads(1 as u64))219 }220 // Storage: Nonfungible TokenProperties (r:1 w:1)221 fn repair_item() -> Weight {222 Weight::from_ref_time(6_111_000 as u64)223 .saturating_add(T::DbWeight::get().reads(1 as u64))224 .saturating_add(T::DbWeight::get().writes(1 as u64))225 }226}227228// For backwards compatibility and tests229impl WeightInfo for () {230 // Storage: Nonfungible TokensMinted (r:1 w:1)231 // Storage: Nonfungible AccountBalance (r:1 w:1)232 // Storage: Nonfungible TokenData (r:0 w:1)233 // Storage: Nonfungible Owned (r:0 w:1)234 fn create_item() -> Weight {235 Weight::from_ref_time(26_377_000 as u64)236 .saturating_add(RocksDbWeight::get().reads(2 as u64))237 .saturating_add(RocksDbWeight::get().writes(4 as u64))238 }239 // Storage: Nonfungible TokensMinted (r:1 w:1)240 // Storage: Nonfungible AccountBalance (r:1 w:1)241 // Storage: Nonfungible TokenData (r:0 w:4)242 // Storage: Nonfungible Owned (r:0 w:4)243 fn create_multiple_items(b: u32, ) -> Weight {244 Weight::from_ref_time(20_059_186 as u64)245 // Standard Error: 4_735246 .saturating_add(Weight::from_ref_time(4_856_306 as u64).saturating_mul(b as u64))247 .saturating_add(RocksDbWeight::get().reads(2 as u64))248 .saturating_add(RocksDbWeight::get().writes(2 as u64))249 .saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(b as u64)))250 }251 // Storage: Nonfungible TokensMinted (r:1 w:1)252 // Storage: Nonfungible AccountBalance (r:4 w:4)253 // Storage: Nonfungible TokenData (r:0 w:4)254 // Storage: Nonfungible Owned (r:0 w:4)255 fn create_multiple_items_ex(b: u32, ) -> Weight {256 Weight::from_ref_time(16_365_581 as u64)257 // Standard Error: 9_711258 .saturating_add(Weight::from_ref_time(6_681_940 as u64).saturating_mul(b as u64))259 .saturating_add(RocksDbWeight::get().reads(1 as u64))260 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))261 .saturating_add(RocksDbWeight::get().writes(1 as u64))262 .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64)))263 }264 // Storage: Nonfungible TokenData (r:1 w:1)265 // Storage: Nonfungible TokenChildren (r:1 w:0)266 // Storage: Nonfungible TokensBurnt (r:1 w:1)267 // Storage: Nonfungible AccountBalance (r:1 w:1)268 // Storage: Nonfungible Allowance (r:1 w:0)269 // Storage: Nonfungible Owned (r:0 w:1)270 // Storage: Nonfungible TokenProperties (r:0 w:1)271 fn burn_item() -> Weight {272 Weight::from_ref_time(33_502_000 as u64)273 .saturating_add(RocksDbWeight::get().reads(5 as u64))274 .saturating_add(RocksDbWeight::get().writes(5 as u64))275 }276 // Storage: Nonfungible TokenChildren (r:1 w:0)277 // Storage: Nonfungible TokenData (r:1 w:1)278 // Storage: Nonfungible TokensBurnt (r:1 w:1)279 // Storage: Nonfungible AccountBalance (r:1 w:1)280 // Storage: Nonfungible Allowance (r:1 w:0)281 // Storage: Nonfungible Owned (r:0 w:1)282 // Storage: Nonfungible TokenProperties (r:0 w:1)283 fn burn_recursively_self_raw() -> Weight {284 Weight::from_ref_time(43_255_000 as u64)285 .saturating_add(RocksDbWeight::get().reads(5 as u64))286 .saturating_add(RocksDbWeight::get().writes(5 as u64))287 }288 // Storage: Nonfungible TokenChildren (r:1 w:0)289 // Storage: Nonfungible TokenData (r:1 w:1)290 // Storage: Nonfungible TokensBurnt (r:1 w:1)291 // Storage: Nonfungible AccountBalance (r:1 w:1)292 // Storage: Nonfungible Allowance (r:1 w:0)293 // Storage: Nonfungible Owned (r:0 w:1)294 // Storage: Nonfungible TokenProperties (r:0 w:1)295 // Storage: Common CollectionById (r:1 w:0)296 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {297 Weight::from_ref_time(42_992_000 as u64)298 // Standard Error: 1_010_119299 .saturating_add(Weight::from_ref_time(209_972_755 as u64).saturating_mul(b as u64))300 .saturating_add(RocksDbWeight::get().reads(7 as u64))301 .saturating_add(RocksDbWeight::get().reads((4 as u64).saturating_mul(b as u64)))302 .saturating_add(RocksDbWeight::get().writes(6 as u64))303 .saturating_add(RocksDbWeight::get().writes((4 as u64).saturating_mul(b as u64)))304 }305 // Storage: Nonfungible TokenData (r:1 w:1)306 // Storage: Nonfungible AccountBalance (r:2 w:2)307 // Storage: Nonfungible Allowance (r:1 w:0)308 // Storage: Nonfungible Owned (r:0 w:2)309 fn transfer() -> Weight {310 Weight::from_ref_time(31_239_000 as u64)311 .saturating_add(RocksDbWeight::get().reads(4 as u64))312 .saturating_add(RocksDbWeight::get().writes(5 as u64))313 }314 // Storage: Nonfungible TokenData (r:1 w:0)315 // Storage: Nonfungible Allowance (r:1 w:1)316 fn approve() -> Weight {317 Weight::from_ref_time(21_985_000 as u64)318 .saturating_add(RocksDbWeight::get().reads(2 as u64))319 .saturating_add(RocksDbWeight::get().writes(1 as u64))320 }321 // Storage: Nonfungible TokenData (r:1 w:0)322 // Storage: Nonfungible Allowance (r:1 w:1)323 fn approve_from() -> Weight {324 Weight::from_ref_time(18_965_000 as u64)325 .saturating_add(RocksDbWeight::get().reads(2 as u64))326 .saturating_add(RocksDbWeight::get().writes(1 as u64))327 }328 // Storage: Nonfungible Allowance (r:1 w:1)329 // Storage: Nonfungible TokenData (r:1 w:1)330 // Storage: Nonfungible AccountBalance (r:2 w:2)331 // Storage: Nonfungible Owned (r:0 w:2)332 fn transfer_from() -> Weight {333 Weight::from_ref_time(36_382_000 as u64)334 .saturating_add(RocksDbWeight::get().reads(4 as u64))335 .saturating_add(RocksDbWeight::get().writes(6 as u64))336 }337 // Storage: Nonfungible Allowance (r:1 w:1)338 // Storage: Nonfungible TokenData (r:1 w:1)339 // Storage: Nonfungible TokenChildren (r:1 w:0)340 // Storage: Nonfungible TokensBurnt (r:1 w:1)341 // Storage: Nonfungible AccountBalance (r:1 w:1)342 // Storage: Nonfungible Owned (r:0 w:1)343 // Storage: Nonfungible TokenProperties (r:0 w:1)344 fn burn_from() -> Weight {345 Weight::from_ref_time(42_046_000 as u64)346 .saturating_add(RocksDbWeight::get().reads(5 as u64))347 .saturating_add(RocksDbWeight::get().writes(6 as u64))348 }349 // Storage: Common CollectionPropertyPermissions (r:1 w:1)350 fn set_token_property_permissions(b: u32, ) -> Weight {351 Weight::from_ref_time(5_543_000 as u64)352 // Standard Error: 40_525353 .saturating_add(Weight::from_ref_time(12_126_787 as u64).saturating_mul(b as u64))354 .saturating_add(RocksDbWeight::get().reads(1 as u64))355 .saturating_add(RocksDbWeight::get().writes(1 as u64))356 }357 // Storage: Common CollectionPropertyPermissions (r:1 w:0)358 // Storage: Nonfungible TokenProperties (r:1 w:1)359 fn set_token_properties(b: u32, ) -> Weight {360 Weight::from_ref_time(4_361_000 as u64)361 // Standard Error: 5_349_868362 .saturating_add(Weight::from_ref_time(637_246_356 as u64).saturating_mul(b as u64))363 .saturating_add(RocksDbWeight::get().reads(2 as u64))364 .saturating_add(RocksDbWeight::get().writes(1 as u64))365 }366 // Storage: Common CollectionPropertyPermissions (r:1 w:0)367 // Storage: Nonfungible TokenProperties (r:1 w:1)368 fn delete_token_properties(b: u32, ) -> Weight {369 Weight::from_ref_time(4_489_000 as u64)370 // Standard Error: 5_738_954371 .saturating_add(Weight::from_ref_time(689_912_822 as u64).saturating_mul(b as u64))372 .saturating_add(RocksDbWeight::get().reads(2 as u64))373 .saturating_add(RocksDbWeight::get().writes(1 as u64))374 }375 // Storage: Nonfungible TokenData (r:1 w:0)376 fn token_owner() -> Weight {377 Weight::from_ref_time(6_881_000 as u64)378 .saturating_add(RocksDbWeight::get().reads(1 as u64))379 }380 // Storage: Nonfungible CollectionAllowance (r:0 w:1)381 fn set_allowance_for_all() -> Weight {382 Weight::from_ref_time(16_223_000 as u64)383 .saturating_add(RocksDbWeight::get().writes(1 as u64))384 }385 // Storage: Nonfungible CollectionAllowance (r:1 w:0)386 fn allowance_for_all() -> Weight {387 Weight::from_ref_time(5_639_000 as u64)388 .saturating_add(RocksDbWeight::get().reads(1 as u64))389 }390 // Storage: Nonfungible TokenProperties (r:1 w:1)391 fn repair_item() -> Weight {392 Weight::from_ref_time(6_111_000 as u64)393 .saturating_add(RocksDbWeight::get().reads(1 as u64))394 .saturating_add(RocksDbWeight::get().writes(1 as u64))395 }396}pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -515,12 +515,29 @@
Ok(())
}
+ /// A batch operation to add, edit or remove properties for a token.
+ /// It sets or removes a token's properties according to
+ /// `properties_updates` contents:
+ /// * sets a property under the <key> with the value provided `(<key>, Some(<value>))`
+ /// * removes a property under the <key> if the value is `None` `(<key>, None)`.
+ ///
+ /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
+ /// - `is_token_create`: Indicates that method is called during token initialization.
+ /// Allows to bypass ownership check.
+ ///
+ /// All affected properties should have `mutable` permission
+ /// to be **deleted** or to be **set more than once**,
+ /// and the sender should have permission to edit those properties.
+ ///
+ /// This function fires an event for each property change.
+ /// In case of an error, all the changes (including the events) will be reverted
+ /// since the function is transactional.
#[transactional]
fn modify_token_properties(
collection: &RefungibleHandle<T>,
sender: &T::CrossAccountId,
token_id: TokenId,
- properties: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
+ properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
is_token_create: bool,
nesting_budget: &dyn Budget,
) -> DispatchResult {
@@ -544,15 +561,16 @@
Ok(is_bundle_owner)
};
- for (key, value) in properties {
- let permission = <PalletCommon<T>>::property_permissions(collection.id)
+ let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
+ let permissions = <PalletCommon<T>>::property_permissions(collection.id);
+
+ for (key, value) in properties_updates {
+ let permission = permissions
.get(&key)
.cloned()
.unwrap_or_else(PropertyPermission::none);
- let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
- .get(&key)
- .is_some();
+ let is_property_exists = stored_properties.get(&key).is_some();
match permission {
PropertyPermission { mutable: false, .. } if is_property_exists => {
@@ -578,10 +596,9 @@
match value {
Some(value) => {
- <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.try_set(key.clone(), value)
- })
- .map_err(<CommonError<T>>::from)?;
+ stored_properties
+ .try_set(key.clone(), value)
+ .map_err(<CommonError<T>>::from)?;
<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
collection.id,
@@ -590,10 +607,9 @@
));
}
None => {
- <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.remove(&key)
- })
- .map_err(<CommonError<T>>::from)?;
+ stored_properties
+ .remove(&key)
+ .map_err(<CommonError<T>>::from)?;
<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
collection.id,
@@ -612,6 +628,8 @@
);
}
+ <TokenProperties<T>>::set((collection.id, token_id), stored_properties);
+
Ok(())
}
@@ -1353,7 +1371,7 @@
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
- <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
}
pub fn delete_collection_properties(
@@ -1361,7 +1379,11 @@
sender: &T::CrossAccountId,
property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ <PalletCommon<T>>::delete_collection_properties(
+ collection,
+ sender,
+ property_keys.into_iter(),
+ )
}
pub fn set_token_property_permissions(
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -246,21 +246,21 @@
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
+ // Storage: Refungible TokenProperties (r:1 w:1)
// Storage: Common CollectionPropertyPermissions (r:1 w:0)
- // Storage: Refungible TokenProperties (r:1 w:1)
fn set_token_properties(b: u32, ) -> Weight {
- Weight::from_ref_time(4_578_000 as u64)
- // Standard Error: 5_396_287
- .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))
+ Weight::from_ref_time(25_518_267 as u64)
+ // Standard Error: 20_451
+ .saturating_add(Weight::from_ref_time(5_041_089 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
+ // Storage: Refungible TokenProperties (r:1 w:1)
// Storage: Common CollectionPropertyPermissions (r:1 w:0)
- // Storage: Refungible TokenProperties (r:1 w:1)
fn delete_token_properties(b: u32, ) -> Weight {
- Weight::from_ref_time(4_583_000 as u64)
- // Standard Error: 5_762_380
- .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))
+ Weight::from_ref_time(13_715_000 as u64)
+ // Standard Error: 28_323
+ .saturating_add(Weight::from_ref_time(13_113_351 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
@@ -478,21 +478,21 @@
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
+ // Storage: Refungible TokenProperties (r:1 w:1)
// Storage: Common CollectionPropertyPermissions (r:1 w:0)
- // Storage: Refungible TokenProperties (r:1 w:1)
fn set_token_properties(b: u32, ) -> Weight {
- Weight::from_ref_time(4_578_000 as u64)
- // Standard Error: 5_396_287
- .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))
+ Weight::from_ref_time(25_518_267 as u64)
+ // Standard Error: 20_451
+ .saturating_add(Weight::from_ref_time(5_041_089 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
+ // Storage: Refungible TokenProperties (r:1 w:1)
// Storage: Common CollectionPropertyPermissions (r:1 w:0)
- // Storage: Refungible TokenProperties (r:1 w:1)
fn delete_token_properties(b: u32, ) -> Weight {
- Weight::from_ref_time(4_583_000 as u64)
- // Standard Error: 5_762_380
- .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))
+ Weight::from_ref_time(13_715_000 as u64)
+ // Standard Error: 28_323
+ .saturating_add(Weight::from_ref_time(13_113_351 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -33,7 +33,6 @@
};
use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
-use sp_std::vec;
use up_data_structs::{
CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
CreateCollectionData,
@@ -316,13 +315,14 @@
<PalletCommon<T>>::set_collection_properties(
&collection,
&caller,
- vec![up_data_structs::Property {
+ [up_data_structs::Property {
key: key::base_uri(),
value: base_uri
.into_bytes()
.try_into()
.map_err(|_| "base uri is too large")?,
- }],
+ }]
+ .into_iter(),
)
.map_err(dispatch_to_evm::<T>)?;
}
runtime/common/identity.rsdiffbeforeafterboth--- a/runtime/common/identity.rs
+++ b/runtime/common/identity.rs
@@ -24,6 +24,9 @@
transaction_validity::{TransactionValidity, ValidTransaction, TransactionValidityError},
};
+#[cfg(feature = "collator-selection")]
+use sp_runtime::transaction_validity::InvalidTransaction;
+
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct DisableIdentityCalls;
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -651,6 +651,9 @@
try {
result = await this.signTransaction(sender, this.constructApiCall(extrinsic, params), options, extrinsic) as ITransactionResult;
events = this.eventHelper.extractEvents(result.result.events);
+ const errorEvent = events.find((event) => event.method == 'ExecutedFailed' || event.method == 'CreatedFailed');
+ if (errorEvent)
+ throw Error(errorEvent.method + ': ' + extrinsic);
}
catch(e) {
if(!(e as object).hasOwnProperty('status')) throw e;