git.delta.rocks / unique-network / refs/commits / 31962dd005a3

difftreelog

CORE-302 Implement setLimits

Trubnikov Sergey2022-04-22parent: #0c9dfc5.patch.diff
in: master

9 files changed

modifiedCargo.lockdiffbeforeafterboth
6091 "pallet-nonfungible",6091 "pallet-nonfungible",
6092 "parity-scale-codec 3.1.2",6092 "parity-scale-codec 3.1.2",
6093 "scale-info",6093 "scale-info",
6094 "serde_json",
6094 "sp-core",6095 "sp-core",
6095 "sp-runtime",6096 "sp-runtime",
6096 "sp-std",6097 "sp-std",
modifiedpallets/evm-collection/Cargo.tomldiffbeforeafterboth
10] }10] }
11ethereum = { version = "0.12.0", default-features = false }11ethereum = { version = "0.12.0", default-features = false }
12log = { default-features = false, version = "0.4.14" }12log = { default-features = false, version = "0.4.14" }
13serde_json = { version = "1.0.68", default-features = false, features = ["alloc"] }
1314
14# Substrate15# Substrate
15frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.21' }16frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.21' }
27pallet-common = { default-features = false, path = '../../pallets/common' }28pallet-common = { default-features = false, path = '../../pallets/common' }
28pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }29pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
29pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }30pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }
30up-data-structs = { default-features = false, path = '../../primitives/data-structs' }31up-data-structs = { default-features = false, path = '../../primitives/data-structs', features = ["serde1"] }
3132
32[dependencies.codec]33[dependencies.codec]
33default-features = false34default-features = false
modifiedpallets/evm-collection/src/eth.rsdiffbeforeafterboth
112 // Ok(())112 // Ok(())
113 // }113 // }
114114
115 // fn set_offchain_shema(shema: string) -> Result<void> {115 fn set_offchain_shema(shema: string) -> Result<void> {
116 // Ok(())116 let shema = shema
117 // }117 .into_bytes()
118118 .try_into()
119 // fn set_const_on_chain_schema(shema: string) -> Result<void> {119 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;
120 // Ok(())120 collection.offchain_schema = shema;
121 // }121 save(collection)
122 }
123
124 fn confirm_sponsorship(&self, caller: caller, collection_address: address) -> Result<void> {
125 let (_, mut collection) = collection_from_address(collection_address, &self.0)?;
126 let caller = T::CrossAccountId::from_eth(caller);
127 if !collection.confirm_sponsorship(caller.as_sub()) {
128 return Err(Error::Revert("Caller is not set as sponsor".into()));
129 }
130 save(collection)
131 }
122132
123 // fn set_variable_on_chain_schema(shema: string) -> Result<void> {133 // fn set_variable_on_chain_schema(shema: string) -> Result<void> {
124 // Ok(())134 // Ok(())
125 // }135 // }
126136
127 // fn set_limits(limits: string) -> Result<void> {137 fn set_variable_on_chain_schema(
128 // Ok(())138 &self,
129 // }139 caller: caller,
140 collection_address: address,
141 variable: string,
142 ) -> Result<void> {
143 let (_, mut collection) = collection_from_address(collection_address, &self.0)?;
144 check_is_owner(caller, &collection)?;
145
146 let variable = variable.into_bytes().try_into().map_err(|_| {
147 error_feild_too_long(stringify!(variable), VARIABLE_ON_CHAIN_SCHEMA_LIMIT)
148 })?;
149 collection.variable_on_chain_schema = variable;
150 save(collection)
151 }
152
153 fn set_const_on_chain_schema(
154 &self,
155 caller: caller,
156 collection_address: address,
157 const_on_chain: string,
158 ) -> Result<void> {
159 let (_, mut collection) = collection_from_address(collection_address, &self.0)?;
160 check_is_owner(caller, &collection)?;
161
162 let const_on_chain = const_on_chain.into_bytes().try_into().map_err(|_| {
163 error_feild_too_long(stringify!(const_on_chain), CONST_ON_CHAIN_SCHEMA_LIMIT)
164 })?;
165 collection.const_on_chain_schema = const_on_chain;
166 save(collection)
167 }
168
169 fn set_limits(
170 &self,
171 caller: caller,
172 collection_address: address,
173 limits_json: string,
174 ) -> Result<void> {
175 let (_, mut collection) = collection_from_address(collection_address, &self.0)?;
176 check_is_owner(caller, &collection)?;
177
178 let limits = serde_json::from_str(limits_json.as_ref())
179 .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
180 collection.limits = limits;
181 save(collection)
182 }
130}183}
131184
132fn error_feild_too_long(feild: &str, bound: u32) -> Error {185fn error_feild_too_long(feild: &str, bound: u32) -> Error {
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: d32d510424// Selector: 037b69c8
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(
88 dummy;88 dummy;
89 }89 }
90
91 // Selector: setLimits(address,string) d05638cc
92 function setLimits(address collectionAddress, string memory limitsJson)
93 public
94 view
95 {
96 require(false, stub_error);
97 collectionAddress;
98 limitsJson;
99 dummy;
100 }
90}101}
91102
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
506}506}
507507
508#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]508#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
509#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
509pub enum MetaUpdatePermission {510pub enum MetaUpdatePermission {
510 ItemOwner,511 ItemOwner,
511 Admin,512 Admin,
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: d32d510415// Selector: 037b69c8
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(
46 string memory constOnChain46 string memory constOnChain
47 ) external view;47 ) external view;
48
49 // Selector: setLimits(address,string) d05638cc
50 function setLimits(address collectionAddress, string memory limitsJson)
51 external
52 view;
48}53}
4954
modifiedtests/src/eth/collectionAbi.jsondiffbeforeafterboth
37 "stateMutability": "view",37 "stateMutability": "view",
38 "type": "function"38 "type": "function"
39 },39 },
40 {
41 "inputs": [
42 {
43 "internalType": "address",
44 "name": "collectionAddress",
45 "type": "address"
46 },
47 { "internalType": "string", "name": "limitsJson", "type": "string" }
48 ],
49 "name": "setLimits",
50 "outputs": [],
51 "stateMutability": "view",
52 "type": "function"
53 },
40 {54 {
41 "inputs": [55 "inputs": [
42 {56 {
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
101 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constShema);101 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constShema);
102 });102 });
103
104 itWeb3('Set limits', async ({api, web3}) => {
105 const owner = await createEthAccountWithBalance(api, web3);
106 const helper = collectionHelper(web3, owner);
107 const result = await helper.methods.create721Collection('Const collection', '4', '4').send();
108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
109 const limits = {
110 accountTokenOwnershipLimit: 1000,
111 sponsoredDataSize: 1024,
112 // sponsoredDataRateLimit: { sponsoringDisabled: null },
113 tokenLimit: 1000000,
114 sponsorTransferTimeout: 6,
115 sponsorApproveTimeout: 6,
116 ownerCanTransfer: false,
117 ownerCanDestroy: false,
118 transfersEnabled: false,
119 };
120 const limitsJson = '{' +
121 '"account_token_ownership_limit": '+ limits.accountTokenOwnershipLimit +',' +
122 '"sponsored_data_size": ' + limits.sponsoredDataSize + ',' +
123 // '"sponsored_data_rate_limit": { sponsoringDisabled: null },' +
124 '"token_limit": ' + limits.tokenLimit + ',' +
125 '"sponsor_transfer_timeout": ' + limits.sponsorTransferTimeout + ',' +
126 '"sponsor_approve_timeout": ' + limits.sponsorApproveTimeout + ',' +
127 '"owner_can_transfer": ' + limits.ownerCanTransfer + ',' +
128 '"owner_can_destroy": ' + limits.ownerCanDestroy + ',' +
129 '"transfers_enabled": ' + limits.transfersEnabled +
130 '}';
131
132 await helper.methods.setLimits(collectionIdAddress, limitsJson).send();
133
134 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
135 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);
136 expect(collection.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);
137 expect(collection.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);
138 expect(collection.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);
139 expect(collection.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);
140 expect(collection.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);
141 expect(collection.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);
142 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);
143 });
103});144});