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
706 /// Value "ERC721Metadata".706 /// Value "ERC721Metadata".
707 pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";707 pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
708
709 /// Value "1" ERC721 metadata supported.
710 pub const ERC721_METADATA_SUPPORTED: &[u8] = b"1";
711708
712 /// Value for [`ERC721_METADATA`].709 /// Value for [`ERC721_METADATA`].
713 pub fn erc721() -> up_data_structs::PropertyValue {710 pub fn erc721() -> up_data_structs::PropertyValue {
719 property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)716 property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)
720 }717 }
721
722 /// Value for [`ERC721_METADATA_SUPPORTED`].
723 pub fn erc721_metadata_supported() -> up_data_structs::PropertyValue {
724 property_value_from_bytes(ERC721_METADATA_SUPPORTED).expect(EXPECT_CONVERT_ERROR)
725 }
726 }718 }
727719
728 /// Convert `byte` to [`PropertyKey`].720 /// Convert `byte` to [`PropertyKey`].
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
71 Collection,71 Collection,
72 RpcCollection,72 RpcCollection,
73 CollectionFlags,73 CollectionFlags,
74 RpcCollectionFlags,
74 CollectionId,75 CollectionId,
75 CreateItemData,76 CreateItemData,
76 MAX_TOKEN_PREFIX_LENGTH,77 MAX_TOKEN_PREFIX_LENGTH,
825 properties,826 properties,
826 read_only: flags.external,827 read_only: flags.external,
828
829 flags: RpcCollectionFlags {
827 foreign: flags.foreign,830 foreign: flags.foreign,
831 erc721metadata: flags.erc721metadata,
832 },
828 })833 })
829 }834 }
830}835}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
708 }708 }
709}709}
710
711impl<T: Config> NonfungibleHandle<T> {
712 pub fn supports_metadata(&self) -> bool {
713 let has_metadata_support_enabled = if let Some(erc721_metadata) =
714 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
715 {
716 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
717 } else {
718 false
719 };
720
721 let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
722
723 has_metadata_support_enabled && has_url_property_permissions
724 }
725}
726710
727#[solidity_interface(711#[solidity_interface(
728 name = UniqueNFT,712 name = UniqueNFT,
732 ERC721UniqueExtensions,716 ERC721UniqueExtensions,
733 ERC721Mintable,717 ERC721Mintable,
734 ERC721Burnable,718 ERC721Burnable,
719 ERC721Metadata(if(this.flags.erc721metadata)),
735 Collection(via(common_mut returns CollectionHandle<T>)),720 Collection(via(common_mut returns CollectionHandle<T>)),
736 TokenProperties,721 TokenProperties,
737 ERC721Metadata(if(this.supports_metadata())),
738 )722 )
739)]723)]
740impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}724impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
764 }764 }
765}765}
766
767impl<T: Config> RefungibleHandle<T> {
768 pub fn supports_metadata(&self) -> bool {
769 let has_metadata_support_enabled = if let Some(erc721_metadata) =
770 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
771 {
772 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
773 } else {
774 false
775 };
776
777 let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
778
779 has_metadata_support_enabled && has_url_property_permissions
780 }
781}
782766
783#[solidity_interface(767#[solidity_interface(
784 name = UniqueRefungible,768 name = UniqueRefungible,
788 ERC721UniqueExtensions,772 ERC721UniqueExtensions,
789 ERC721Mintable,773 ERC721Mintable,
790 ERC721Burnable,774 ERC721Burnable,
775 ERC721Metadata(if(this.flags.erc721metadata)),
791 Collection(via(common_mut returns CollectionHandle<T>)),776 Collection(via(common_mut returns CollectionHandle<T>)),
792 TokenProperties,777 TokenProperties,
793 ERC721Metadata(if(this.supports_metadata())),
794 )778 )
795)]779)]
796impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}780impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
89 Ok((caller, name, description, token_prefix, base_uri_value))89 Ok((caller, name, description, token_prefix, base_uri_value))
90}90}
9191
92fn default_url_pkp() -> up_data_structs::PropertyKeyPermission {
93 up_data_structs::PropertyKeyPermission {
94 key: key::url(),
95 permission: up_data_structs::PropertyPermission {
96 mutable: true,
97 collection_admin: true,
98 token_owner: false,
99 },
100 }
101}
102fn default_suffix_pkp() -> up_data_structs::PropertyKeyPermission {
103 up_data_structs::PropertyKeyPermission {
104 key: key::suffix(),
105 permission: up_data_structs::PropertyPermission {
106 mutable: true,
107 collection_admin: true,
108 token_owner: false,
109 },
110 }
111}
92fn make_data<T: Config>(112fn make_data<T: Config>(
93 name: CollectionName,113 name: CollectionName,
94 mode: CollectionMode,114 mode: CollectionMode,
98 add_properties: bool,118 add_properties: bool,
99) -> Result<CreateCollectionData<T::AccountId>> {119) -> Result<CreateCollectionData<T::AccountId>> {
100 let token_property_permissions = if add_properties {120 let token_property_permissions = if add_properties {
101 vec![121 vec![default_url_pkp(), default_suffix_pkp()]
102 up_data_structs::PropertyKeyPermission {
103 key: key::url(),
104 permission: up_data_structs::PropertyPermission {
131 key: key::schema_version(),134 key: key::schema_version(),
132 value: property_value::schema_version(),135 value: property_value::schema_version(),
133 },136 },
134 up_data_structs::Property {
135 key: key::erc721_metadata(),
136 value: property_value::erc721_metadata_supported(),
137 },
138 ];137 ];
139 if !base_uri_value.is_empty() {138 if !base_uri_value.is_empty() {
140 properties.push(up_data_structs::Property {139 properties.push(up_data_structs::Property {
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.