difftreelog
fix bulk properties set
in: master
6 files changed
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.rsdiffbeforeafterboth1198 Ok(())1198 Ok(())1199 }1199 }120012001201 /// Set collection property.1202 ///1203 /// * `collection` - Collection handler.1204 /// * `sender` - The owner or administrator of the collection.1205 /// * `property` - The property to set.1206 pub fn set_collection_property(1201 fn modify_collection_properties(1207 collection: &CollectionHandle<T>,1202 collection: &CollectionHandle<T>,1208 sender: &T::CrossAccountId,1203 sender: &T::CrossAccountId,1209 property: Property,1204 properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,1210 ) -> DispatchResult {1205 ) -> DispatchResult {1211 collection.check_is_owner_or_admin(sender)?;1206 collection.check_is_owner_or_admin(sender)?;121212071213 CollectionProperties::<T>::try_mutate(collection.id, |properties| {1208 let mut stored_properties = <CollectionProperties<T>>::get(collection.id);1214 let property = property.clone();12091215 properties.try_set(property.key, property.value)1210 for (key, value) in properties_updates {1216 })1211 match value {1217 .map_err(<Error<T>>::from)?;1212 Some(value) => {12181213 stored_properties1214 .try_set(key.clone(), value)1219 Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));1215 .map_err(<Error<T>>::from)?;12161217 Self::deposit_event(Event::CollectionPropertySet(collection.id, key));1220 <PalletEvm<T>>::deposit_log(1218 <PalletEvm<T>>::deposit_log(1221 erc::CollectionHelpersEvents::CollectionChanged {1219 erc::CollectionHelpersEvents::CollectionChanged {1222 collection_id: eth::collection_id_to_address(collection.id),1220 collection_id: eth::collection_id_to_address(collection.id),1223 }1221 }1224 .to_log(T::ContractAddress::get()),1222 .to_log(T::ContractAddress::get()),1225 );1223 );1224 }1225 None => {1226 stored_properties.remove(&key).map_err(<Error<T>>::from)?;12271228 Self::deposit_event(Event::CollectionPropertyDeleted(collection.id, key));1229 <PalletEvm<T>>::deposit_log(1230 erc::CollectionHelpersEvents::CollectionChanged {1231 collection_id: eth::collection_id_to_address(collection.id),1232 }1233 .to_log(T::ContractAddress::get()),1234 );1235 }1236 }1237 }12381239 <CollectionProperties<T>>::mutate(collection.id, |properties| {1240 *properties = stored_properties;1241 });122612421227 Ok(())1243 Ok(())1228 }1244 }12451246 /// Set collection property.1247 ///1248 /// * `collection` - Collection handler.1249 /// * `sender` - The owner or administrator of the collection.1250 /// * `property` - The property to set.1251 pub fn set_collection_property(1252 collection: &CollectionHandle<T>,1253 sender: &T::CrossAccountId,1254 property: Property,1255 ) -> DispatchResult {1256 Self::set_collection_properties(collection, sender, [property].into_iter())1257 }122912581230 /// Set a scoped collection property, where the scope is a special prefix1259 /// Set a scoped collection property, where the scope is a special prefix1231 /// prohibiting a user access to change the property directly.1260 /// prohibiting a user access to change the property directly.1274 pub fn set_collection_properties(1303 pub fn set_collection_properties(1275 collection: &CollectionHandle<T>,1304 collection: &CollectionHandle<T>,1276 sender: &T::CrossAccountId,1305 sender: &T::CrossAccountId,1277 properties: Vec<Property>,1306 properties: impl Iterator<Item = Property>,1278 ) -> DispatchResult {1307 ) -> DispatchResult {1279 for property in properties {1280 Self::set_collection_property(collection, sender, property)?;1308 Self::modify_collection_properties(1281 }1309 collection,12821310 sender,1283 Ok(())1311 properties.map(|property| (property.key, Some(property.value))),1312 )1284 }1313 }128513141293 sender: &T::CrossAccountId,1322 sender: &T::CrossAccountId,1294 property_key: PropertyKey,1323 property_key: PropertyKey,1295 ) -> DispatchResult {1324 ) -> DispatchResult {1296 collection.check_is_owner_or_admin(sender)?;12971298 CollectionProperties::<T>::try_mutate(collection.id, |properties| {1299 properties.remove(&property_key)1300 })1301 .map_err(<Error<T>>::from)?;13021303 Self::deposit_event(Event::CollectionPropertyDeleted(1304 collection.id,1305 property_key,1306 ));1307 <PalletEvm<T>>::deposit_log(1325 Self::delete_collection_properties(collection, sender, [property_key].into_iter())1308 erc::CollectionHelpersEvents::CollectionChanged {1309 collection_id: eth::collection_id_to_address(collection.id),1310 }1311 .to_log(T::ContractAddress::get()),1312 );13131314 Ok(())1315 }1326 }131613271317 /// Delete collection properties.1328 /// Delete collection properties.1323 pub fn delete_collection_properties(1334 pub fn delete_collection_properties(1324 collection: &CollectionHandle<T>,1335 collection: &CollectionHandle<T>,1325 sender: &T::CrossAccountId,1336 sender: &T::CrossAccountId,1326 property_keys: Vec<PropertyKey>,1337 property_keys: impl Iterator<Item = PropertyKey>,1327 ) -> DispatchResult {1338 ) -> DispatchResult {1328 for key in property_keys {1329 Self::delete_collection_property(collection, sender, key)?;1339 Self::modify_collection_properties(collection, sender, property_keys.map(|key| (key, None)))1330 }13311332 Ok(())1333 }1340 }133413411335 /// Set collection propetry permission without any checks.1342 /// 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
@@ -590,7 +590,7 @@
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 +614,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 +650,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 +661,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 +682,10 @@
);
}
+ <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
+ *properties = stored_properties;
+ });
+
Ok(())
}
@@ -784,7 +787,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 +796,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/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -520,7 +520,7 @@
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 +544,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 +579,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 +590,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 +611,10 @@
);
}
+ <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
+ *properties = stored_properties;
+ });
+
Ok(())
}
@@ -1353,7 +1356,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 +1364,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/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>)?;
}