git.delta.rocks / unique-network / refs/commits / 503c92cd6363

difftreelog

feat remove schemaName/schemaVersion

Yaroslav Bolyukin2022-10-14parent: #9d4aa0e.patch.diff
in: master

4 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
660 pub mod key {660 pub mod key {
661 use super::*;661 use super::*;
662
663 /// Key "schemaName".
664 pub fn schema_name() -> up_data_structs::PropertyKey {
665 property_key_from_bytes(b"schemaName").expect(EXPECT_CONVERT_ERROR)
666 }
667
668 /// Key "schemaVersion".
669 pub fn schema_version() -> up_data_structs::PropertyKey {
670 property_key_from_bytes(b"schemaVersion").expect(EXPECT_CONVERT_ERROR)
671 }
672662
673 /// Key "baseURI".663 /// Key "baseURI".
674 pub fn base_uri() -> up_data_structs::PropertyKey {664 pub fn base_uri() -> up_data_structs::PropertyKey {
690 property_key_from_bytes(b"parentNft").expect(EXPECT_CONVERT_ERROR)680 property_key_from_bytes(b"parentNft").expect(EXPECT_CONVERT_ERROR)
691 }681 }
692
693 /// Key "ERC721Metadata".
694 pub fn erc721_metadata() -> up_data_structs::PropertyKey {
695 property_key_from_bytes(b"ERC721Metadata").expect(EXPECT_CONVERT_ERROR)
696 }
697 }682 }
698
699 /// Values.
700 pub mod value {
701 use super::*;
702
703 /// Value "Schema version".
704 pub const SCHEMA_VERSION: &[u8] = b"1.0.0";
705
706 /// Value "ERC721Metadata".
707 pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
708
709 /// Value for [`ERC721_METADATA`].
710 pub fn erc721() -> up_data_structs::PropertyValue {
711 property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
712 }
713
714 /// Value for [`SCHEMA_VERSION`].
715 pub fn schema_version() -> up_data_structs::PropertyValue {
716 property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)
717 }
718 }
719683
720 /// Convert `byte` to [`PropertyKey`].684 /// Convert `byte` to [`PropertyKey`].
721 pub fn property_key_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyKey> {685 pub fn property_key_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyKey> {
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
34use sp_std::vec::Vec;34use sp_std::vec::Vec;
35use pallet_common::{35use pallet_common::{
36 erc::{36 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
37 CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key,
38 static_property::value,
39 },
40 CollectionHandle, CollectionPropertyPermissions,37 CollectionHandle, CollectionPropertyPermissions,
41};38};
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
29use frame_support::{BoundedBTreeMap, BoundedVec};29use frame_support::{BoundedBTreeMap, BoundedVec};
30use pallet_common::{30use pallet_common::{
31 CollectionHandle, CollectionPropertyPermissions,31 CollectionHandle, CollectionPropertyPermissions,
32 erc::{CommonEvmHandler, CollectionCall, static_property::key, static_property::value},32 erc::{CommonEvmHandler, CollectionCall, static_property::key},
33};33};
34use pallet_evm::{account::CrossAccountId, PrecompileHandle};34use pallet_evm::{account::CrossAccountId, PrecompileHandle};
35use pallet_evm_coder_substrate::{call, dispatch_to_evm};35use pallet_evm_coder_substrate::{call, dispatch_to_evm};
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
25 dispatch::CollectionDispatch,25 dispatch::CollectionDispatch,
26 erc::{26 erc::{
27 CollectionHelpersEvents,27 CollectionHelpersEvents,
28 static_property::{key, value as property_value},28 static_property::{key},
29 },29 },
30 Pallet as PalletCommon,30 Pallet as PalletCommon,
31};31};
125 } else {125 } else {
126 up_data_structs::CollectionPropertiesPermissionsVec::default()126 up_data_structs::CollectionPropertiesPermissionsVec::default()
127 };127 };
128 let properties = if add_properties {128 let properties = if add_properties && !base_uri_value.is_empty() {
129 let mut properties = vec![
130 up_data_structs::Property {
131 key: key::schema_name(),
132 value: property_value::erc721(),
133 },
134 up_data_structs::Property {
135 key: key::schema_version(),
136 value: property_value::schema_version(),
137 },
138 ];
139 if !base_uri_value.is_empty() {
140 properties.push(up_data_structs::Property {129 vec![up_data_structs::Property {
141 key: key::base_uri(),130 key: key::base_uri(),
142 value: base_uri_value,131 value: base_uri_value,
143 })132 }]
133 .try_into()
134 .expect("limit >= 1")
144 }135 } else {
145 properties
146 .try_into()
147 .map_err(|e| Error::Revert(format!("{:?}", e)))?
148 } else {
149 up_data_structs::CollectionPropertiesVec::default()136 up_data_structs::CollectionPropertiesVec::default()
150 };137 };
151138
404 }391 }
405392
406 let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);393 let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);
407 let mut new_properties = vec![];
408 if all_properties.get(&key::schema_name()).is_none() {394 if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {
409 self.recorder().consume_sstore()?;
410 new_properties.push(up_data_structs::Property {
411 key: key::schema_name(),
412 value: property_value::erc721(),
413 });
414 new_properties.push(up_data_structs::Property {
415 key: key::schema_version(),
416 value: property_value::schema_version(),
417 });
418 }
419 if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {
420 new_properties.push(up_data_structs::Property {
421 key: key::base_uri(),
422 value: base_uri
423 .into_bytes()
424 .try_into()
425 .map_err(|_| "base uri is too large")?,
426 });
427 }
428
429 if !new_properties.is_empty() {
430 self.recorder().consume_sstore()?;395 self.recorder().consume_sstore()?;
431 <PalletCommon<T>>::set_collection_properties(&collection, &caller, new_properties)396 <PalletCommon<T>>::set_collection_properties(
397 &collection,
398 &caller,
399 vec![up_data_structs::Property {
400 key: key::base_uri(),
401 value: base_uri
402 .into_bytes()
403 .try_into()
404 .map_err(|_| "base uri is too large")?,
405 }],
406 )
432 .map_err(dispatch_to_evm::<T>)?;407 .map_err(dispatch_to_evm::<T>)?;
433 }408 }