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

difftreelog

refactor move erc721metadata to flags

Yaroslav Bolyukin2022-10-13parent: #d4f43b6.patch.diff
in: master

6 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -706,9 +706,6 @@
 		/// Value "ERC721Metadata".
 		pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
 
-		/// Value "1" ERC721 metadata supported.
-		pub const ERC721_METADATA_SUPPORTED: &[u8] = b"1";
-
 		/// Value for [`ERC721_METADATA`].
 		pub fn erc721() -> up_data_structs::PropertyValue {
 			property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
@@ -717,11 +714,6 @@
 		/// Value for [`SCHEMA_VERSION`].
 		pub fn schema_version() -> up_data_structs::PropertyValue {
 			property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)
-		}
-
-		/// Value for [`ERC721_METADATA_SUPPORTED`].
-		pub fn erc721_metadata_supported() -> up_data_structs::PropertyValue {
-			property_value_from_bytes(ERC721_METADATA_SUPPORTED).expect(EXPECT_CONVERT_ERROR)
 		}
 	}
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -71,6 +71,7 @@
 	Collection,
 	RpcCollection,
 	CollectionFlags,
+	RpcCollectionFlags,
 	CollectionId,
 	CreateItemData,
 	MAX_TOKEN_PREFIX_LENGTH,
@@ -824,7 +825,11 @@
 			token_property_permissions,
 			properties,
 			read_only: flags.external,
-			foreign: flags.foreign,
+
+			flags: RpcCollectionFlags {
+				foreign: flags.foreign,
+				erc721metadata: flags.erc721metadata,
+			},
 		})
 	}
 }
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -708,22 +708,6 @@
 	}
 }
 
-impl<T: Config> NonfungibleHandle<T> {
-	pub fn supports_metadata(&self) -> bool {
-		let has_metadata_support_enabled = if let Some(erc721_metadata) =
-			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
-		{
-			*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
-		} else {
-			false
-		};
-
-		let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
-
-		has_metadata_support_enabled && has_url_property_permissions
-	}
-}
-
 #[solidity_interface(
 	name = UniqueNFT,
 	is(
@@ -732,9 +716,9 @@
 		ERC721UniqueExtensions,
 		ERC721Mintable,
 		ERC721Burnable,
+		ERC721Metadata(if(this.flags.erc721metadata)),
 		Collection(via(common_mut returns CollectionHandle<T>)),
 		TokenProperties,
-		ERC721Metadata(if(this.supports_metadata())),
 	)
 )]
 impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -764,22 +764,6 @@
 	}
 }
 
-impl<T: Config> RefungibleHandle<T> {
-	pub fn supports_metadata(&self) -> bool {
-		let has_metadata_support_enabled = if let Some(erc721_metadata) =
-			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
-		{
-			*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
-		} else {
-			false
-		};
-
-		let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
-
-		has_metadata_support_enabled && has_url_property_permissions
-	}
-}
-
 #[solidity_interface(
 	name = UniqueRefungible,
 	is(
@@ -788,9 +772,9 @@
 		ERC721UniqueExtensions,
 		ERC721Mintable,
 		ERC721Burnable,
+		ERC721Metadata(if(this.flags.erc721metadata)),
 		Collection(via(common_mut returns CollectionHandle<T>)),
 		TokenProperties,
-		ERC721Metadata(if(this.supports_metadata())),
 	)
 )]
 impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -89,6 +89,26 @@
 	Ok((caller, name, description, token_prefix, base_uri_value))
 }
 
+fn default_url_pkp() -> up_data_structs::PropertyKeyPermission {
+	up_data_structs::PropertyKeyPermission {
+		key: key::url(),
+		permission: up_data_structs::PropertyPermission {
+			mutable: true,
+			collection_admin: true,
+			token_owner: false,
+		},
+	}
+}
+fn default_suffix_pkp() -> up_data_structs::PropertyKeyPermission {
+	up_data_structs::PropertyKeyPermission {
+		key: key::suffix(),
+		permission: up_data_structs::PropertyPermission {
+			mutable: true,
+			collection_admin: true,
+			token_owner: false,
+		},
+	}
+}
 fn make_data<T: Config>(
 	name: CollectionName,
 	mode: CollectionMode,
@@ -98,26 +118,9 @@
 	add_properties: bool,
 ) -> Result<CreateCollectionData<T::AccountId>> {
 	let token_property_permissions = if add_properties {
-		vec![
-			up_data_structs::PropertyKeyPermission {
-				key: key::url(),
-				permission: up_data_structs::PropertyPermission {
-					mutable: true,
-					collection_admin: true,
-					token_owner: false,
-				},
-			},
-			up_data_structs::PropertyKeyPermission {
-				key: key::suffix(),
-				permission: up_data_structs::PropertyPermission {
-					mutable: true,
-					collection_admin: true,
-					token_owner: false,
-				},
-			},
-		]
-		.try_into()
-		.map_err(|e| Error::Revert(format!("{:?}", e)))?
+		vec![default_url_pkp(), default_suffix_pkp()]
+			.try_into()
+			.map_err(|e| Error::Revert(format!("{:?}", e)))?
 	} else {
 		up_data_structs::CollectionPropertiesPermissionsVec::default()
 	};
@@ -130,10 +133,6 @@
 			up_data_structs::Property {
 				key: key::schema_version(),
 				value: property_value::schema_version(),
-			},
-			up_data_structs::Property {
-				key: key::erc721_metadata(),
-				value: property_value::erc721_metadata_supported(),
 			},
 		];
 		if !base_uri_value.is_empty() {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
365 /// Tokens in foreign collections can be transferred, but not burnt365 /// Tokens in foreign collections can be transferred, but not burnt
366 #[bondrewd(bits = "0..1")]366 #[bondrewd(bits = "0..1")]
367 pub foreign: bool,367 pub foreign: bool,
368 /// Supports ERC721Metadata
369 #[bondrewd(bits = "1..2")]
370 pub erc721metadata: bool,
368 /// External collections can't be managed using `unique` api371 /// External collections can't be managed using `unique` api
369 #[bondrewd(bits = "7..8")]372 #[bondrewd(bits = "7..8")]
370 pub external: bool,373 pub external: bool,
371374
372 #[bondrewd(reserve, bits = "1..7")]375 #[bondrewd(reserve, bits = "2..7")]
373 pub reserved: u8,376 pub reserved: u8,
374}377}
375bondrewd_codec!(CollectionFlags);378bondrewd_codec!(CollectionFlags);
434 pub meta_update_permission: MetaUpdatePermission,437 pub meta_update_permission: MetaUpdatePermission,
435}438}
439
440#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
441#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
442pub struct RpcCollectionFlags {
443 /// Is collection is foreign.
444 pub foreign: bool,
445 /// Collection supports ERC721Metadata.
446 pub erc721metadata: bool,
447}
436448
437/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version).449/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version).
438#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]450#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
471 /// Is collection read only.483 /// Is collection read only.
472 pub read_only: bool,484 pub read_only: bool,
473485
474 /// Is collection is foreign.486 /// Extra collection flags
475 pub foreign: bool,487 pub flags: RpcCollectionFlags,
476}488}
477489
478/// Data used for create collection.490/// Data used for create collection.