From 18b6bd9b18fdd56541cf9e95b35b032e71342c4a Mon Sep 17 00:00:00 2001 From: bludnic Date: Mon, 25 Dec 2023 17:33:40 +0000 Subject: [PATCH] fix(LSK): include `nonce` in transaction fee calculation --- src/lib/lisk/lisk-utils.ts | 7 ++++++- src/store/modules/lsk/lsk-getters.js | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/lisk/lisk-utils.ts b/src/lib/lisk/lisk-utils.ts index 728958531..e99ed3fbe 100644 --- a/src/lib/lisk/lisk-utils.ts +++ b/src/lib/lisk/lisk-utils.ts @@ -219,6 +219,10 @@ type EstimateFeeParams = { */ data?: string isNewAccount?: boolean + /** + * Current nonce + */ + nonce: number | string } /** @@ -232,6 +236,7 @@ export function estimateFee(params?: EstimateFeeParams) { keyPair = LSK_DEMO_ACCOUNT.keyPair, recipientAddress = LSK_DEMO_ACCOUNT.address, data = '', + nonce = 0, isNewAccount } = params || {} @@ -239,7 +244,7 @@ export function estimateFee(params?: EstimateFeeParams) { module: 'token', command: 'transfer', fee: BigInt(0), - nonce: BigInt(0), + nonce: BigInt(nonce), senderPublicKey: Buffer.from(keyPair.publicKey, 'hex'), params: { tokenID: Buffer.from(LSK_TOKEN_ID, 'hex'), diff --git a/src/store/modules/lsk/lsk-getters.js b/src/store/modules/lsk/lsk-getters.js index 826f54bf6..6883536a4 100644 --- a/src/store/modules/lsk/lsk-getters.js +++ b/src/store/modules/lsk/lsk-getters.js @@ -4,8 +4,13 @@ import baseGetters from '../lsk-base/lsk-base-getters' export default { ...baseGetters, - fee: () => (amount, _recipientAddress, data, isNewAccount) => { - return estimateFee({ amount, data, isNewAccount }) + fee: (state) => (amount, recipientAddress, data, isNewAccount) => { + return estimateFee({ + amount, + data, + isNewAccount, + nonce: state.nonce + }) }, height(state) {