git.delta.rocks / unique-network / refs/commits / 57a093883bee

difftreelog

Added `set_properties` method for `TokenProperties` interface.

PraetorP2022-10-24parent: #7125f4f.patch.diff
in: master

19 files changed

modifiedCargo.lockdiffbeforeafterboth
63586358
6359[[package]]6359[[package]]
6360name = "pallet-nonfungible"6360name = "pallet-nonfungible"
6361version = "0.1.5"6361version = "0.1.6"
6362dependencies = [6362dependencies = [
6363 "ethereum",6363 "ethereum",
6364 "evm-coder",6364 "evm-coder",
64806480
6481[[package]]6481[[package]]
6482name = "pallet-refungible"6482name = "pallet-refungible"
6483version = "0.2.4"6483version = "0.2.5"
6484dependencies = [6484dependencies = [
6485 "derivative",6485 "derivative",
6486 "ethereum",6486 "ethereum",
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
385385
386 /// Get collection owner.386 /// Get collection owner.
387 ///387 ///
388 /// @return Tuble with sponsor address and his substrate mirror.388 /// @return Tuple with sponsor address and his substrate mirror.
389 /// If address is canonical then substrate mirror is zero and vice versa.389 /// If address is canonical then substrate mirror is zero and vice versa.
390 /// @dev EVM selector for this function is: 0xdf727d3b,390 /// @dev EVM selector for this function is: 0xdf727d3b,
391 /// or in textual repr: collectionOwner()391 /// or in textual repr: collectionOwner()
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
22
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5<!-- bureaucrate goes here -->
6
7## [v0.1.6] - 2022-20-10
8
9### Change
10
11- Added `set_properties` method for `TokenProperties` interface.
12
5## [v0.1.5] - 2022-08-2413## [v0.1.5] - 2022-08-24
614
7### Change15### Change
8 - Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.
916
10<!-- bureaucrate goes here -->17- Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.
18
11## [v0.1.4] 2022-08-1619## [v0.1.4] 2022-08-16
1220
28- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b36- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
2937
30## [0.1.2] - 2022-07-2538## [0.1.2] - 2022-07-25
39
31### Changed40### Changed
41
32- New `token_uri` retrieval logic:42- New `token_uri` retrieval logic:
3343
34 If the collection has a `url` property and it is not empty, it is returned.44 If the collection has a `url` property and it is not empty, it is returned.
39 otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).49 otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
4050
41## [0.1.1] - 2022-07-1451## [0.1.1] - 2022-07-14
52
42### Added53### Added
4354
44- Implementation of RPC method `token_owners`.55- Implementation of RPC method `token_owners`.
45 For reasons of compatibility with this pallet, returns only one owner if token exists.56 For reasons of compatibility with this pallet, returns only one owner if token exists.
46 This was an internal request to improve the web interface and support fractionalization event.57 This was an internal request to improve the web interface and support fractionalization event.
4758
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
1[package]1[package]
2name = "pallet-nonfungible"2name = "pallet-nonfungible"
3version = "0.1.5"3version = "0.1.6"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
114 .map_err(dispatch_to_evm::<T>)114 .map_err(dispatch_to_evm::<T>)
115 }115 }
116
117 /// @notice Set token properties value.
118 /// @dev Throws error if `msg.sender` has no permission to edit the property.
119 /// @param tokenId ID of the token.
120 /// @param properties settable properties
121 fn set_properties(
122 &mut self,
123 caller: caller,
124 token_id: uint256,
125 properties: Vec<(string, bytes)>,
126 ) -> Result<()> {
127 let caller = T::CrossAccountId::from_eth(caller);
128 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
129
130 let nesting_budget = self
131 .recorder
132 .weight_calls_budget(<StructureWeight<T>>::find_parent());
133
134 let properties = properties
135 .into_iter()
136 .map(|(key, value)| {
137 let key = <Vec<u8>>::from(key)
138 .try_into()
139 .map_err(|_| "key too large")?;
140
141 let value = value.0.try_into().map_err(|_| "value too large")?;
142
143 Ok(Property { key, value })
144 })
145 .collect::<Result<Vec<_>>>()?;
146
147 <Pallet<T>>::set_token_properties(
148 self,
149 &caller,
150 TokenId(token_id),
151 properties.into_iter(),
152 <Pallet<T>>::token_exists(&self, TokenId(token_id)),
153 &nesting_budget,
154 )
155 .map_err(dispatch_to_evm::<T>)
156 }
116157
117 /// @notice Delete token property value.158 /// @notice Delete token property value.
118 /// @dev Throws error if `msg.sender` has no permission to edit the property.159 /// @dev Throws error if `msg.sender` has no permission to edit the property.
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
18}18}
1919
20/// @title A contract that allows to set and delete token properties and change token property permissions.20/// @title A contract that allows to set and delete token properties and change token property permissions.
21/// @dev the ERC-165 identifier for this interface is 0x4136937721/// @dev the ERC-165 identifier for this interface is 0x55dba919
22contract TokenProperties is Dummy, ERC165 {22contract TokenProperties is Dummy, ERC165 {
23 /// @notice Set permissions for token property.23 /// @notice Set permissions for token property.
24 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.24 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
61 dummy = 0;61 dummy = 0;
62 }62 }
63
64 /// @notice Set token properties value.
65 /// @dev Throws error if `msg.sender` has no permission to edit the property.
66 /// @param tokenId ID of the token.
67 /// @param properties settable properties
68 /// @dev EVM selector for this function is: 0x14ed3a6e,
69 /// or in textual repr: setProperties(uint256,(string,bytes)[])
70 function setProperties(uint256 tokenId, Tuple19[] memory properties) public {
71 require(false, stub_error);
72 tokenId;
73 properties;
74 dummy = 0;
75 }
6376
64 /// @notice Delete token property value.77 /// @notice Delete token property value.
65 /// @dev Throws error if `msg.sender` has no permission to edit the property.78 /// @dev Throws error if `msg.sender` has no permission to edit the property.
458471
459 /// Get collection owner.472 /// Get collection owner.
460 ///473 ///
461 /// @return Tuble with sponsor address and his substrate mirror.474 /// @return Tuple with sponsor address and his substrate mirror.
462 /// If address is canonical then substrate mirror is zero and vice versa.475 /// If address is canonical then substrate mirror is zero and vice versa.
463 /// @dev EVM selector for this function is: 0xdf727d3b,476 /// @dev EVM selector for this function is: 0xdf727d3b,
464 /// or in textual repr: collectionOwner()477 /// or in textual repr: collectionOwner()
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
22
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5## [v0.2.5] - 2022-20-10
6
7### Change
8
9- Added `set_properties` method for `TokenProperties` interface.
10
5## [v0.2.4] - 2022-08-2411## [v0.2.4] - 2022-08-24
612
7### Change13### Change
8 - Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.
914
15- Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.
16
10<!-- bureaucrate goes here -->17<!-- bureaucrate goes here -->
18
11## [v0.2.3] 2022-08-1619## [v0.2.3] 2022-08-16
1220
13### Other changes21### Other changes
modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
1[package]1[package]
2name = "pallet-refungible"2name = "pallet-refungible"
3version = "0.2.4"3version = "0.2.5"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
117 .map_err(dispatch_to_evm::<T>)117 .map_err(dispatch_to_evm::<T>)
118 }118 }
119
120 /// @notice Set token properties value.
121 /// @dev Throws error if `msg.sender` has no permission to edit the property.
122 /// @param tokenId ID of the token.
123 /// @param properties settable properties
124 fn set_properties(
125 &mut self,
126 caller: caller,
127 token_id: uint256,
128 properties: Vec<(string, bytes)>,
129 ) -> Result<()> {
130 let caller = T::CrossAccountId::from_eth(caller);
131 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
132
133 let nesting_budget = self
134 .recorder
135 .weight_calls_budget(<StructureWeight<T>>::find_parent());
136
137 let properties = properties
138 .into_iter()
139 .map(|(key, value)| {
140 let key = <Vec<u8>>::from(key)
141 .try_into()
142 .map_err(|_| "key too large")?;
143
144 let value = value.0.try_into().map_err(|_| "value too large")?;
145
146 Ok(Property { key, value })
147 })
148 .collect::<Result<Vec<_>>>()?;
149
150 <Pallet<T>>::set_token_properties(
151 self,
152 &caller,
153 TokenId(token_id),
154 properties.into_iter(),
155 <Pallet<T>>::token_exists(&self, TokenId(token_id)),
156 &nesting_budget,
157 )
158 .map_err(dispatch_to_evm::<T>)
159 }
119160
120 /// @notice Delete token property value.161 /// @notice Delete token property value.
121 /// @dev Throws error if `msg.sender` has no permission to edit the property.162 /// @dev Throws error if `msg.sender` has no permission to edit the property.
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
18}18}
1919
20/// @title A contract that allows to set and delete token properties and change token property permissions.20/// @title A contract that allows to set and delete token properties and change token property permissions.
21/// @dev the ERC-165 identifier for this interface is 0x4136937721/// @dev the ERC-165 identifier for this interface is 0x55dba919
22contract TokenProperties is Dummy, ERC165 {22contract TokenProperties is Dummy, ERC165 {
23 /// @notice Set permissions for token property.23 /// @notice Set permissions for token property.
24 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.24 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
61 dummy = 0;61 dummy = 0;
62 }62 }
63
64 /// @notice Set token properties value.
65 /// @dev Throws error if `msg.sender` has no permission to edit the property.
66 /// @param tokenId ID of the token.
67 /// @param properties settable properties
68 /// @dev EVM selector for this function is: 0x14ed3a6e,
69 /// or in textual repr: setProperties(uint256,(string,bytes)[])
70 function setProperties(uint256 tokenId, Tuple19[] memory properties) public {
71 require(false, stub_error);
72 tokenId;
73 properties;
74 dummy = 0;
75 }
6376
64 /// @notice Delete token property value.77 /// @notice Delete token property value.
65 /// @dev Throws error if `msg.sender` has no permission to edit the property.78 /// @dev Throws error if `msg.sender` has no permission to edit the property.
458471
459 /// Get collection owner.472 /// Get collection owner.
460 ///473 ///
461 /// @return Tuble with sponsor address and his substrate mirror.474 /// @return Tuple with sponsor address and his substrate mirror.
462 /// If address is canonical then substrate mirror is zero and vice versa.475 /// If address is canonical then substrate mirror is zero and vice versa.
463 /// @dev EVM selector for this function is: 0xdf727d3b,476 /// @dev EVM selector for this function is: 0xdf727d3b,
464 /// or in textual repr: collectionOwner()477 /// or in textual repr: collectionOwner()
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
249249
250 /// Get collection owner.250 /// Get collection owner.
251 ///251 ///
252 /// @return Tuble with sponsor address and his substrate mirror.252 /// @return Tuple with sponsor address and his substrate mirror.
253 /// If address is canonical then substrate mirror is zero and vice versa.253 /// If address is canonical then substrate mirror is zero and vice versa.
254 /// @dev EVM selector for this function is: 0xdf727d3b,254 /// @dev EVM selector for this function is: 0xdf727d3b,
255 /// or in textual repr: collectionOwner()255 /// or in textual repr: collectionOwner()
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
13}13}
1414
15/// @title A contract that allows to set and delete token properties and change token property permissions.15/// @title A contract that allows to set and delete token properties and change token property permissions.
16/// @dev the ERC-165 identifier for this interface is 0x4136937716/// @dev the ERC-165 identifier for this interface is 0x55dba919
17interface TokenProperties is Dummy, ERC165 {17interface TokenProperties is Dummy, ERC165 {
18 /// @notice Set permissions for token property.18 /// @notice Set permissions for token property.
19 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.19 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
43 bytes memory value43 bytes memory value
44 ) external;44 ) external;
45
46 /// @notice Set token properties value.
47 /// @dev Throws error if `msg.sender` has no permission to edit the property.
48 /// @param tokenId ID of the token.
49 /// @param properties settable properties
50 /// @dev EVM selector for this function is: 0x14ed3a6e,
51 /// or in textual repr: setProperties(uint256,(string,bytes)[])
52 function setProperties(uint256 tokenId, Tuple19[] memory properties) external;
4553
46 /// @notice Delete token property value.54 /// @notice Delete token property value.
47 /// @dev Throws error if `msg.sender` has no permission to edit the property.55 /// @dev Throws error if `msg.sender` has no permission to edit the property.
298306
299 /// Get collection owner.307 /// Get collection owner.
300 ///308 ///
301 /// @return Tuble with sponsor address and his substrate mirror.309 /// @return Tuple with sponsor address and his substrate mirror.
302 /// If address is canonical then substrate mirror is zero and vice versa.310 /// If address is canonical then substrate mirror is zero and vice versa.
303 /// @dev EVM selector for this function is: 0xdf727d3b,311 /// @dev EVM selector for this function is: 0xdf727d3b,
304 /// or in textual repr: collectionOwner()312 /// or in textual repr: collectionOwner()
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
13}13}
1414
15/// @title A contract that allows to set and delete token properties and change token property permissions.15/// @title A contract that allows to set and delete token properties and change token property permissions.
16/// @dev the ERC-165 identifier for this interface is 0x4136937716/// @dev the ERC-165 identifier for this interface is 0x55dba919
17interface TokenProperties is Dummy, ERC165 {17interface TokenProperties is Dummy, ERC165 {
18 /// @notice Set permissions for token property.18 /// @notice Set permissions for token property.
19 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.19 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
43 bytes memory value43 bytes memory value
44 ) external;44 ) external;
45
46 /// @notice Set token properties value.
47 /// @dev Throws error if `msg.sender` has no permission to edit the property.
48 /// @param tokenId ID of the token.
49 /// @param properties settable properties
50 /// @dev EVM selector for this function is: 0x14ed3a6e,
51 /// or in textual repr: setProperties(uint256,(string,bytes)[])
52 function setProperties(uint256 tokenId, Tuple19[] memory properties) external;
4553
46 /// @notice Delete token property value.54 /// @notice Delete token property value.
47 /// @dev Throws error if `msg.sender` has no permission to edit the property.55 /// @dev Throws error if `msg.sender` has no permission to edit the property.
298306
299 /// Get collection owner.307 /// Get collection owner.
300 ///308 ///
301 /// @return Tuble with sponsor address and his substrate mirror.309 /// @return Tuple with sponsor address and his substrate mirror.
302 /// If address is canonical then substrate mirror is zero and vice versa.310 /// If address is canonical then substrate mirror is zero and vice versa.
303 /// @dev EVM selector for this function is: 0xdf727d3b,311 /// @dev EVM selector for this function is: 0xdf727d3b,
304 /// or in textual repr: collectionOwner()312 /// or in textual repr: collectionOwner()
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
674 "stateMutability": "nonpayable",674 "stateMutability": "nonpayable",
675 "type": "function"675 "type": "function"
676 },676 },
677 {
678 "inputs": [
679 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
680 {
681 "components": [
682 { "internalType": "string", "name": "field_0", "type": "string" },
683 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
684 ],
685 "internalType": "struct Tuple19[]",
686 "name": "properties",
687 "type": "tuple[]"
688 }
689 ],
690 "name": "setProperties",
691 "outputs": [],
692 "stateMutability": "nonpayable",
693 "type": "function"
694 },
677 {695 {
678 "inputs": [696 "inputs": [
679 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },697 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
modifiedtests/src/eth/reFungibleAbi.jsondiffbeforeafterboth
656 "stateMutability": "nonpayable",656 "stateMutability": "nonpayable",
657 "type": "function"657 "type": "function"
658 },658 },
659 {
660 "inputs": [
661 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
662 {
663 "components": [
664 { "internalType": "string", "name": "field_0", "type": "string" },
665 { "internalType": "bytes", "name": "field_1", "type": "bytes" }
666 ],
667 "internalType": "struct Tuple19[]",
668 "name": "properties",
669 "type": "tuple[]"
670 }
671 ],
672 "name": "setProperties",
673 "outputs": [],
674 "stateMutability": "nonpayable",
675 "type": "function"
676 },
659 {677 {
660 "inputs": [678 "inputs": [
661 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },679 { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
modifiedtests/src/eth/tokenProperties.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 {ITokenPropertyPermission} from '../util/playgrounds/types';
1920
20describe('EVM token properties', () => {21describe('EVM token properties', () => {
21 let donor: IKeyringPair;22 let donor: IKeyringPair;
69 expect(value).to.equal('testValue');70 expect(value).to.equal('testValue');
70 });71 });
72
73 itEth('Can be multiple set for NFT ', async({helper}) => {
74 const caller = await helper.eth.createAccountWithBalance(donor);
75
76 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });
77 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,
78 collectionAdmin: true,
79 mutable: true}}; });
80
81 const collection = await helper.nft.mintCollection(alice, {
82 tokenPrefix: 'ethp',
83 tokenPropertyPermissions: permissions,
84 });
85
86 const token = await collection.mintToken(alice);
87
88 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));
89 expect(valuesBefore).to.be.deep.equal([]);
90
91 await collection.addAdmin(alice, {Ethereum: caller});
92
93 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
94 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
95
96 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});
97
98 const values = await token.getProperties(properties.map(p => p.field_0));
99 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));
100 });
101
102 itEth('Can be multiple set for RFT ', async({helper}) => {
103 const caller = await helper.eth.createAccountWithBalance(donor);
104
105 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });
106 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,
107 collectionAdmin: true,
108 mutable: true}}; });
109
110 const collection = await helper.rft.mintCollection(alice, {
111 tokenPrefix: 'ethp',
112 tokenPropertyPermissions: permissions,
113 });
114
115 const token = await collection.mintToken(alice);
116
117 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));
118 expect(valuesBefore).to.be.deep.equal([]);
119
120 await collection.addAdmin(alice, {Ethereum: caller});
121
122 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
123 const contract = helper.ethNativeContract.collection(address, 'rft', caller);
124
125 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});
126
127 const values = await token.getProperties(properties.map(p => p.field_0));
128 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));
129 });
71130
72 itEth('Can be deleted', async({helper}) => {131 itEth('Can be deleted', async({helper}) => {
73 const caller = await helper.eth.createAccountWithBalance(donor);132 const caller = await helper.eth.createAccountWithBalance(donor);