Skip to content

Commit

Permalink
fix: use correct nonce to dry-run contract calls
Browse files Browse the repository at this point in the history
It won't fail if multiple transactions are stuck before in mempool.
  • Loading branch information
davidyuk committed Mar 3, 2024
1 parent b525f07 commit e1d9123
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/popup/components/Modals/ConfirmTransactionSign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ import {
import { camelCase } from 'lodash-es';
import { useI18n } from 'vue-i18n';
import BigNumber from 'bignumber.js';
import { decode, Encoded, getExecutionCost } from '@aeternity/aepp-sdk';
import {
decode, Encoded, getExecutionCost, unpackTx, Tag, getTransactionSignerAddress, buildTx,
} from '@aeternity/aepp-sdk';
import { ContractByteArrayEncoder, BytecodeContractCallEncoder } from '@aeternity/aepp-calldata';
import JsonBig from '@/lib/json-big';
Expand Down Expand Up @@ -429,12 +431,11 @@ export default defineComponent({
error.value = t('validation.enoughCoin');
return;
}
if (popupProps.value.tx?.contractId) {
const accountAddress = popupProps.value.tx.callerId || popupProps.value.tx.senderId!;
const dryRunResult = await sdk.txDryRun(
popupProps.value.txBase64,
accountAddress as Encoded.AccountAddress,
);
const txParams = unpackTx(popupProps.value.txBase64);
if (txParams.tag === Tag.ContractCallTx || txParams.tag === Tag.ContractCreateTx) {
const accountAddress = getTransactionSignerAddress(popupProps.value.txBase64);
txParams.nonce = (await sdk.api.getAccountByPubkey(accountAddress)).nonce + 1;
const dryRunResult = await sdk.txDryRun(buildTx(txParams), accountAddress);
if (dryRunResult.callObj && dryRunResult.callObj.returnType !== 'ok') {
error.value = new ContractByteArrayEncoder().decode(
dryRunResult.callObj.returnValue as Encoded.ContractBytearray,
Expand Down

0 comments on commit e1d9123

Please sign in to comment.