difftreelog
refactor move erc721metadata to flags
in: master
6 files changed
pallets/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)
}
}
pallets/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,
+ },
})
}
}
pallets/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]> {}
pallets/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]> {}
pallets/unique/src/eth/mod.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use ethereum as _;21use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};22use frame_support::traits::Get;23use pallet_common::{24 CollectionById,25 dispatch::CollectionDispatch,26 erc::{27 CollectionHelpersEvents,28 static_property::{key, value as property_value},29 },30};31use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};33use sp_std::vec;34use up_data_structs::{35 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,36 CollectionMode, PropertyValue,37};3839use crate::{Config, SelfWeightOf, weights::WeightInfo};4041use sp_std::vec::Vec;42use alloc::format;4344/// See [`CollectionHelpersCall`]45pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);46impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {47 fn recorder(&self) -> &SubstrateRecorder<T> {48 &self.049 }5051 fn into_recorder(self) -> SubstrateRecorder<T> {52 self.053 }54}5556fn convert_data<T: Config>(57 caller: caller,58 name: string,59 description: string,60 token_prefix: string,61 base_uri: string,62) -> Result<(63 T::CrossAccountId,64 CollectionName,65 CollectionDescription,66 CollectionTokenPrefix,67 PropertyValue,68)> {69 let caller = T::CrossAccountId::from_eth(caller);70 let name = name71 .encode_utf16()72 .collect::<Vec<u16>>()73 .try_into()74 .map_err(|_| error_field_too_long(stringify!(name), CollectionName::bound()))?;75 let description = description76 .encode_utf16()77 .collect::<Vec<u16>>()78 .try_into()79 .map_err(|_| {80 error_field_too_long(stringify!(description), CollectionDescription::bound())81 })?;82 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {83 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())84 })?;85 let base_uri_value = base_uri86 .into_bytes()87 .try_into()88 .map_err(|_| error_field_too_long(stringify!(token_prefix), PropertyValue::bound()))?;89 Ok((caller, name, description, token_prefix, base_uri_value))90}9192fn make_data<T: Config>(93 name: CollectionName,94 mode: CollectionMode,95 description: CollectionDescription,96 token_prefix: CollectionTokenPrefix,97 base_uri_value: PropertyValue,98 add_properties: bool,99) -> Result<CreateCollectionData<T::AccountId>> {100 let token_property_permissions = if add_properties {101 vec![102 up_data_structs::PropertyKeyPermission {103 key: key::url(),104 permission: up_data_structs::PropertyPermission {105 mutable: true,106 collection_admin: true,107 token_owner: false,108 },109 },110 up_data_structs::PropertyKeyPermission {111 key: key::suffix(),112 permission: up_data_structs::PropertyPermission {113 mutable: true,114 collection_admin: true,115 token_owner: false,116 },117 },118 ]119 .try_into()120 .map_err(|e| Error::Revert(format!("{:?}", e)))?121 } else {122 up_data_structs::CollectionPropertiesPermissionsVec::default()123 };124 let properties = if add_properties {125 let mut properties = vec![126 up_data_structs::Property {127 key: key::schema_name(),128 value: property_value::erc721(),129 },130 up_data_structs::Property {131 key: key::schema_version(),132 value: property_value::schema_version(),133 },134 up_data_structs::Property {135 key: key::erc721_metadata(),136 value: property_value::erc721_metadata_supported(),137 },138 ];139 if !base_uri_value.is_empty() {140 properties.push(up_data_structs::Property {141 key: key::base_uri(),142 value: base_uri_value,143 })144 }145 properties146 .try_into()147 .map_err(|e| Error::Revert(format!("{:?}", e)))?148 } else {149 up_data_structs::CollectionPropertiesVec::default()150 };151152 let data = CreateCollectionData {153 name,154 mode,155 description,156 token_prefix,157 token_property_permissions,158 properties,159 ..Default::default()160 };161 Ok(data)162}163164fn create_refungible_collection_internal<165 T: Config + pallet_nonfungible::Config + pallet_refungible::Config,166>(167 caller: caller,168 value: value,169 name: string,170 description: string,171 token_prefix: string,172 base_uri: string,173 add_properties: bool,174) -> Result<address> {175 let (caller, name, description, token_prefix, base_uri_value) =176 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;177 let data = make_data::<T>(178 name,179 CollectionMode::ReFungible,180 description,181 token_prefix,182 base_uri_value,183 add_properties,184 )?;185 check_sent_amount_equals_collection_creation_price::<T>(value)?;186 let collection_helpers_address =187 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());188189 let collection_id =190 T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)191 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;192 let address = pallet_common::eth::collection_id_to_address(collection_id);193 Ok(address)194}195196fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {197 let value = value.as_u128();198 let creation_price: u128 = T::CollectionCreationPrice::get()199 .try_into()200 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait201 .expect("Collection creation price should be convertible to u128");202 if value != creation_price {203 return Err(format!(204 "Sent amount not equals to collection creation price ({0})",205 creation_price206 )207 .into());208 }209 Ok(())210}211212/// @title Contract, which allows users to operate with collections213#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]214impl<T> EvmCollectionHelpers<T>215where216 T: Config + pallet_common::Config + pallet_nonfungible::Config + pallet_refungible::Config,217{218 /// Create an NFT collection219 /// @param name Name of the collection220 /// @param description Informative description of the collection221 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications222 /// @return address Address of the newly created collection223 #[weight(<SelfWeightOf<T>>::create_collection())]224 #[solidity(rename_selector = "createNFTCollection")]225 fn create_nft_collection(226 &mut self,227 caller: caller,228 value: value,229 name: string,230 description: string,231 token_prefix: string,232 ) -> Result<address> {233 let (caller, name, description, token_prefix, _base_uri_value) =234 convert_data::<T>(caller, name, description, token_prefix, "".into())?;235 let data = make_data::<T>(236 name,237 CollectionMode::NFT,238 description,239 token_prefix,240 Default::default(),241 false,242 )?;243 check_sent_amount_equals_collection_creation_price::<T>(value)?;244 let collection_helpers_address =245 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());246 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)247 .map_err(dispatch_to_evm::<T>)?;248249 let address = pallet_common::eth::collection_id_to_address(collection_id);250 Ok(address)251 }252 /// Create an NFT collection253 /// @param name Name of the collection254 /// @param description Informative description of the collection255 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications256 /// @return address Address of the newly created collection257 #[weight(<SelfWeightOf<T>>::create_collection())]258 #[deprecated(note = "mathod was renamed to `create_nft_collection`, prefer it instead")]259 fn create_nonfungible_collection(260 &mut self,261 caller: caller,262 value: value,263 name: string,264 description: string,265 token_prefix: string,266 ) -> Result<address> {267 self.create_nft_collection(caller, value, name, description, token_prefix)268 }269270 #[weight(<SelfWeightOf<T>>::create_collection())]271 #[solidity(rename_selector = "createERC721MetadataCompatibleNFTCollection")]272 fn create_nonfungible_collection_with_properties(273 &mut self,274 caller: caller,275 value: value,276 name: string,277 description: string,278 token_prefix: string,279 base_uri: string,280 ) -> Result<address> {281 let (caller, name, description, token_prefix, base_uri_value) =282 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;283 let data = make_data::<T>(284 name,285 CollectionMode::NFT,286 description,287 token_prefix,288 base_uri_value,289 true,290 )?;291 check_sent_amount_equals_collection_creation_price::<T>(value)?;292 let collection_helpers_address =293 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());294 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)295 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;296297 let address = pallet_common::eth::collection_id_to_address(collection_id);298 Ok(address)299 }300301 #[weight(<SelfWeightOf<T>>::create_collection())]302 #[solidity(rename_selector = "createRFTCollection")]303 fn create_rft_collection(304 &mut self,305 caller: caller,306 value: value,307 name: string,308 description: string,309 token_prefix: string,310 ) -> Result<address> {311 create_refungible_collection_internal::<T>(312 caller,313 value,314 name,315 description,316 token_prefix,317 Default::default(),318 false,319 )320 }321322 #[weight(<SelfWeightOf<T>>::create_collection())]323 #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]324 fn create_refungible_collection_with_properties(325 &mut self,326 caller: caller,327 value: value,328 name: string,329 description: string,330 token_prefix: string,331 base_uri: string,332 ) -> Result<address> {333 create_refungible_collection_internal::<T>(334 caller,335 value,336 name,337 description,338 token_prefix,339 base_uri,340 true,341 )342 }343344 /// Check if a collection exists345 /// @param collectionAddress Address of the collection in question346 /// @return bool Does the collection exist?347 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {348 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {349 let collection_id = id;350 return Ok(<CollectionById<T>>::contains_key(collection_id));351 }352353 Ok(false)354 }355356 fn collection_creation_fee(&self) -> Result<value> {357 let price: u128 = T::CollectionCreationPrice::get()358 .try_into()359 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait360 .expect("Collection creation price should be convertible to u128");361 Ok(price.into())362 }363}364365/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]366pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);367impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>368 for CollectionHelpersOnMethodCall<T>369{370 fn is_reserved(contract: &sp_core::H160) -> bool {371 contract == &T::ContractAddress::get()372 }373374 fn is_used(contract: &sp_core::H160) -> bool {375 contract == &T::ContractAddress::get()376 }377378 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {379 if handle.code_address() != T::ContractAddress::get() {380 return None;381 }382383 let helpers =384 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));385 pallet_evm_coder_substrate::call(handle, helpers)386 }387388 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {389 (contract == &T::ContractAddress::get())390 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())391 }392}393394generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);395generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);396397fn error_field_too_long(feild: &str, bound: usize) -> Error {398 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))399}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use ethereum as _;21use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};22use frame_support::traits::Get;23use pallet_common::{24 CollectionById,25 dispatch::CollectionDispatch,26 erc::{27 CollectionHelpersEvents,28 static_property::{key, value as property_value},29 },30};31use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};33use sp_std::vec;34use up_data_structs::{35 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,36 CollectionMode, PropertyValue,37};3839use crate::{Config, SelfWeightOf, weights::WeightInfo};4041use sp_std::vec::Vec;42use alloc::format;4344/// See [`CollectionHelpersCall`]45pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);46impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {47 fn recorder(&self) -> &SubstrateRecorder<T> {48 &self.049 }5051 fn into_recorder(self) -> SubstrateRecorder<T> {52 self.053 }54}5556fn convert_data<T: Config>(57 caller: caller,58 name: string,59 description: string,60 token_prefix: string,61 base_uri: string,62) -> Result<(63 T::CrossAccountId,64 CollectionName,65 CollectionDescription,66 CollectionTokenPrefix,67 PropertyValue,68)> {69 let caller = T::CrossAccountId::from_eth(caller);70 let name = name71 .encode_utf16()72 .collect::<Vec<u16>>()73 .try_into()74 .map_err(|_| error_field_too_long(stringify!(name), CollectionName::bound()))?;75 let description = description76 .encode_utf16()77 .collect::<Vec<u16>>()78 .try_into()79 .map_err(|_| {80 error_field_too_long(stringify!(description), CollectionDescription::bound())81 })?;82 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {83 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())84 })?;85 let base_uri_value = base_uri86 .into_bytes()87 .try_into()88 .map_err(|_| error_field_too_long(stringify!(token_prefix), PropertyValue::bound()))?;89 Ok((caller, name, description, token_prefix, base_uri_value))90}9192fn 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}112fn make_data<T: Config>(113 name: CollectionName,114 mode: CollectionMode,115 description: CollectionDescription,116 token_prefix: CollectionTokenPrefix,117 base_uri_value: PropertyValue,118 add_properties: bool,119) -> Result<CreateCollectionData<T::AccountId>> {120 let token_property_permissions = if add_properties {121 vec![default_url_pkp(), default_suffix_pkp()]122 .try_into()123 .map_err(|e| Error::Revert(format!("{:?}", e)))?124 } else {125 up_data_structs::CollectionPropertiesPermissionsVec::default()126 };127 let properties = if add_properties {128 let mut properties = vec![129 up_data_structs::Property {130 key: key::schema_name(),131 value: property_value::erc721(),132 },133 up_data_structs::Property {134 key: key::schema_version(),135 value: property_value::schema_version(),136 },137 ];138 if !base_uri_value.is_empty() {139 properties.push(up_data_structs::Property {140 key: key::base_uri(),141 value: base_uri_value,142 })143 }144 properties145 .try_into()146 .map_err(|e| Error::Revert(format!("{:?}", e)))?147 } else {148 up_data_structs::CollectionPropertiesVec::default()149 };150151 let data = CreateCollectionData {152 name,153 mode,154 description,155 token_prefix,156 token_property_permissions,157 properties,158 ..Default::default()159 };160 Ok(data)161}162163fn create_refungible_collection_internal<164 T: Config + pallet_nonfungible::Config + pallet_refungible::Config,165>(166 caller: caller,167 value: value,168 name: string,169 description: string,170 token_prefix: string,171 base_uri: string,172 add_properties: bool,173) -> Result<address> {174 let (caller, name, description, token_prefix, base_uri_value) =175 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;176 let data = make_data::<T>(177 name,178 CollectionMode::ReFungible,179 description,180 token_prefix,181 base_uri_value,182 add_properties,183 )?;184 check_sent_amount_equals_collection_creation_price::<T>(value)?;185 let collection_helpers_address =186 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());187188 let collection_id =189 T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)190 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;191 let address = pallet_common::eth::collection_id_to_address(collection_id);192 Ok(address)193}194195fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {196 let value = value.as_u128();197 let creation_price: u128 = T::CollectionCreationPrice::get()198 .try_into()199 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait200 .expect("Collection creation price should be convertible to u128");201 if value != creation_price {202 return Err(format!(203 "Sent amount not equals to collection creation price ({0})",204 creation_price205 )206 .into());207 }208 Ok(())209}210211/// @title Contract, which allows users to operate with collections212#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]213impl<T> EvmCollectionHelpers<T>214where215 T: Config + pallet_common::Config + pallet_nonfungible::Config + pallet_refungible::Config,216{217 /// Create an NFT collection218 /// @param name Name of the collection219 /// @param description Informative description of the collection220 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications221 /// @return address Address of the newly created collection222 #[weight(<SelfWeightOf<T>>::create_collection())]223 #[solidity(rename_selector = "createNFTCollection")]224 fn create_nft_collection(225 &mut self,226 caller: caller,227 value: value,228 name: string,229 description: string,230 token_prefix: string,231 ) -> Result<address> {232 let (caller, name, description, token_prefix, _base_uri_value) =233 convert_data::<T>(caller, name, description, token_prefix, "".into())?;234 let data = make_data::<T>(235 name,236 CollectionMode::NFT,237 description,238 token_prefix,239 Default::default(),240 false,241 )?;242 check_sent_amount_equals_collection_creation_price::<T>(value)?;243 let collection_helpers_address =244 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());245 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)246 .map_err(dispatch_to_evm::<T>)?;247248 let address = pallet_common::eth::collection_id_to_address(collection_id);249 Ok(address)250 }251 /// Create an NFT collection252 /// @param name Name of the collection253 /// @param description Informative description of the collection254 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications255 /// @return address Address of the newly created collection256 #[weight(<SelfWeightOf<T>>::create_collection())]257 #[deprecated(note = "mathod was renamed to `create_nft_collection`, prefer it instead")]258 fn create_nonfungible_collection(259 &mut self,260 caller: caller,261 value: value,262 name: string,263 description: string,264 token_prefix: string,265 ) -> Result<address> {266 self.create_nft_collection(caller, value, name, description, token_prefix)267 }268269 #[weight(<SelfWeightOf<T>>::create_collection())]270 #[solidity(rename_selector = "createERC721MetadataCompatibleNFTCollection")]271 fn create_nonfungible_collection_with_properties(272 &mut self,273 caller: caller,274 value: value,275 name: string,276 description: string,277 token_prefix: string,278 base_uri: string,279 ) -> Result<address> {280 let (caller, name, description, token_prefix, base_uri_value) =281 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;282 let data = make_data::<T>(283 name,284 CollectionMode::NFT,285 description,286 token_prefix,287 base_uri_value,288 true,289 )?;290 check_sent_amount_equals_collection_creation_price::<T>(value)?;291 let collection_helpers_address =292 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());293 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)294 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;295296 let address = pallet_common::eth::collection_id_to_address(collection_id);297 Ok(address)298 }299300 #[weight(<SelfWeightOf<T>>::create_collection())]301 #[solidity(rename_selector = "createRFTCollection")]302 fn create_rft_collection(303 &mut self,304 caller: caller,305 value: value,306 name: string,307 description: string,308 token_prefix: string,309 ) -> Result<address> {310 create_refungible_collection_internal::<T>(311 caller,312 value,313 name,314 description,315 token_prefix,316 Default::default(),317 false,318 )319 }320321 #[weight(<SelfWeightOf<T>>::create_collection())]322 #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]323 fn create_refungible_collection_with_properties(324 &mut self,325 caller: caller,326 value: value,327 name: string,328 description: string,329 token_prefix: string,330 base_uri: string,331 ) -> Result<address> {332 create_refungible_collection_internal::<T>(333 caller,334 value,335 name,336 description,337 token_prefix,338 base_uri,339 true,340 )341 }342343 /// Check if a collection exists344 /// @param collectionAddress Address of the collection in question345 /// @return bool Does the collection exist?346 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {347 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {348 let collection_id = id;349 return Ok(<CollectionById<T>>::contains_key(collection_id));350 }351352 Ok(false)353 }354355 fn collection_creation_fee(&self) -> Result<value> {356 let price: u128 = T::CollectionCreationPrice::get()357 .try_into()358 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait359 .expect("Collection creation price should be convertible to u128");360 Ok(price.into())361 }362}363364/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]365pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);366impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>367 for CollectionHelpersOnMethodCall<T>368{369 fn is_reserved(contract: &sp_core::H160) -> bool {370 contract == &T::ContractAddress::get()371 }372373 fn is_used(contract: &sp_core::H160) -> bool {374 contract == &T::ContractAddress::get()375 }376377 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {378 if handle.code_address() != T::ContractAddress::get() {379 return None;380 }381382 let helpers =383 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));384 pallet_evm_coder_substrate::call(handle, helpers)385 }386387 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {388 (contract == &T::ContractAddress::get())389 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())390 }391}392393generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);394generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);395396fn error_field_too_long(feild: &str, bound: usize) -> Error {397 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))398}primitives/data-structs/src/lib.rsdiffbeforeafterboth--- 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.