difftreelog
Added `set_properties` method for `TokenProperties` interface.
in: master
19 files changed
Cargo.lockdiffbeforeafterboth635863586359[[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",648064806481[[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",pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth385385386 /// 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()pallets/nonfungible/CHANGELOG.mddiffbeforeafterboth223All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.445<!-- bureaucrate goes here -->67## [v0.1.6] - 2022-20-1089### Change1011- Added `set_properties` method for `TokenProperties` interface.125## [v0.1.5] - 2022-08-2413## [v0.1.5] - 2022-08-246147### Change15### Change8 - Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.91610<!-- bureaucrate goes here -->17- Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.1811## [v0.1.4] 2022-08-1619## [v0.1.4] 2022-08-16122028- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b36- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b293730## [0.1.2] - 2022-07-2538## [0.1.2] - 2022-07-253931### Changed40### Changed4132- New `token_uri` retrieval logic:42- New `token_uri` retrieval logic:334334 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).405041## [0.1.1] - 2022-07-1451## [0.1.1] - 2022-07-145242### Added53### Added435444- 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.4758pallets/nonfungible/Cargo.tomldiffbeforeafterboth1[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"66pallets/nonfungible/src/erc.rsdiffbeforeafterboth114 .map_err(dispatch_to_evm::<T>)114 .map_err(dispatch_to_evm::<T>)115 }115 }116117 /// @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 properties121 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")?;129130 let nesting_budget = self131 .recorder132 .weight_calls_budget(<StructureWeight<T>>::find_parent());133134 let properties = properties135 .into_iter()136 .map(|(key, value)| {137 let key = <Vec<u8>>::from(key)138 .try_into()139 .map_err(|_| "key too large")?;140141 let value = value.0.try_into().map_err(|_| "value too large")?;142143 Ok(Property { key, value })144 })145 .collect::<Result<Vec<_>>>()?;146147 <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 }116157117 /// @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.pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth18}18}191920/// @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 0x55dba91922contract 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 }6364 /// @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 properties68 /// @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 }637664 /// @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.458471459 /// 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()pallets/refungible/CHANGELOG.mddiffbeforeafterboth223All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.445## [v0.2.5] - 2022-20-1067### Change89- Added `set_properties` method for `TokenProperties` interface.105## [v0.2.4] - 2022-08-2411## [v0.2.4] - 2022-08-246127### Change13### Change8 - Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.91415- Add bound `AsRef<[u8; 32]>` to `T::CrossAccountId`.1610<!-- bureaucrate goes here -->17<!-- bureaucrate goes here -->1811## [v0.2.3] 2022-08-1619## [v0.2.3] 2022-08-16122013### Other changes21### Other changespallets/refungible/Cargo.tomldiffbeforeafterboth1[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"66pallets/refungible/src/erc.rsdiffbeforeafterboth117 .map_err(dispatch_to_evm::<T>)117 .map_err(dispatch_to_evm::<T>)118 }118 }119120 /// @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 properties124 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")?;132133 let nesting_budget = self134 .recorder135 .weight_calls_budget(<StructureWeight<T>>::find_parent());136137 let properties = properties138 .into_iter()139 .map(|(key, value)| {140 let key = <Vec<u8>>::from(key)141 .try_into()142 .map_err(|_| "key too large")?;143144 let value = value.0.try_into().map_err(|_| "value too large")?;145146 Ok(Property { key, value })147 })148 .collect::<Result<Vec<_>>>()?;149150 <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 }119160120 /// @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.pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth18}18}191920/// @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 0x55dba91922contract 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 }6364 /// @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 properties68 /// @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 }637664 /// @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.458471459 /// 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()tests/src/eth/api/UniqueFungible.soldiffbeforeafterboth249249250 /// 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()tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth13}13}141415/// @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 0x55dba91917interface 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 value44 ) external;44 ) external;4546 /// @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 properties50 /// @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;455346 /// @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.298306299 /// 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()tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth13}13}141415/// @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 0x55dba91917interface 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 value44 ) external;44 ) external;4546 /// @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 properties50 /// @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;455346 /// @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.298306299 /// 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()tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth674 "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" },tests/src/eth/reFungibleAbi.jsondiffbeforeafterboth656 "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" },tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth161617import {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';192020describe('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});9293 const address = helper.ethAddress.fromCollectionId(collection.collectionId);94 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9596 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});9798 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});121122 const address = helper.ethAddress.fromCollectionId(collection.collectionId);123 const contract = helper.ethNativeContract.collection(address, 'rft', caller);124125 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});126127 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 });7113072 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);