git.delta.rocks / unique-network / refs/commits / 0c9dfc515d68

difftreelog

CORE-302 Implement methods for setup collection.

Trubnikov Sergey2022-04-21parent: #d7a043d.patch.diff
in: master

8 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
115 })115 })
116 }116 }
117117
118 pub fn new_with_recorder(id: CollectionId, recorder: Rc<SubstrateRecorder<T>>) -> Option<Self> {118 pub fn new_with_recorder(id: CollectionId, recorder: SubstrateRecorder<T>) -> Option<Self> {
119 <CollectionById<T>>::get(id).map(|collection| Self {119 <CollectionById<T>>::get(id).map(|collection| Self {
120 id,120 id,
121 collection,121 collection,
154 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);154 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);
155 }155 }
156
157 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> bool {
158 if self.collection.sponsorship.pending_sponsor() != Some(sender) {
159 return false;
160 };
161
162 self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());
163 true
164 }
156}165}
157impl<T: Config> Deref for CollectionHandle<T> {166impl<T: Config> Deref for CollectionHandle<T> {
158 type Target = Collection<T::AccountId>;167 type Target = Collection<T::AccountId>;
modifiedpallets/evm-collection/src/eth.rsdiffbeforeafterboth
17use core::marker::PhantomData;17use core::marker::PhantomData;
18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
19use ethereum as _;19use ethereum as _;
20use pallet_common::{CollectionById, CollectionHandle};20use pallet_common::CollectionById;
21use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
22use pallet_evm::{22use pallet_evm::{
23 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,23 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,
26use sp_core::H160;26use sp_core::H160;
27use up_data_structs::{27use up_data_structs::{
28 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,28 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
29 MAX_COLLECTION_NAME_LENGTH, SponsorshipState,29 MAX_COLLECTION_NAME_LENGTH,
30};30};
31use crate::{Config, Pallet};31use crate::{Config, Pallet};
32use frame_support::traits::Get;32use frame_support::traits::Get;
103 Ok(address)102 Ok(address)
104 }103 }
105104
106 fn set_sponsor(105 // fn set_sponsor(collection_id: address, sponsor: address) -> Result<void> {
107 &self,106 // let collection_id =
108 caller: caller,107 // pallet_common::eth::map_eth_to_id(&collection_id).ok_or(Error::Revert("".into()))?;
109 contract_address: address,108 // let mut collection = <CollectionById<T>>::get(collection_id).ok_or(Error::Revert("".into()))?;
110 sponsor: address,109 // let sponsor = T::CrossAccountId::from_eth(sponsor);
111 ) -> Result<void> {110 // collection.sponsorship = SponsorshipState::Unconfirmed(sponsor.as_sub().clone());
112 let collection_id =111 // <CollectionById<T>>::insert(collection_id, collection);
113 pallet_common::eth::map_eth_to_id(&contract_address).ok_or(Error::Revert("".into()))?;112 // Ok(())
114 let mut collection =113 // }
115 pallet_common::CollectionHandle::new_with_recorder(collection_id, self.0.clone())
116 .ok_or(Error::Revert("".into()))?;
117
118 let caller = T::CrossAccountId::from_eth(caller);
119 collection.check_is_owner(&caller).map_err(|e| Error::Revert(format!("{:?}", e)))?;
120
121 let sponsor = T::CrossAccountId::from_eth(sponsor);
122 collection.set_sponsor(sponsor.as_sub().clone());
123 collection
124 .save()
125 .map_err(|e| Error::Revert(format!("{:?}", e)))
126 }
127114
128 // fn set_offchain_shema(shema: string) -> Result<void> {115 // fn set_offchain_shema(shema: string) -> Result<void> {
129 // Ok(())116 // Ok(())
168 return None;155 return None;
169 }156 }
170157
171 let helpers = EvmCollection::<T>(SubstrateRecorder::<T>::new(gas_left));158 let helpers = EvmCollection::<T>(SubstrateRecorder::new(gas_left));
172 pallet_evm_coder_substrate::call(*source, helpers, value, input)159 pallet_evm_coder_substrate::call(*source, helpers, value, input)
173 }160 }
174161
modifiedpallets/evm-collection/src/stubs/Collection.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-collection/src/stubs/Collection.soldiffbeforeafterboth
21 }21 }
22}22}
2323
24// Selector: 6503bbc224// Selector: d32d5104
25contract Collection is Dummy, ERC165 {25contract Collection is Dummy, ERC165 {
26 // Selector: create721Collection(string,string,string) 951c015126 // Selector: create721Collection(string,string,string) 951c0151
27 function create721Collection(27 function create721Collection(
38 }38 }
3939
40 // Selector: setSponsor(address,address) f01fba9340 // Selector: setSponsor(address,address) f01fba93
41 function setSponsor(address contractAddress, address sponsor) public view {41 function setSponsor(address collectionAddress, address sponsor)
42 public
43 view
44 {
42 require(false, stub_error);45 require(false, stub_error);
43 contractAddress;46 collectionAddress;
44 sponsor;47 sponsor;
45 dummy;48 dummy;
46 }49 }
50
51 // Selector: confirmSponsorship(address) abc00001
52 function confirmSponsorship(address collectionAddress) public view {
53 require(false, stub_error);
54 collectionAddress;
55 dummy;
56 }
57
58 // Selector: setOffchainShema(address,string) d7dc2de3
59 function setOffchainShema(address collectionAddress, string memory shema)
60 public
61 view
62 {
63 require(false, stub_error);
64 collectionAddress;
65 shema;
66 dummy;
67 }
68
69 // Selector: setVariableOnChainSchema(address,string) 582691c3
70 function setVariableOnChainSchema(
71 address collectionAddress,
72 string memory variable
73 ) public view {
74 require(false, stub_error);
75 collectionAddress;
76 variable;
77 dummy;
78 }
79
80 // Selector: setConstOnChainSchema(address,string) 921456e7
81 function setConstOnChainSchema(
82 address collectionAddress,
83 string memory constOnChain
84 ) public view {
85 require(false, stub_error);
86 collectionAddress;
87 constOnChain;
88 dummy;
89 }
47}90}
4891
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
544544
545 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;545 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
546 ensure!(546 ensure!(
547 target_collection.sponsorship.pending_sponsor() == Some(&sender),547 target_collection.confirm_sponsorship(&sender),
548 Error::<T>::ConfirmUnsetSponsorFail548 Error::<T>::ConfirmUnsetSponsorFail
549 );549 );
550
551 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());
552550
553 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(551 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(
554 collection_id,552 collection_id,
modifiedtests/src/eth/api/Collection.soldiffbeforeafterboth
12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
13}13}
1414
15// Selector: 6503bbc215// Selector: d32d5104
16interface Collection is Dummy, ERC165 {16interface Collection is Dummy, ERC165 {
17 // Selector: create721Collection(string,string,string) 951c015117 // Selector: create721Collection(string,string,string) 951c0151
18 function create721Collection(18 function create721Collection(
22 ) external view returns (address);22 ) external view returns (address);
2323
24 // Selector: setSponsor(address,address) f01fba9324 // Selector: setSponsor(address,address) f01fba93
25 function setSponsor(address contractAddress, address sponsor) external view;25 function setSponsor(address collectionAddress, address sponsor)
26 external
27 view;
28
29 // Selector: confirmSponsorship(address) abc00001
30 function confirmSponsorship(address collectionAddress) external view;
31
32 // Selector: setOffchainShema(address,string) d7dc2de3
33 function setOffchainShema(address collectionAddress, string memory shema)
34 external
35 view;
36
37 // Selector: setVariableOnChainSchema(address,string) 582691c3
38 function setVariableOnChainSchema(
39 address collectionAddress,
40 string memory variable
41 ) external view;
42
43 // Selector: setConstOnChainSchema(address,string) 921456e7
44 function setConstOnChainSchema(
45 address collectionAddress,
46 string memory constOnChain
47 ) external view;
26}48}
2749
modifiedtests/src/eth/collectionAbi.jsondiffbeforeafterboth
1[1[
2 {
3 "inputs": [
4 {
5 "internalType": "address",
6 "name": "collectionAddress",
7 "type": "address"
8 }
9 ],
10 "name": "confirmSponsorship",
11 "outputs": [],
12 "stateMutability": "view",
13 "type": "function"
14 },
2 {15 {
3 "inputs": [16 "inputs": [
4 { "internalType": "string", "name": "name", "type": "string" },17 { "internalType": "string", "name": "name", "type": "string" },
10 "stateMutability": "view",23 "stateMutability": "view",
11 "type": "function"24 "type": "function"
12 },25 },
26 {
27 "inputs": [
28 {
29 "internalType": "address",
30 "name": "collectionAddress",
31 "type": "address"
32 },
33 { "internalType": "string", "name": "constOnChain", "type": "string" }
34 ],
35 "name": "setConstOnChainSchema",
36 "outputs": [],
37 "stateMutability": "view",
38 "type": "function"
39 },
40 {
41 "inputs": [
42 {
43 "internalType": "address",
44 "name": "collectionAddress",
45 "type": "address"
46 },
47 { "internalType": "string", "name": "shema", "type": "string" }
48 ],
49 "name": "setOffchainShema",
50 "outputs": [],
51 "stateMutability": "view",
52 "type": "function"
53 },
13 {54 {
14 "inputs": [55 "inputs": [
15 {56 {
16 "internalType": "address",57 "internalType": "address",
17 "name": "contractAddress",58 "name": "collectionAddress",
18 "type": "address"59 "type": "address"
19 },60 },
20 { "internalType": "address", "name": "sponsor", "type": "address" }61 { "internalType": "address", "name": "sponsor", "type": "address" }
24 "stateMutability": "view",65 "stateMutability": "view",
25 "type": "function"66 "type": "function"
26 },67 },
68 {
69 "inputs": [
70 {
71 "internalType": "address",
72 "name": "collectionAddress",
73 "type": "address"
74 },
75 { "internalType": "string", "name": "variable", "type": "string" }
76 ],
77 "name": "setVariableOnChainSchema",
78 "outputs": [],
79 "stateMutability": "view",
80 "type": "function"
81 },
27 {82 {
28 "inputs": [83 "inputs": [
29 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }84 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
57 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);57 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
58 const sponsor = await createEthAccountWithBalance(api, web3);58 const sponsor = await createEthAccountWithBalance(api, web3);
59 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();59 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();
60 const collection = (await getDetailedCollectionInfo(api, collectionId))!;60 let collection = (await getDetailedCollectionInfo(api, collectionId))!;
61 expect(collection.sponsorship.isUnconfirmed).to.be.true;61 expect(collection.sponsorship.isUnconfirmed).to.be.true;
62 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));62 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
63 await expect(helper.methods.confirmSponsorship(collectionIdAddress).call()).to.be.rejectedWith('Caller is not set as sponsor');
64 const sponsorHelper = collectionHelper(web3, sponsor);
65 await sponsorHelper.methods.confirmSponsorship(collectionIdAddress).send();
66 collection = (await getDetailedCollectionInfo(api, collectionId))!;
67 expect(collection.sponsorship.isConfirmed).to.be.true;
68 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
63 });69 });
6470
6571 itWeb3('Set offchain shema', async ({api, web3}) => {
72 const owner = await createEthAccountWithBalance(api, web3);
73 const helper = collectionHelper(web3, owner);
74 let result = await helper.methods.create721Collection('Shema collection', '2', '2').send();
75 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
76 const shema = 'Some shema';
77 result = await helper.methods.setOffchainShema(collectionIdAddress, shema).send();
78 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
79 expect(collection.offchainSchema.toHuman()).to.be.eq(shema);
80 });
81
82 itWeb3('Set variable on chain schema', async ({api, web3}) => {
83 const owner = await createEthAccountWithBalance(api, web3);
84 const helper = collectionHelper(web3, owner);
85 let result = await helper.methods.create721Collection('Variable collection', '3', '3').send();
86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
87 const variable = 'Some variable';
88 result = await helper.methods.setVariableOnChainSchema(collectionIdAddress, variable).send();
89 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
90 expect(collection.variableOnChainSchema.toHuman()).to.be.eq(variable);
91 });
92
93 itWeb3('Set const on chain schema', async ({api, web3}) => {
94 const owner = await createEthAccountWithBalance(api, web3);
95 const helper = collectionHelper(web3, owner);
96 let result = await helper.methods.create721Collection('Const collection', '4', '4').send();
97 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
98 const constShema = 'Some const';
99 result = await helper.methods.setConstOnChainSchema(collectionIdAddress, constShema).send();
100 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
101 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constShema);
102 });
66});103});