Skip to content

Commit

Permalink
Handle nonces in runtime transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jul 30, 2024
1 parent a000cc1 commit e9fdf1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/app/state/account/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ describe('hasAccountUnknownPendingTransactions', () => {
).toBe(true)
})

it('paratime transaction updates a different nonce within the paratime', () => {
expect(
hasAccountUnknownPendingTransactions({
account: {
address: currentAddress,
nonce: 1n.toString(),
transactions: [
{
from: currentAddress, // Sent on Emerald
to: 'oasis1qq235lqj77855qcemcr5w2qm372s4amqcc4v3ztc', // 0xC3ecf872F643C6238Aa20673798eed6F7dA199e9
status: TransactionStatus.Successful,
runtimeName: 'Emerald',
runtimeId: '000000000000000000000000000000000000000000000000e2eaa99fc008f87f',
round: 11129138,
type: 'consensus.Deposit',
nonce: 0n.toString(), // Misleading Emerald nonce
},
] as Transaction[],
},
} as RootState),
).toBe(true)
})

it('multiple pages of transactions', () => {
const onePageOfReceivedTxs = new Array(TRANSACTIONS_LIMIT).fill(null).map(() => ({
from: 'oasis1qp2frld759c6u92pxs768nd2ctnrduhqp5f6f273',
Expand Down
1 change: 1 addition & 0 deletions src/app/state/account/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const hasAccountUnknownPendingTransactions = createSelector(
[selectAccountNonce, selectTransactions, selectAccountAddress],
(accountNonce, transactions, accountAddress) => {
const noncesFromTxs = transactions
.filter(tx => !tx.runtimeId)
.filter(tx => tx.from !== undefined)
.filter(tx => tx.from === accountAddress)
.filter(tx => tx.nonce !== undefined)
Expand Down
2 changes: 1 addition & 1 deletion src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qqnk4au603zs94k0d0n7c0hkx8t4p6r87s60axru",
"hash": "25b84ca4582f6e3140c384ad60b98415d2c3079d1fc5f2221e45da7b13c70817",
"level": undefined,
"nonce": undefined,
"nonce": "4",
"round": 997775,
"runtimeId": "000000000000000000000000000000000000000000000000e2eaa99fc008f87f",
"runtimeName": "Emerald",
Expand Down
3 changes: 2 additions & 1 deletion src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export function parseTransactionsList(
runtimeName: t.runtimeName,
runtimeId: t.runtimeId,
round: t.round,
nonce: undefined,
nonce:
t.ctx?.nonce ?? t.etx?.nonce != null ? BigInt(t.ctx?.nonce ?? t.etx?.nonce).toString() : undefined,
}
return parsed
} else {
Expand Down

0 comments on commit e9fdf1f

Please sign in to comment.