difftreelog
chore make rft token default if parent token is not set
in: master
2 files changed
pallets/refungible/src/erc_token.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -59,8 +59,11 @@
let key_scoped = PropertyScope::Eth
.apply(key)
.expect("property key shouldn't exceed length limit");
- let value = props.get(&key_scoped).ok_or("key not found")?;
- Ok(H160::from_slice(value.as_slice()))
+ if let Some(value) = props.get(&key_scoped) {
+ Ok(H160::from_slice(value.as_slice()))
+ } else {
+ Ok(*T::CrossTokenAddressMapping::token_to_address(self.id, self.1).as_eth())
+ }
}
fn parent_token_id(&self) -> Result<uint256> {
@@ -71,13 +74,16 @@
let key_scoped = PropertyScope::Eth
.apply(key)
.expect("property key shouldn't exceed length limit");
- let value = props.get(&key_scoped).ok_or("key not found")?;
- let nft_token_address = H160::from_slice(value.as_slice());
- let nft_token_account = T::CrossAccountId::from_eth(nft_token_address);
- let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account)
- .ok_or("parent NFT should contain NFT token address")?;
+ if let Some(value) = props.get(&key_scoped) {
+ let nft_token_address = H160::from_slice(value.as_slice());
+ let nft_token_account = T::CrossAccountId::from_eth(nft_token_address);
+ let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account)
+ .ok_or("parent NFT should contain NFT token address")?;
- Ok(token_id.into())
+ Ok(token_id.into())
+ } else {
+ Ok(self.1.into())
+ }
}
}
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth656 expect(tokenId).to.be.equal(nftTokenId);656 expect(tokenId).to.be.equal(nftTokenId);657 });657 });658659 itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {660 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);661662 const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);663 const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);664 const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();665 await refungibleContract.methods.mint(owner, refungibleTokenId).send();666667 const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);668 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);669670 const tokenAddress = await refungibleTokenContract.methods.parentToken().call();671 const tokenId = await refungibleTokenContract.methods.parentTokenId().call();672 expect(tokenAddress).to.be.equal(rftTokenAddress);673 expect(tokenId).to.be.equal(refungibleTokenId);674 });658});675});659676660677