difftreelog
feat make collection ERC721 compatible
in: master
4 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth27 CollectionHelpersEvents,27 CollectionHelpersEvents,28 static_property::{key, value as property_value},28 static_property::{key, value as property_value},29 },29 },30 Pallet as PalletCommon,30};31};31use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};32use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};33use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};340 )341 )341 }342 }343344 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]345 fn make_collection_metadata_compatible(346 &mut self,347 caller: caller,348 collection: address,349 base_uri: string,350 ) -> Result<()> {351 let caller = T::CrossAccountId::from_eth(caller);352 let collection =353 pallet_common::eth::map_eth_to_id(&collection).ok_or("not a collection address")?;354 let mut collection =355 <crate::CollectionHandle<T>>::new(collection).ok_or("collection not found")?;356357 if !matches!(358 collection.mode,359 CollectionMode::NFT | CollectionMode::ReFungible360 ) {361 return Err("target collection should be either NFT or Refungible".into());362 }363364 self.recorder().consume_sstore()?;365 collection366 .check_is_owner_or_admin(&caller)367 .map_err(dispatch_to_evm::<T>)?;368369 if collection.flags.erc721metadata {370 return Err("target collection is already Erc721Metadata compatible".into());371 }372 collection.flags.erc721metadata = true;373374 let all_permissions = <pallet_common::CollectionPropertyPermissions<T>>::get(collection.id);375 if all_permissions.get(&key::url()).is_none() {376 self.recorder().consume_sstore()?;377 <PalletCommon<T>>::set_property_permission(&collection, &caller, default_url_pkp())378 .map_err(dispatch_to_evm::<T>)?;379 }380 if all_permissions.get(&key::suffix()).is_none() {381 self.recorder().consume_sstore()?;382 <PalletCommon<T>>::set_property_permission(&collection, &caller, default_suffix_pkp())383 .map_err(dispatch_to_evm::<T>)?;384 }385386 let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);387 let mut new_properties = vec![];388 if all_properties.get(&key::schema_name()).is_none() {389 self.recorder().consume_sstore()?;390 new_properties.push(up_data_structs::Property {391 key: key::schema_name(),392 value: property_value::erc721(),393 });394 new_properties.push(up_data_structs::Property {395 key: key::schema_version(),396 value: property_value::schema_version(),397 });398 }399 if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {400 new_properties.push(up_data_structs::Property {401 key: key::base_uri(),402 value: base_uri403 .into_bytes()404 .try_into()405 .map_err(|_| "base uri is too large")?,406 });407 }408409 if !new_properties.is_empty() {410 self.recorder().consume_sstore()?;411 <PalletCommon<T>>::set_collection_properties(&collection, &caller, new_properties)412 .map_err(dispatch_to_evm::<T>)?;413 }414415 self.recorder().consume_sstore()?;416 collection.save().map_err(dispatch_to_evm::<T>)?;417418 Ok(())419 }342420343 /// Check if a collection exists421 /// Check if a collection exists344 /// @param collectionAddress Address of the collection in question422 /// @param collectionAddress Address of the collection in questionpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -23,7 +23,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xd14d1221
+/// @dev the ERC-165 identifier for this interface is 0x542f5079
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -114,6 +114,15 @@
return 0x0000000000000000000000000000000000000000;
}
+ /// @dev EVM selector for this function is: 0x85624258,
+ /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)
+ function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {
+ require(false, stub_error);
+ collection;
+ baseUri;
+ dummy = 0;
+ }
+
/// Check if a collection exists
/// @param collectionAddress Address of the collection in question
/// @return bool Does the collection exist?
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -18,7 +18,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xd14d1221
+/// @dev the ERC-165 identifier for this interface is 0x542f5079
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -72,6 +72,10 @@
string memory baseUri
) external payable returns (address);
+ /// @dev EVM selector for this function is: 0x85624258,
+ /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)
+ function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;
+
/// Check if a collection exists
/// @param collectionAddress Address of the collection in question
/// @return bool Does the collection exist?
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -97,6 +97,16 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "collection", "type": "address" },
+ { "internalType": "string", "name": "baseUri", "type": "string" }
+ ],
+ "name": "makeCollectionERC721MetadataCompatible",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
],
"name": "supportsInterface",