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
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -33,10 +33,7 @@
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_std::vec::Vec;
 use pallet_common::{
-	erc::{
-		CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key,
-		static_property::value,
-	},
+	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
 	CollectionHandle, CollectionPropertyPermissions,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -29,7 +29,7 @@
 use frame_support::{BoundedBTreeMap, BoundedVec};
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions,
-	erc::{CommonEvmHandler, CollectionCall, static_property::key, static_property::value},
+	erc::{CommonEvmHandler, CollectionCall, static_property::key},
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -25,7 +25,7 @@
 	dispatch::CollectionDispatch,
 	erc::{
 		CollectionHelpersEvents,
-		static_property::{key, value as property_value},
+		static_property::{key},
 	},
 	Pallet as PalletCommon,
 };
@@ -125,26 +125,13 @@
 	} else {
 		up_data_structs::CollectionPropertiesPermissionsVec::default()
 	};
-	let properties = if add_properties {
-		let mut properties = vec![
-			up_data_structs::Property {
-				key: key::schema_name(),
-				value: property_value::erc721(),
-			},
-			up_data_structs::Property {
-				key: key::schema_version(),
-				value: property_value::schema_version(),
-			},
-		];
-		if !base_uri_value.is_empty() {
-			properties.push(up_data_structs::Property {
-				key: key::base_uri(),
-				value: base_uri_value,
-			})
-		}
-		properties
-			.try_into()
-			.map_err(|e| Error::Revert(format!("{:?}", e)))?
+	let properties = if add_properties && !base_uri_value.is_empty() {
+		vec![up_data_structs::Property {
+			key: key::base_uri(),
+			value: base_uri_value,
+		}]
+		.try_into()
+		.expect("limit >= 1")
 	} else {
 		up_data_structs::CollectionPropertiesVec::default()
 	};
@@ -404,32 +391,20 @@
 		}
 
 		let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);
-		let mut new_properties = vec![];
-		if all_properties.get(&key::schema_name()).is_none() {
-			self.recorder().consume_sstore()?;
-			new_properties.push(up_data_structs::Property {
-				key: key::schema_name(),
-				value: property_value::erc721(),
-			});
-			new_properties.push(up_data_structs::Property {
-				key: key::schema_version(),
-				value: property_value::schema_version(),
-			});
-		}
 		if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {
-			new_properties.push(up_data_structs::Property {
-				key: key::base_uri(),
-				value: base_uri
-					.into_bytes()
-					.try_into()
-					.map_err(|_| "base uri is too large")?,
-			});
-		}
-
-		if !new_properties.is_empty() {
 			self.recorder().consume_sstore()?;
-			<PalletCommon<T>>::set_collection_properties(&collection, &caller, new_properties)
-				.map_err(dispatch_to_evm::<T>)?;
+			<PalletCommon<T>>::set_collection_properties(
+				&collection,
+				&caller,
+				vec![up_data_structs::Property {
+					key: key::base_uri(),
+					value: base_uri
+						.into_bytes()
+						.try_into()
+						.map_err(|_| "base uri is too large")?,
+				}],
+			)
+			.map_err(dispatch_to_evm::<T>)?;
 		}
 
 		self.recorder().consume_sstore()?;