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

difftreelog

feat add eth methots for bulk properties

Trubnikov Sergey2022-10-24parent: #0321433.patch.diff
in: master

14 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
27use sp_std::vec::Vec;27use sp_std::vec::Vec;
28use up_data_structs::{28use up_data_structs::{
29 AccessMode, CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property,29 AccessMode, CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property,
30 SponsoringRateLimit, SponsorshipState,30 SponsoringRateLimit, SponsorshipState, PropertyKey,
31};31};
32use alloc::format;32use alloc::format;
3333
97 .map_err(dispatch_to_evm::<T>)97 .map_err(dispatch_to_evm::<T>)
98 }98 }
99
100 /// Set collection properties.
101 ///
102 /// @param properties Vector of properties key/value pair.
103 #[weight(<SelfWeightOf<T>>::set_collection_properties(properties.len() as u32))]
104 fn set_collection_properties(
105 &mut self,
106 caller: caller,
107 properties: Vec<(string, bytes)>,
108 ) -> Result<void> {
109 for (key, value) in properties.into_iter() {
110 self.set_collection_property(caller, key, value)?;
111 }
112 Ok(())
113 }
99114
100 /// Delete collection property.115 /// Delete collection property.
101 ///116 ///
123 .try_into()138 .try_into()
124 .map_err(|_| "key too large")?;139 .map_err(|_| "key too large")?;
125140
126 let props = <CollectionProperties<T>>::get(self.id);141 let props = CollectionProperties::<T>::get(self.id);
127 let prop = props.get(&key).ok_or("key not found")?;142 let prop = props.get(&key).ok_or("key not found")?;
128143
129 Ok(bytes(prop.to_vec()))144 Ok(bytes(prop.to_vec()))
130 }145 }
146
147 /// Get collection properties.
148 ///
149 /// @param keys Properties keys.
150 /// @return Vector of properties key/value pairs.
151 fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<(string, bytes)>> {
152 let mut keys_ = Vec::<PropertyKey>::with_capacity(keys.len());
153 for key in keys {
154 keys_.push(
155 <Vec<u8>>::from(key)
156 .try_into()
157 .map_err(|_| Error::Revert("key too large".into()))?,
158 )
159 }
160 let properties = Pallet::<T>::filter_collection_properties(self.id, Some(keys_))
161 .map_err(dispatch_to_evm::<T>)?;
162
163 let mut properties_ = Vec::<(string, bytes)>::with_capacity(properties.len());
164 for p in properties {
165 let key =
166 string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;
167 let value = bytes(p.value.to_vec());
168 properties_.push((key, value));
169 }
170 Ok(properties_)
171 }
131172
132 /// Set the sponsor of the collection.173 /// Set the sponsor of the collection.
133 ///174 ///
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
18}18}
1919
20/// @title A contract that allows you to work with collections.20/// @title A contract that allows you to work with collections.
21/// @dev the ERC-165 identifier for this interface is 0x25d897dc21/// @dev the ERC-165 identifier for this interface is 0x5d354410
22contract Collection is Dummy, ERC165 {22contract Collection is Dummy, ERC165 {
23 /// Set collection property.23 /// Set collection property.
24 ///24 ///
33 dummy = 0;33 dummy = 0;
34 }34 }
35
36 /// Set collection properties.
37 ///
38 /// @param properties Vector of properties key/value pair.
39 /// @dev EVM selector for this function is: 0x50b26b2a,
40 /// or in textual repr: setCollectionProperties((string,bytes)[])
41 function setCollectionProperties(Tuple10[] memory properties) public {
42 require(false, stub_error);
43 properties;
44 dummy = 0;
45 }
3546
36 /// Delete collection property.47 /// Delete collection property.
37 ///48 ///
59 return hex"";70 return hex"";
60 }71 }
72
73 /// Get collection properties.
74 ///
75 /// @param keys Properties keys.
76 /// @return Vector of properties key/value pairs.
77 /// @dev EVM selector for this function is: 0x285fb8e6,
78 /// or in textual repr: collectionProperties(string[])
79 function collectionProperties(string[] memory keys) public view returns (Tuple10[] memory) {
80 require(false, stub_error);
81 keys;
82 dummy;
83 return new Tuple10[](0);
84 }
6185
62 /// Set the sponsor of the collection.86 /// Set the sponsor of the collection.
63 ///87 ///
397 }421 }
398}422}
423
424/// @dev anonymous struct
425struct Tuple10 {
426 string field_0;
427 bytes field_1;
428}
399429
400/// @dev the ERC-165 identifier for this interface is 0x032e5926430/// @dev the ERC-165 identifier for this interface is 0x032e5926
401contract ERC20UniqueExtensions is Dummy, ERC165 {431contract ERC20UniqueExtensions is Dummy, ERC165 {
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
91}91}
9292
93/// @title A contract that allows you to work with collections.93/// @title A contract that allows you to work with collections.
94/// @dev the ERC-165 identifier for this interface is 0x25d897dc94/// @dev the ERC-165 identifier for this interface is 0x5d354410
95contract Collection is Dummy, ERC165 {95contract Collection is Dummy, ERC165 {
96 /// Set collection property.96 /// Set collection property.
97 ///97 ///
106 dummy = 0;106 dummy = 0;
107 }107 }
108
109 /// Set collection properties.
110 ///
111 /// @param properties Vector of properties key/value pair.
112 /// @dev EVM selector for this function is: 0x50b26b2a,
113 /// or in textual repr: setCollectionProperties((string,bytes)[])
114 function setCollectionProperties(Tuple19[] memory properties) public {
115 require(false, stub_error);
116 properties;
117 dummy = 0;
118 }
108119
109 /// Delete collection property.120 /// Delete collection property.
110 ///121 ///
132 return hex"";143 return hex"";
133 }144 }
145
146 /// Get collection properties.
147 ///
148 /// @param keys Properties keys.
149 /// @return Vector of properties key/value pairs.
150 /// @dev EVM selector for this function is: 0x285fb8e6,
151 /// or in textual repr: collectionProperties(string[])
152 function collectionProperties(string[] memory keys) public view returns (Tuple19[] memory) {
153 require(false, stub_error);
154 keys;
155 dummy;
156 return new Tuple19[](0);
157 }
134158
135 /// Set the sponsor of the collection.159 /// Set the sponsor of the collection.
136 ///160 ///
470 }494 }
471}495}
496
497/// @dev anonymous struct
498struct Tuple19 {
499 string field_0;
500 bytes field_1;
501}
472502
473/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension503/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
474/// @dev See https://eips.ethereum.org/EIPS/eip-721504/// @dev See https://eips.ethereum.org/EIPS/eip-721
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
91}91}
9292
93/// @title A contract that allows you to work with collections.93/// @title A contract that allows you to work with collections.
94/// @dev the ERC-165 identifier for this interface is 0x25d897dc94/// @dev the ERC-165 identifier for this interface is 0x5d354410
95contract Collection is Dummy, ERC165 {95contract Collection is Dummy, ERC165 {
96 /// Set collection property.96 /// Set collection property.
97 ///97 ///
106 dummy = 0;106 dummy = 0;
107 }107 }
108
109 /// Set collection properties.
110 ///
111 /// @param properties Vector of properties key/value pair.
112 /// @dev EVM selector for this function is: 0x50b26b2a,
113 /// or in textual repr: setCollectionProperties((string,bytes)[])
114 function setCollectionProperties(Tuple19[] memory properties) public {
115 require(false, stub_error);
116 properties;
117 dummy = 0;
118 }
108119
109 /// Delete collection property.120 /// Delete collection property.
110 ///121 ///
132 return hex"";143 return hex"";
133 }144 }
145
146 /// Get collection properties.
147 ///
148 /// @param keys Properties keys.
149 /// @return Vector of properties key/value pairs.
150 /// @dev EVM selector for this function is: 0x285fb8e6,
151 /// or in textual repr: collectionProperties(string[])
152 function collectionProperties(string[] memory keys) public view returns (Tuple19[] memory) {
153 require(false, stub_error);
154 keys;
155 dummy;
156 return new Tuple19[](0);
157 }
134158
135 /// Set the sponsor of the collection.159 /// Set the sponsor of the collection.
136 ///160 ///
470 }494 }
471}495}
496
497/// @dev anonymous struct
498struct Tuple19 {
499 string field_0;
500 bytes field_1;
501}
472502
473/// @dev the ERC-165 identifier for this interface is 0x5b5e139f503/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
474contract ERC721Metadata is Dummy, ERC165 {504contract ERC721Metadata is Dummy, ERC165 {
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
13}13}
1414
15/// @title A contract that allows you to work with collections.15/// @title A contract that allows you to work with collections.
16/// @dev the ERC-165 identifier for this interface is 0x25d897dc16/// @dev the ERC-165 identifier for this interface is 0x5d354410
17interface Collection is Dummy, ERC165 {17interface Collection is Dummy, ERC165 {
18 /// Set collection property.18 /// Set collection property.
19 ///19 ///
23 /// or in textual repr: setCollectionProperty(string,bytes)23 /// or in textual repr: setCollectionProperty(string,bytes)
24 function setCollectionProperty(string memory key, bytes memory value) external;24 function setCollectionProperty(string memory key, bytes memory value) external;
25
26 /// Set collection properties.
27 ///
28 /// @param properties Vector of properties key/value pair.
29 /// @dev EVM selector for this function is: 0x50b26b2a,
30 /// or in textual repr: setCollectionProperties((string,bytes)[])
31 function setCollectionProperties(Tuple10[] memory properties) external;
2532
26 /// Delete collection property.33 /// Delete collection property.
27 ///34 ///
40 /// or in textual repr: collectionProperty(string)47 /// or in textual repr: collectionProperty(string)
41 function collectionProperty(string memory key) external view returns (bytes memory);48 function collectionProperty(string memory key) external view returns (bytes memory);
49
50 /// Get collection properties.
51 ///
52 /// @param keys Properties keys.
53 /// @return Vector of properties key/value pairs.
54 /// @dev EVM selector for this function is: 0x285fb8e6,
55 /// or in textual repr: collectionProperties(string[])
56 function collectionProperties(string[] memory keys) external view returns (Tuple10[] memory);
4257
43 /// Set the sponsor of the collection.58 /// Set the sponsor of the collection.
44 ///59 ///
258 function setOwnerCross(Tuple6 memory newOwner) external;273 function setOwnerCross(Tuple6 memory newOwner) external;
259}274}
275
276/// @dev anonymous struct
277struct Tuple10 {
278 string field_0;
279 bytes field_1;
280}
260281
261/// @dev the ERC-165 identifier for this interface is 0x032e5926282/// @dev the ERC-165 identifier for this interface is 0x032e5926
262interface ERC20UniqueExtensions is Dummy, ERC165 {283interface ERC20UniqueExtensions is Dummy, ERC165 {
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
62}62}
6363
64/// @title A contract that allows you to work with collections.64/// @title A contract that allows you to work with collections.
65/// @dev the ERC-165 identifier for this interface is 0x25d897dc65/// @dev the ERC-165 identifier for this interface is 0x5d354410
66interface Collection is Dummy, ERC165 {66interface Collection is Dummy, ERC165 {
67 /// Set collection property.67 /// Set collection property.
68 ///68 ///
72 /// or in textual repr: setCollectionProperty(string,bytes)72 /// or in textual repr: setCollectionProperty(string,bytes)
73 function setCollectionProperty(string memory key, bytes memory value) external;73 function setCollectionProperty(string memory key, bytes memory value) external;
74
75 /// Set collection properties.
76 ///
77 /// @param properties Vector of properties key/value pair.
78 /// @dev EVM selector for this function is: 0x50b26b2a,
79 /// or in textual repr: setCollectionProperties((string,bytes)[])
80 function setCollectionProperties(Tuple19[] memory properties) external;
7481
75 /// Delete collection property.82 /// Delete collection property.
76 ///83 ///
89 /// or in textual repr: collectionProperty(string)96 /// or in textual repr: collectionProperty(string)
90 function collectionProperty(string memory key) external view returns (bytes memory);97 function collectionProperty(string memory key) external view returns (bytes memory);
98
99 /// Get collection properties.
100 ///
101 /// @param keys Properties keys.
102 /// @return Vector of properties key/value pairs.
103 /// @dev EVM selector for this function is: 0x285fb8e6,
104 /// or in textual repr: collectionProperties(string[])
105 function collectionProperties(string[] memory keys) external view returns (Tuple19[] memory);
91106
92 /// Set the sponsor of the collection.107 /// Set the sponsor of the collection.
93 ///108 ///
307 function setOwnerCross(Tuple6 memory newOwner) external;322 function setOwnerCross(Tuple6 memory newOwner) external;
308}323}
324
325/// @dev anonymous struct
326struct Tuple19 {
327 string field_0;
328 bytes field_1;
329}
309330
310/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension331/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
311/// @dev See https://eips.ethereum.org/EIPS/eip-721332/// @dev See https://eips.ethereum.org/EIPS/eip-721
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
62}62}
6363
64/// @title A contract that allows you to work with collections.64/// @title A contract that allows you to work with collections.
65/// @dev the ERC-165 identifier for this interface is 0x25d897dc65/// @dev the ERC-165 identifier for this interface is 0x5d354410
66interface Collection is Dummy, ERC165 {66interface Collection is Dummy, ERC165 {
67 /// Set collection property.67 /// Set collection property.
68 ///68 ///
72 /// or in textual repr: setCollectionProperty(string,bytes)72 /// or in textual repr: setCollectionProperty(string,bytes)
73 function setCollectionProperty(string memory key, bytes memory value) external;73 function setCollectionProperty(string memory key, bytes memory value) external;
74
75 /// Set collection properties.
76 ///
77 /// @param properties Vector of properties key/value pair.
78 /// @dev EVM selector for this function is: 0x50b26b2a,
79 /// or in textual repr: setCollectionProperties((string,bytes)[])
80 function setCollectionProperties(Tuple19[] memory properties) external;
7481
75 /// Delete collection property.82 /// Delete collection property.
76 ///83 ///
89 /// or in textual repr: collectionProperty(string)96 /// or in textual repr: collectionProperty(string)
90 function collectionProperty(string memory key) external view returns (bytes memory);97 function collectionProperty(string memory key) external view returns (bytes memory);
98
99 /// Get collection properties.
100 ///
101 /// @param keys Properties keys.
102 /// @return Vector of properties key/value pairs.
103 /// @dev EVM selector for this function is: 0x285fb8e6,
104 /// or in textual repr: collectionProperties(string[])
105 function collectionProperties(string[] memory keys) external view returns (Tuple19[] memory);
91106
92 /// Set the sponsor of the collection.107 /// Set the sponsor of the collection.
93 ///108 ///
307 function setOwnerCross(Tuple6 memory newOwner) external;322 function setOwnerCross(Tuple6 memory newOwner) external;
308}323}
324
325/// @dev anonymous struct
326struct Tuple19 {
327 string field_0;
328 bytes field_1;
329}
309330
310/// @dev the ERC-165 identifier for this interface is 0x5b5e139f331/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
311interface ERC721Metadata is Dummy, ERC165 {332interface ERC721Metadata is Dummy, ERC165 {
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
162 });162 });
163});163});
164
165describe('EVM collection property', () => {
166 itEth('Set/read properties', async ({helper, privateKey}) => {
167 const alice = await privateKey('//Alice');
168 const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
169
170 const sender = await helper.eth.createAccountWithBalance(alice, 100n);
171 await collection.addAdmin(alice, {Ethereum: sender});
172
173 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
174 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);
175
176 const key1 = 'key1';
177 const value1 = Buffer.from('value1');
178
179 const key2 = 'key2';
180 const value2 = Buffer.from('value2');
181
182 const writeProperties = [
183 [key1, '0x'+value1.toString('hex')],
184 [key2, '0x'+value2.toString('hex')],
185 ];
186
187 await contract.methods.setCollectionProperties(writeProperties).send();
188 const readProperties = await contract.methods.collectionProperties([key1, key2]).call();
189 expect(readProperties).to.be.like(writeProperties);
190 });
191});
164192
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
228 "stateMutability": "view",228 "stateMutability": "view",
229 "type": "function"229 "type": "function"
230 },230 },
231 {
232 "inputs": [
233 { "internalType": "string[]", "name": "keys", "type": "string[]" }
234 ],
235 "name": "collectionProperties",
236 "outputs": [
237 {
238 "components": [
239 { "internalType": "string", "name": "field_0", "type": "string" },
240 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
241 ],
242 "internalType": "struct Tuple10[]",
243 "name": "",
244 "type": "tuple[]"
245 }
246 ],
247 "stateMutability": "view",
248 "type": "function"
249 },
231 {250 {
232 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],251 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
233 "name": "collectionProperty",252 "name": "collectionProperty",
461 "stateMutability": "nonpayable",480 "stateMutability": "nonpayable",
462 "type": "function"481 "type": "function"
463 },482 },
483 {
484 "inputs": [
485 {
486 "components": [
487 { "internalType": "string", "name": "field_0", "type": "string" },
488 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
489 ],
490 "internalType": "struct Tuple10[]",
491 "name": "properties",
492 "type": "tuple[]"
493 }
494 ],
495 "name": "setCollectionProperties",
496 "outputs": [],
497 "stateMutability": "nonpayable",
498 "type": "function"
499 },
464 {500 {
465 "inputs": [501 "inputs": [
466 { "internalType": "string", "name": "key", "type": "string" },502 { "internalType": "string", "name": "key", "type": "string" },
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
258 "stateMutability": "view",258 "stateMutability": "view",
259 "type": "function"259 "type": "function"
260 },260 },
261 {
262 "inputs": [
263 { "internalType": "string[]", "name": "keys", "type": "string[]" }
264 ],
265 "name": "collectionProperties",
266 "outputs": [
267 {
268 "components": [
269 { "internalType": "string", "name": "field_0", "type": "string" },
270 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
271 ],
272 "internalType": "struct Tuple19[]",
273 "name": "",
274 "type": "tuple[]"
275 }
276 ],
277 "stateMutability": "view",
278 "type": "function"
279 },
261 {280 {
262 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],281 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
263 "name": "collectionProperty",282 "name": "collectionProperty",
576 "stateMutability": "nonpayable",595 "stateMutability": "nonpayable",
577 "type": "function"596 "type": "function"
578 },597 },
598 {
599 "inputs": [
600 {
601 "components": [
602 { "internalType": "string", "name": "field_0", "type": "string" },
603 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
604 ],
605 "internalType": "struct Tuple19[]",
606 "name": "properties",
607 "type": "tuple[]"
608 }
609 ],
610 "name": "setCollectionProperties",
611 "outputs": [],
612 "stateMutability": "nonpayable",
613 "type": "function"
614 },
579 {615 {
580 "inputs": [616 "inputs": [
581 { "internalType": "string", "name": "key", "type": "string" },617 { "internalType": "string", "name": "key", "type": "string" },
modifiedtests/src/eth/reFungibleAbi.jsondiffbeforeafterboth
240 "stateMutability": "view",240 "stateMutability": "view",
241 "type": "function"241 "type": "function"
242 },242 },
243 {
244 "inputs": [
245 { "internalType": "string[]", "name": "keys", "type": "string[]" }
246 ],
247 "name": "collectionProperties",
248 "outputs": [
249 {
250 "components": [
251 { "internalType": "string", "name": "field_0", "type": "string" },
252 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
253 ],
254 "internalType": "struct Tuple19[]",
255 "name": "",
256 "type": "tuple[]"
257 }
258 ],
259 "stateMutability": "view",
260 "type": "function"
261 },
243 {262 {
244 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],263 "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
245 "name": "collectionProperty",264 "name": "collectionProperty",
558 "stateMutability": "nonpayable",577 "stateMutability": "nonpayable",
559 "type": "function"578 "type": "function"
560 },579 },
580 {
581 "inputs": [
582 {
583 "components": [
584 { "internalType": "string", "name": "field_0", "type": "string" },
585 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
586 ],
587 "internalType": "struct Tuple19[]",
588 "name": "properties",
589 "type": "tuple[]"
590 }
591 ],
592 "name": "setCollectionProperties",
593 "outputs": [],
594 "stateMutability": "nonpayable",
595 "type": "function"
596 },
561 {597 {
562 "inputs": [598 "inputs": [
563 { "internalType": "string", "name": "key", "type": "string" },599 { "internalType": "string", "name": "key", "type": "string" },