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

difftreelog

fix bulk properties set

Daniel Shiposha2023-01-12parent: #46515fa.patch.diff
in: master

6 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
125 .map(eth::Property::try_into)125 .map(eth::Property::try_into)
126 .collect::<Result<Vec<_>>>()?;126 .collect::<Result<Vec<_>>>()?;
127127
128 <Pallet<T>>::set_collection_properties(self, &caller, properties)128 <Pallet<T>>::set_collection_properties(self, &caller, properties.into_iter())
129 .map_err(dispatch_to_evm::<T>)129 .map_err(dispatch_to_evm::<T>)
130 }130 }
131131
158 })158 })
159 .collect::<Result<Vec<_>>>()?;159 .collect::<Result<Vec<_>>>()?;
160160
161 <Pallet<T>>::delete_collection_properties(self, &caller, keys).map_err(dispatch_to_evm::<T>)161 <Pallet<T>>::delete_collection_properties(self, &caller, keys.into_iter())
162 .map_err(dispatch_to_evm::<T>)
162 }163 }
163164
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1198 Ok(())1198 Ok(())
1199 }1199 }
12001200
1201 /// 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)?;
12121207
1213 CollectionProperties::<T>::try_mutate(collection.id, |properties| {1208 let mut stored_properties = <CollectionProperties<T>>::get(collection.id);
1214 let property = property.clone();1209
1215 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_properties
1214 .try_set(key.clone(), value)
1219 Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));1215 .map_err(<Error<T>>::from)?;
1216
1217 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)?;
1227
1228 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 }
1238
1239 <CollectionProperties<T>>::mutate(collection.id, |properties| {
1240 *properties = stored_properties;
1241 });
12261242
1227 Ok(())1243 Ok(())
1228 }1244 }
1245
1246 /// 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 }
12291258
1230 /// Set a scoped collection property, where the scope is a special prefix1259 /// Set a scoped collection property, where the scope is a special prefix
1231 /// 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 }
12851314
1293 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)?;
1297
1298 CollectionProperties::<T>::try_mutate(collection.id, |properties| {
1299 properties.remove(&property_key)
1300 })
1301 .map_err(<Error<T>>::from)?;
1302
1303 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 );
1313
1314 Ok(())
1315 }1326 }
13161327
1317 /// 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 }
1331
1332 Ok(())
1333 }1340 }
13341341
1335 /// Set collection propetry permission without any checks.1342 /// Set collection propetry permission without any checks.
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
266 sender: &T::CrossAccountId,266 sender: &T::CrossAccountId,
267 properties: Vec<Property>,267 properties: Vec<Property>,
268 ) -> DispatchResult {268 ) -> DispatchResult {
269 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)269 <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
270 }270 }
271271
272 /// Delete properties of the collection, associated with the provided keys.272 /// Delete properties of the collection, associated with the provided keys.
278 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)278 <PalletCommon<T>>::delete_collection_properties(
279 collection,
280 sender,
281 property_keys.into_iter(),
282 )
279 }283 }
280284
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
590 collection: &NonfungibleHandle<T>,590 collection: &NonfungibleHandle<T>,
591 sender: &T::CrossAccountId,591 sender: &T::CrossAccountId,
592 token_id: TokenId,592 token_id: TokenId,
593 properties: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,593 properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
594 is_token_create: bool,594 is_token_create: bool,
595 nesting_budget: &dyn Budget,595 nesting_budget: &dyn Budget,
596 ) -> DispatchResult {596 ) -> DispatchResult {
614 })614 })
615 };615 };
616
617 let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
618 let permissions = <PalletCommon<T>>::property_permissions(collection.id);
616619
617 for (key, value) in properties {620 for (key, value) in properties_updates {
618 let permission = <PalletCommon<T>>::property_permissions(collection.id)621 let permission = permissions
619 .get(&key)622 .get(&key)
620 .cloned()623 .cloned()
621 .unwrap_or_else(PropertyPermission::none);624 .unwrap_or_else(PropertyPermission::none);
622625
623 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))626 let is_property_exists = stored_properties.get(&key).is_some();
624 .get(&key)
625 .is_some();
626627
649650
650 match value {651 match value {
651 Some(value) => {652 Some(value) => {
652 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {653 stored_properties
653 properties.try_set(key.clone(), value)654 .try_set(key.clone(), value)
654 })
655 .map_err(<CommonError<T>>::from)?;655 .map_err(<CommonError<T>>::from)?;
656656
657 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(657 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
661 ));661 ));
662 }662 }
663 None => {663 None => {
664 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {664 stored_properties
665 properties.remove(&key)665 .remove(&key)
666 })
667 .map_err(<CommonError<T>>::from)?;666 .map_err(<CommonError<T>>::from)?;
668667
669 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(668 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
683 );682 );
684 }683 }
684
685 <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
686 *properties = stored_properties;
687 });
685688
686 Ok(())689 Ok(())
687 }690 }
784 sender: &T::CrossAccountId,787 sender: &T::CrossAccountId,
785 properties: Vec<Property>,788 properties: Vec<Property>,
786 ) -> DispatchResult {789 ) -> DispatchResult {
787 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)790 <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
788 }791 }
789792
790 /// Remove properties from the collection793 /// Remove properties from the collection
796 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)799 <PalletCommon<T>>::delete_collection_properties(
800 collection,
801 sender,
802 property_keys.into_iter(),
803 )
797 }804 }
798805
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
520 collection: &RefungibleHandle<T>,520 collection: &RefungibleHandle<T>,
521 sender: &T::CrossAccountId,521 sender: &T::CrossAccountId,
522 token_id: TokenId,522 token_id: TokenId,
523 properties: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,523 properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
524 is_token_create: bool,524 is_token_create: bool,
525 nesting_budget: &dyn Budget,525 nesting_budget: &dyn Budget,
526 ) -> DispatchResult {526 ) -> DispatchResult {
544 Ok(is_bundle_owner)544 Ok(is_bundle_owner)
545 };545 };
546
547 let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
548 let permissions = <PalletCommon<T>>::property_permissions(collection.id);
546549
547 for (key, value) in properties {550 for (key, value) in properties_updates {
548 let permission = <PalletCommon<T>>::property_permissions(collection.id)551 let permission = permissions
549 .get(&key)552 .get(&key)
550 .cloned()553 .cloned()
551 .unwrap_or_else(PropertyPermission::none);554 .unwrap_or_else(PropertyPermission::none);
552555
553 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))556 let is_property_exists = stored_properties.get(&key).is_some();
554 .get(&key)
555 .is_some();
556557
578579
579 match value {580 match value {
580 Some(value) => {581 Some(value) => {
581 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {582 stored_properties
582 properties.try_set(key.clone(), value)583 .try_set(key.clone(), value)
583 })
584 .map_err(<CommonError<T>>::from)?;584 .map_err(<CommonError<T>>::from)?;
585585
586 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(586 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
590 ));590 ));
591 }591 }
592 None => {592 None => {
593 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {593 stored_properties
594 properties.remove(&key)594 .remove(&key)
595 })
596 .map_err(<CommonError<T>>::from)?;595 .map_err(<CommonError<T>>::from)?;
597596
598 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(597 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
612 );611 );
613 }612 }
613
614 <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
615 *properties = stored_properties;
616 });
614617
615 Ok(())618 Ok(())
616 }619 }
1353 sender: &T::CrossAccountId,1356 sender: &T::CrossAccountId,
1354 properties: Vec<Property>,1357 properties: Vec<Property>,
1355 ) -> DispatchResult {1358 ) -> DispatchResult {
1356 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)1359 <PalletCommon<T>>::set_collection_properties(collection, sender, properties.into_iter())
1357 }1360 }
13581361
1359 pub fn delete_collection_properties(1362 pub fn delete_collection_properties(
1360 collection: &RefungibleHandle<T>,1363 collection: &RefungibleHandle<T>,
1361 sender: &T::CrossAccountId,1364 sender: &T::CrossAccountId,
1362 property_keys: Vec<PropertyKey>,1365 property_keys: Vec<PropertyKey>,
1363 ) -> DispatchResult {1366 ) -> DispatchResult {
1364 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)1367 <PalletCommon<T>>::delete_collection_properties(
1368 collection,
1369 sender,
1370 property_keys.into_iter(),
1371 )
1365 }1372 }
13661373
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
33};33};
34use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};34use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
35use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};35use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
36use sp_std::vec;
37use up_data_structs::{36use up_data_structs::{
38 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,37 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
39 CreateCollectionData,38 CreateCollectionData,
316 <PalletCommon<T>>::set_collection_properties(315 <PalletCommon<T>>::set_collection_properties(
317 &collection,316 &collection,
318 &caller,317 &caller,
319 vec![up_data_structs::Property {318 [up_data_structs::Property {
320 key: key::base_uri(),319 key: key::base_uri(),
321 value: base_uri320 value: base_uri
322 .into_bytes()321 .into_bytes()
323 .try_into()322 .try_into()
324 .map_err(|_| "base uri is too large")?,323 .map_err(|_| "base uri is too large")?,
325 }],324 }]
325 .into_iter(),
326 )326 )
327 .map_err(dispatch_to_evm::<T>)?;327 .map_err(dispatch_to_evm::<T>)?;
328 }328 }