--- 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) } } --- 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, + }, }) } } --- a/pallets/nonfungible/src/erc.rs +++ b/pallets/nonfungible/src/erc.rs @@ -708,22 +708,6 @@ } } -impl NonfungibleHandle { - pub fn supports_metadata(&self) -> bool { - let has_metadata_support_enabled = if let Some(erc721_metadata) = - pallet_common::Pallet::::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::(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)), TokenProperties, - ERC721Metadata(if(this.supports_metadata())), ) )] impl NonfungibleHandle where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {} --- a/pallets/refungible/src/erc.rs +++ b/pallets/refungible/src/erc.rs @@ -764,22 +764,6 @@ } } -impl RefungibleHandle { - pub fn supports_metadata(&self) -> bool { - let has_metadata_support_enabled = if let Some(erc721_metadata) = - pallet_common::Pallet::::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::(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)), TokenProperties, - ERC721Metadata(if(this.supports_metadata())), ) )] impl RefungibleHandle where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {} --- 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( name: CollectionName, mode: CollectionMode, @@ -98,26 +118,9 @@ add_properties: bool, ) -> Result> { 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() { --- a/primitives/data-structs/src/lib.rs +++ b/primitives/data-structs/src/lib.rs @@ -365,11 +365,14 @@ /// Tokens in foreign collections can be transferred, but not burnt #[bondrewd(bits = "0..1")] pub foreign: bool, + /// Supports ERC721Metadata + #[bondrewd(bits = "1..2")] + pub erc721metadata: bool, /// External collections can't be managed using `unique` api #[bondrewd(bits = "7..8")] pub external: bool, - #[bondrewd(reserve, bits = "1..7")] + #[bondrewd(reserve, bits = "2..7")] pub reserved: u8, } bondrewd_codec!(CollectionFlags); @@ -434,6 +437,15 @@ pub meta_update_permission: MetaUpdatePermission, } +#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)] +#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] +pub struct RpcCollectionFlags { + /// Is collection is foreign. + pub foreign: bool, + /// Collection supports ERC721Metadata. + pub erc721metadata: bool, +} + /// Collection parameters, used in RPC calls (see [`Collection`] for the storage version). #[derive(Encode, Decode, Clone, PartialEq, TypeInfo)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] @@ -471,8 +483,8 @@ /// Is collection read only. pub read_only: bool, - /// Is collection is foreign. - pub foreign: bool, + /// Extra collection flags + pub flags: RpcCollectionFlags, } /// Data used for create collection.