git.delta.rocks / unique-network / refs/commits / 4afba3743846

difftreelog

add `collectionComtractAddress` funtion to `CollectionHelpers` interface

PraetorP2022-11-28parent: #b7593be.patch.diff
in: master

13 files changed

modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
491 Err("not implemented".into())491 Err("not implemented".into())
492 }492 }
493 493
494 /// @notice Returns collection helper contract address 494 /// @notice Returns collection helper contract address
495 fn collection_helper_address(&self) -> Result<address> {495 fn collection_helper_address(&self) -> Result<address> {
496 Ok(T::ContractAddress::get())496 Ok(T::ContractAddress::get())
497 }497 }
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
28 CollectionById,28 CollectionById,
29 dispatch::CollectionDispatch,29 dispatch::CollectionDispatch,
30 erc::{CollectionHelpersEvents, static_property::key},30 erc::{CollectionHelpersEvents, static_property::key},
31 eth::{map_eth_to_id, collection_id_to_address},
31 Pallet as PalletCommon,32 Pallet as PalletCommon,
32};33};
33use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};34use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
34use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};35use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
35use sp_std::vec;36use sp_std::vec;
36use up_data_structs::{37use up_data_structs::{
37 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,38 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
38 CreateCollectionData,39 CreateCollectionData, CollectionId,
39};40};
4041
41use crate::{weights::WeightInfo, Config, SelfWeightOf};42use crate::{weights::WeightInfo, Config, SelfWeightOf};
362 Ok(price.into())363 Ok(price.into())
363 }364 }
365
366 /// Returns address of a collection.
367 /// @param collectionId - CollectionId of the collection
368 /// @return eth mirror address of the collection
369 fn collection_address(&self, collection_id: uint32) -> Result<address> {
370 Ok(collection_id_to_address(collection_id.into()))
371 }
372
373 /// Returns collectionId of a collection.
374 /// @param collectionAddress - Eth address of the collection
375 /// @return collectionId of the collection
376 fn collection_id(&self, collection_address: address) -> Result<uint32> {
377 map_eth_to_id(&collection_address)
378 .map(|id| id.0)
379 .ok_or(Error::Revert(format!(
380 "failed to convert address {} into collectionId.",
381 collection_address
382 )))
383 }
364}384}
365385
366/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]386/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
24}24}
2525
26/// @title Contract, which allows users to operate with collections26/// @title Contract, which allows users to operate with collections
27/// @dev the ERC-165 identifier for this interface is 0x7dea03b127/// @dev the ERC-165 identifier for this interface is 0xe65011aa
28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
29 /// Create an NFT collection29 /// Create an NFT collection
30 /// @param name Name of the collection30 /// @param name Name of the collection
131 return 0;131 return 0;
132 }132 }
133
134 /// Returns address of a collection.
135 /// @param collectionId - CollectionId of the collection
136 /// @return eth mirror address of the collection
137 /// @dev EVM selector for this function is: 0x2e716683,
138 /// or in textual repr: collectionAddress(uint32)
139 function collectionAddress(uint32 collectionId) public view returns (address) {
140 require(false, stub_error);
141 collectionId;
142 dummy;
143 return 0x0000000000000000000000000000000000000000;
144 }
145
146 /// Returns collectionId of a collection.
147 /// @param collectionAddress - Eth address of the collection
148 /// @return collectionId of the collection
149 /// @dev EVM selector for this function is: 0xb5cb7498,
150 /// or in textual repr: collectionId(address)
151 function collectionId(address collectionAddress) public view returns (uint32) {
152 require(false, stub_error);
153 collectionAddress;
154 dummy;
155 return 0;
156 }
133}157}
134158
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
31 "name": "CollectionDestroyed",31 "name": "CollectionDestroyed",
32 "type": "event"32 "type": "event"
33 },33 },
34 {
35 "inputs": [
36 { "internalType": "uint32", "name": "collectionId", "type": "uint32" }
37 ],
38 "name": "collectionAddress",
39 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
40 "stateMutability": "view",
41 "type": "function"
42 },
34 {43 {
35 "inputs": [],44 "inputs": [],
36 "name": "collectionCreationFee",45 "name": "collectionCreationFee",
37 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],46 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
38 "stateMutability": "view",47 "stateMutability": "view",
39 "type": "function"48 "type": "function"
40 },49 },
50 {
51 "inputs": [
52 {
53 "internalType": "address",
54 "name": "collectionAddress",
55 "type": "address"
56 }
57 ],
58 "name": "collectionId",
59 "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],
60 "stateMutability": "view",
61 "type": "function"
62 },
41 {63 {
42 "inputs": [64 "inputs": [
43 { "internalType": "string", "name": "name", "type": "string" },65 { "internalType": "string", "name": "name", "type": "string" },
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
19}19}
2020
21/// @title Contract, which allows users to operate with collections21/// @title Contract, which allows users to operate with collections
22/// @dev the ERC-165 identifier for this interface is 0x7dea03b122/// @dev the ERC-165 identifier for this interface is 0xe65011aa
23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
24 /// Create an NFT collection24 /// Create an NFT collection
25 /// @param name Name of the collection25 /// @param name Name of the collection
79 /// or in textual repr: collectionCreationFee()79 /// or in textual repr: collectionCreationFee()
80 function collectionCreationFee() external view returns (uint256);80 function collectionCreationFee() external view returns (uint256);
81
82 /// Returns address of a collection.
83 /// @param collectionId - CollectionId of the collection
84 /// @return eth mirror address of the collection
85 /// @dev EVM selector for this function is: 0x2e716683,
86 /// or in textual repr: collectionAddress(uint32)
87 function collectionAddress(uint32 collectionId) external view returns (address);
88
89 /// Returns collectionId of a collection.
90 /// @param collectionAddress - Eth address of the collection
91 /// @return collectionId of the collection
92 /// @dev EVM selector for this function is: 0xb5cb7498,
93 /// or in textual repr: collectionId(address)
94 function collectionId(address collectionAddress) external view returns (uint32);
81}95}
8296
modifiedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth
1616
17import {itEth, usingEthPlaygrounds, expect} from './util';17import {itEth, usingEthPlaygrounds, expect} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Pallets} from '../util';
1920
20const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';21const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
2122
22describe('[eth]CollectionHelerpAddress test: ERC721 ', () => {23describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
23 let donor: IKeyringPair;24 let donor: IKeyringPair;
2425
25 before(async function() {26 before(async function() {
28 });29 });
29 });30 });
3031
31 itEth('NFT\\RFT', async ({helper}) => {32 itEth('NFT', async ({helper}) => {
32 const owner = await helper.eth.createAccountWithBalance(donor);33 const owner = await helper.eth.createAccountWithBalance(donor);
33 34
34 const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');35 const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
35 const nftCollection = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);36 const nftCollection = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
36 37
37 const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
38 const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
39
40 expect((await nftCollection.methods.collectionHelperAddress().call())38 expect((await nftCollection.methods.collectionHelperAddress().call())
41 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);39 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
42
43 expect((await rftCollection.methods.collectionHelperAddress().call())
44 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
45 });40 });
46 41
42 itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
43 const owner = await helper.eth.createAccountWithBalance(donor);
44
45 const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');
46
47 const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
48 expect((await rftCollection.methods.collectionHelperAddress().call())
49 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
50 });
51
47 itEth('FT', async ({helper}) => {52 itEth('FT', async ({helper}) => {
48 const owner = await helper.eth.createAccountWithBalance(donor);53 const owner = await helper.eth.createAccountWithBalance(donor);
54 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);59 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
55 });60 });
56 61
62 itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
63 const owner = await helper.eth.createAccountWithBalance(donor);
64 const collectionId = 7;
65 const collectionAddress = helper.ethAddress.fromCollectionId(collectionId);
66 const helperContract = helper.ethNativeContract.collectionHelpers(owner);
67
68 expect(await helperContract.methods.collectionAddress(collectionId).call()).to.be.equal(collectionAddress);
69 expect(parseInt(await helperContract.methods.collectionId(collectionAddress).call())).to.be.equal(collectionId);
70 });
71
57});72});
5873
modifiedtests/src/interfaces/lookup.tsdiffbeforeafterboth
2935 }2935 }
2936 }2936 }
2937 },2937 },
2938 /**2938 /**
2939 * Lookup338: pallet_maintenance::pallet::Call<T>2939 * Lookup340: pallet_maintenance::pallet::Call<T>
2940 **/2940 **/
2941 PalletMaintenanceCall: {2941 PalletMaintenanceCall: {
2942 _enum: ['enable', 'disable']2942 _enum: ['enable', 'disable']
2943 },2943 },
2944 /**2944 /**
2945 * Lookup339: pallet_test_utils::pallet::Call<T>2945 * Lookup341: pallet_test_utils::pallet::Call<T>
2946 **/2946 **/
2947 PalletTestUtilsCall: {2947 PalletTestUtilsCall: {
2948 _enum: {2948 _enum: {
2949 enable: 'Null',2949 enable: 'Null',
modifiedtests/src/interfaces/types-lookup.tsdiffbeforeafterboth
3175 readonly type: 'Begin' | 'SetData' | 'Finish' | 'InsertEthLogs' | 'InsertEvents';3175 readonly type: 'Begin' | 'SetData' | 'Finish' | 'InsertEthLogs' | 'InsertEvents';
3176 }3176 }
31773177
3178 /** @name PalletMaintenanceCall (338) */3178 /** @name PalletMaintenanceCall (340) */
3179 interface PalletMaintenanceCall extends Enum {3179 interface PalletMaintenanceCall extends Enum {
3180 readonly isEnable: boolean;3180 readonly isEnable: boolean;
3181 readonly isDisable: boolean;3181 readonly isDisable: boolean;
3182 readonly type: 'Enable' | 'Disable';3182 readonly type: 'Enable' | 'Disable';
3183 }3183 }
31843184
3185 /** @name PalletTestUtilsCall (339) */3185 /** @name PalletTestUtilsCall (341) */
3186 interface PalletTestUtilsCall extends Enum {3186 interface PalletTestUtilsCall extends Enum {
3187 readonly isEnable: boolean;3187 readonly isEnable: boolean;
3188 readonly isSetTestValue: boolean;3188 readonly isSetTestValue: boolean;