git.delta.rocks / unique-network / refs/commits / f27580fc65c7

difftreelog

feat make collection ERC721 compatible

Yaroslav Bolyukin2022-10-13parent: #8ad09da.patch.diff
in: master

4 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
27 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 }
343
344 #[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")?;
356
357 if !matches!(
358 collection.mode,
359 CollectionMode::NFT | CollectionMode::ReFungible
360 ) {
361 return Err("target collection should be either NFT or Refungible".into());
362 }
363
364 self.recorder().consume_sstore()?;
365 collection
366 .check_is_owner_or_admin(&caller)
367 .map_err(dispatch_to_evm::<T>)?;
368
369 if collection.flags.erc721metadata {
370 return Err("target collection is already Erc721Metadata compatible".into());
371 }
372 collection.flags.erc721metadata = true;
373
374 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 }
385
386 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_uri
403 .into_bytes()
404 .try_into()
405 .map_err(|_| "base uri is too large")?,
406 });
407 }
408
409 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 }
414
415 self.recorder().consume_sstore()?;
416 collection.save().map_err(dispatch_to_evm::<T>)?;
417
418 Ok(())
419 }
342420
343 /// Check if a collection exists421 /// Check if a collection exists
344 /// @param collectionAddress Address of the collection in question422 /// @param collectionAddress Address of the collection in question
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
23}23}
2424
25/// @title Contract, which allows users to operate with collections25/// @title Contract, which allows users to operate with collections
26/// @dev the ERC-165 identifier for this interface is 0xd14d122126/// @dev the ERC-165 identifier for this interface is 0x542f5079
27contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {27contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
28 /// Create an NFT collection28 /// Create an NFT collection
29 /// @param name Name of the collection29 /// @param name Name of the collection
114 return 0x0000000000000000000000000000000000000000;114 return 0x0000000000000000000000000000000000000000;
115 }115 }
116
117 /// @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 }
116125
117 /// Check if a collection exists126 /// Check if a collection exists
118 /// @param collectionAddress Address of the collection in question127 /// @param collectionAddress Address of the collection in question
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
18}18}
1919
20/// @title Contract, which allows users to operate with collections20/// @title Contract, which allows users to operate with collections
21/// @dev the ERC-165 identifier for this interface is 0xd14d122121/// @dev the ERC-165 identifier for this interface is 0x542f5079
22interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {22interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
23 /// Create an NFT collection23 /// Create an NFT collection
24 /// @param name Name of the collection24 /// @param name Name of the collection
72 string memory baseUri72 string memory baseUri
73 ) external payable returns (address);73 ) external payable returns (address);
74
75 /// @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;
7478
75 /// Check if a collection exists79 /// Check if a collection exists
76 /// @param collectionAddress Address of the collection in question80 /// @param collectionAddress Address of the collection in question
modifiedtests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth
95 "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" }