Skip to content

Commit

Permalink
fix(LSK): include nonce in transaction fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Dec 25, 2023
1 parent c2b2c2b commit 18b6bd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/lib/lisk/lisk-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ type EstimateFeeParams = {
*/
data?: string
isNewAccount?: boolean
/**
* Current nonce
*/
nonce: number | string
}

/**
Expand All @@ -232,14 +236,15 @@ export function estimateFee(params?: EstimateFeeParams) {
keyPair = LSK_DEMO_ACCOUNT.keyPair,
recipientAddress = LSK_DEMO_ACCOUNT.address,
data = '',
nonce = 0,
isNewAccount
} = params || {}

const unsignedTransaction = {
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'),
Expand Down
9 changes: 7 additions & 2 deletions src/store/modules/lsk/lsk-getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 18b6bd9

Please sign in to comment.