Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting warning for opt out of asset transaction in Mocha #712

Open
kashishkhullar opened this issue Jun 9, 2022 · 0 comments
Open

Getting warning for opt out of asset transaction in Mocha #712

kashishkhullar opened this issue Jun 9, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@kashishkhullar
Copy link

Describe the bug

As per my understanding, for opting out of a transaction in Algo-builder, we need to send a AssetTransfer transaction with amount 0, receiver as ourselves and closeRemainderTo set to the creator address.

const optOutTxn = {
      type: types.TransactionType.TransferAsset,
      sign: types.SignType.SecretKey,
      fromAccount: customer.account,
      toAccountAddr: customer.account.addr,
      assetID: nft_id,
      amount: 0,
      payFlags: { totalFee: 1000, closeRemainderTo: seller.account.addr },
};

An example on your repo can be found here:

const optOutParams = [
{
type: types.TransactionType.TransferAsset,
sign: types.SignType.SecretKey,
fromAccount: account,
toAccountAddr: account.addr,
assetID: tesla.assetIndex,
amount: 0,
payFlags: { totalFee: 1000, closeRemainderTo: tesla.creator },
},
];

Although the opt out works fine, I am getting warning printed that the is already opted in to the asset

Expected Behavior

No warnings

Current Behavior

Warning printed

<account address> is already opted in to the asset <asset id>

Possible Solution

In the following function, a console.warn() is added in Line 390 if asset holding is defined but does not handle the case when the transaction is for opting out.

You can add another if condition to check if closeRemainderTo field is set to the creator of the Asset which confirms that this transaction is a Opt Out transaction and not opt in.

optInToASA(assetIndex: number, assetHolding: AssetHoldingM): void {
const accAssetHolding = this.assets.get(assetIndex); // fetch asset holding of account
if (accAssetHolding) {
console.warn(`${this.address} is already opted in to asset ${assetIndex}`);
} else {
if (this.createdAssets.size + this.assets.size === MAX_ALGORAND_ACCOUNT_ASSETS) {
throw new RuntimeError(RUNTIME_ERRORS.ASA.MAX_LIMIT_ASSETS, {
address: assetHolding.creator,
max: MAX_ALGORAND_ACCOUNT_ASSETS,
});
}
this.minBalance += ASSET_CREATION_FEE;
this.assets.set(assetIndex, assetHolding);
}
}

Steps to Reproduce

  1. Create an NFT
  2. Create Opt Out transaction

Environment

  • OS: Windows 11
  • Node.js version: v16.15.0
  • algob version: NA
@kashishkhullar kashishkhullar added the bug Something isn't working label Jun 9, 2022
@vuvoth vuvoth self-assigned this Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants