git.delta.rocks / unique-network / refs/commits / 39430dd15dad

difftreelog

Merge pull request #897 from UniqueNetwork/feature/impl_getApproved

Yaroslav Bolyukin2023-03-30parents: #2df4b51 #0361756.patch.diff
in: master

6 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
515 Ok(())515 Ok(())
516 }516 }
517517
518 /// @dev Not implemented518 /// @notice Get the approved address for a single NFT
519 /// @dev Throws if `tokenId` is not a valid NFT
520 /// @param tokenId The NFT to find the approved address for
521 /// @return The approved address for this NFT, or the zero address if there is none
519 fn get_approved(&self, _token_id: U256) -> Result<Address> {522 fn get_approved(&self, token_id: U256) -> Result<Address> {
520 // TODO: Not implemetable523 let token_id = token_id.try_into()?;
524 let operator = <Pallet<T>>::get_allowance(self, token_id).map_err(dispatch_to_evm::<T>)?;
521 Err("not implemented".into())525 Ok(if let Some(operator) = operator {
526 *operator.as_eth()
527 } else {
528 Address::zero()
529 })
522 }530 }
523531
524 /// @notice Tells whether the given `owner` approves the `operator`.532 /// @notice Tells whether the given `owner` approves the `operator`.
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
1082 }1082 }
1083 }1083 }
1084
1085 pub fn get_allowance(
1086 collection: &NonfungibleHandle<T>,
1087 token_id: TokenId,
1088 ) -> Result<Option<T::CrossAccountId>, DispatchError> {
1089 ensure!(
1090 <TokenData<T>>::get((collection.id, token_id)).is_some(),
1091 <CommonError<T>>::TokenNotFound
1092 );
1093 Ok(<Allowance<T>>::get((collection.id, token_id)))
1094 }
10841095
1085 /// Set allowance for the spender to `transfer` or `burn` sender's token.1096 /// Set allowance for the spender to `transfer` or `burn` sender's token.
1086 ///1097 ///
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
1156 dummy = 0;1156 dummy = 0;
1157 }1157 }
11581158
1159 /// @dev Not implemented1159 /// @notice Get the approved address for a single NFT
1160 /// @dev Throws if `tokenId` is not a valid NFT
1161 /// @param tokenId The NFT to find the approved address for
1162 /// @return The approved address for this NFT, or the zero address if there is none
1160 /// @dev EVM selector for this function is: 0x081812fc,1163 /// @dev EVM selector for this function is: 0x081812fc,
1161 /// or in textual repr: getApproved(uint256)1164 /// or in textual repr: getApproved(uint256)
1162 function getApproved(uint256 tokenId) public view returns (address) {1165 function getApproved(uint256 tokenId) public view returns (address) {
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
781 /// or in textual repr: setApprovalForAll(address,bool)781 /// or in textual repr: setApprovalForAll(address,bool)
782 function setApprovalForAll(address operator, bool approved) external;782 function setApprovalForAll(address operator, bool approved) external;
783783
784 /// @dev Not implemented784 /// @notice Get the approved address for a single NFT
785 /// @dev Throws if `tokenId` is not a valid NFT
786 /// @param tokenId The NFT to find the approved address for
787 /// @return The approved address for this NFT, or the zero address if there is none
785 /// @dev EVM selector for this function is: 0x081812fc,788 /// @dev EVM selector for this function is: 0x081812fc,
786 /// or in textual repr: getApproved(uint256)789 /// or in textual repr: getApproved(uint256)
787 function getApproved(uint256 tokenId) external view returns (address);790 function getApproved(uint256 tokenId) external view returns (address);
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
229 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);229 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
230 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);230 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
231231
232 {
233 const badTokenId = await contract.methods.nextTokenId().call() + 1;
234 await expect(contract.methods.getApproved(badTokenId).call()).to.be.rejectedWith('revert TokenNotFound');
235 }
236 {
237 const approved = await contract.methods.getApproved(tokenId).call();
238 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');
239 }
232 {240 {
233 const result = await contract.methods.approve(spender, tokenId).send({from: owner});241 const result = await contract.methods.approve(spender, tokenId).send({from: owner});
234242
238 expect(event.returnValues.approved).to.be.equal(spender);246 expect(event.returnValues.approved).to.be.equal(spender);
239 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);247 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
240 }248 }
249 {
250 const approved = await contract.methods.getApproved(tokenId).call();
251 expect(approved).to.be.equal(spender);
252 }
241 });253 });
242254
243 itEth('Can perform setApprovalForAll()', async ({helper}) => {255 itEth('Can perform setApprovalForAll()', async ({helper}) => {