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.soldiffbeforeafterboth23}23}242425/// @title Contract, which allows users to operate with collections25/// @title Contract, which allows users to operate with collections26/// @dev the ERC-165 identifier for this interface is 0xd14d122126/// @dev the ERC-165 identifier for this interface is 0x542f507927contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {27contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28 /// Create an NFT collection28 /// Create an NFT collection29 /// @param name Name of the collection29 /// @param name Name of the collection114 return 0x0000000000000000000000000000000000000000;114 return 0x0000000000000000000000000000000000000000;115 }115 }116117 /// @dev EVM selector for this function is: 0x85624258,118 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)119 function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {120 require(false, stub_error);121 collection;122 baseUri;123 dummy = 0;124 }116125117 /// Check if a collection exists126 /// Check if a collection exists118 /// @param collectionAddress Address of the collection in question127 /// @param collectionAddress Address of the collection in questiontests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth18}18}191920/// @title Contract, which allows users to operate with collections20/// @title Contract, which allows users to operate with collections21/// @dev the ERC-165 identifier for this interface is 0xd14d122121/// @dev the ERC-165 identifier for this interface is 0x542f507922interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {22interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {23 /// Create an NFT collection23 /// Create an NFT collection24 /// @param name Name of the collection24 /// @param name Name of the collection72 string memory baseUri72 string memory baseUri73 ) external payable returns (address);73 ) external payable returns (address);7475 /// @dev EVM selector for this function is: 0x85624258,76 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)77 function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;747875 /// Check if a collection exists79 /// Check if a collection exists76 /// @param collectionAddress Address of the collection in question80 /// @param collectionAddress Address of the collection in questiontests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth95 "stateMutability": "view",95 "stateMutability": "view",96 "type": "function"96 "type": "function"97 },97 },98 {99 "inputs": [100 { "internalType": "address", "name": "collection", "type": "address" },101 { "internalType": "string", "name": "baseUri", "type": "string" }102 ],103 "name": "makeCollectionERC721MetadataCompatible",104 "outputs": [],105 "stateMutability": "nonpayable",106 "type": "function"107 },98 {108 {99 "inputs": [109 "inputs": [100 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }110 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }