difftreelog
feat implement ERC721 `getApproved` for NFT.
in: master
3 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth516 }516 }517517518 /// @dev Not implemented518 /// @dev Not implemented519 fn get_approved(&self, _token_id: U256) -> Result<Address> {519 fn get_approved(&self, token_id: U256) -> Result<Address> {520 // TODO: Not implemetable520 let token = token_id.try_into()?;521 let operator = <Pallet<T>>::get_allowance(self, token).map_err(dispatch_to_evm::<T>)?;521 Err("not implemented".into())522 Ok(if let Some(operator) = operator {523 *operator.as_eth()524 } else {525 Address::zero()526 })522 }527 }523528524 /// @notice Tells whether the given `owner` approves the `operator`.529 /// @notice Tells whether the given `owner` approves the `operator`.pallets/nonfungible/src/lib.rsdiffbeforeafterboth1083 }1083 }1084 }1084 }10851086 pub fn get_allowance(1087 collection: &NonfungibleHandle<T>,1088 token: TokenId,1089 ) -> Result<Option<T::CrossAccountId>, DispatchError> {1090 ensure! {1091 <TokenData<T>>::iter_keys().find(1092 |(c, t)| return *c == collection.id && *t == token).is_some()1093 ,<CommonError<T>>::TokenNotFound1094 };1095 Ok(<Allowance<T>>::get((collection.id, token)))1096 }108510971086 /// Set allowance for the spender to `transfer` or `burn` sender's token.1098 /// Set allowance for the spender to `transfer` or `burn` sender's token.1087 ///1099 ///tests/src/eth/nonFungible.test.tsdiffbeforeafterboth240 }240 }241 });241 });242243 itEth('Can perform setApproval()', async ({helper}) => {244 const owner = await helper.eth.createAccountWithBalance(donor);245 const operator = helper.eth.createAccount();246247 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');248 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);249250 const result = await contract.methods.mint(owner).send({from: owner});251 const tokenId = result.events.Transfer.returnValues.tokenId;252253 {254 const approved = await contract.methods.getApproved(tokenId).call();255 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');256 }257 await contract.methods.approve(operator, tokenId).send({from: owner});258 {259 const approved = await contract.methods.getApproved(tokenId).call();260 expect(approved).to.be.equal(operator);261 }262 });263242264243 itEth('Can perform setApprovalForAll()', async ({helper}) => {265 itEth('Can perform setApprovalForAll()', async ({helper}) => {