Skip to content

Commit

Permalink
Merge pull request #2001 from oasisprotocol/lw/simplify-tx-nonces
Browse files Browse the repository at this point in the history
Simplify appending nonces to consensus transactions
  • Loading branch information
lukaw3d authored Jul 12, 2024
2 parents 7a641dc + 28d2670 commit 233651f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .changelog/1999.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Pending transactions

Introduces a section for pending transactions within the transaction history
interface. It is designed to display transactions currently in a pending
state that are made within the wallet. The section will also show up in case
there is a discrepancy between transaction history nonce and wallet nonce,
indicating that some transactions are currently in pending state.
1 change: 0 additions & 1 deletion .changelog/1999.internal.md

This file was deleted.

7 changes: 7 additions & 0 deletions .changelog/2001.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Pending transactions

Introduces a section for pending transactions within the transaction history
interface. It is designed to display transactions currently in a pending
state that are made within the wallet. The section will also show up in case
there is a discrepancy between transaction history nonce and wallet nonce,
indicating that some transactions are currently in pending state.
32 changes: 2 additions & 30 deletions src/app/state/account/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function* fetchAccount(action: PayloadAction<string>) {
const address = action.payload

yield* put(accountActions.setLoading(true))
const { getTransactionsList, getTransaction } = yield* call(getExplorerAPIs)
const { getTransactionsList } = yield* call(getExplorerAPIs)

yield* all([
join(
Expand Down Expand Up @@ -56,35 +56,7 @@ export function* fetchAccount(action: PayloadAction<string>) {
limit: TRANSACTIONS_LIMIT,
})

const detailedTransactions = yield* call(() =>
Promise.allSettled(
transactions.map(tx => {
const { hash, runtimeId, runtimeName, round } = tx

if (!!runtimeId || !!runtimeName || !!round) {
return Promise.reject()
}

return getTransaction({ hash })
}),
),
)
const transactionsWithUpdatedNonce = transactions.map((t, i) => {
const { status, value } = detailedTransactions[i] as PromiseFulfilledResult<Transaction>
// Skip in case transaction detail request failed
if (status === 'fulfilled') {
return {
...t,
nonce: value.nonce,
}
}

return t
})

yield* put(
accountActions.transactionsLoaded({ networkType, transactions: transactionsWithUpdatedNonce }),
)
yield* put(accountActions.transactionsLoaded({ networkType, transactions }))
} catch (e: any) {
console.error('get transactions list failed, continuing without updated list.', e)
if (e instanceof WalletError) {
Expand Down
26 changes: 13 additions & 13 deletions src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qz086axf5hreqpehv5hlgmtw7sfem79gz55v68wp",
"hash": "b831c4b2aa3188058717250cba279795d907e581bb4d7d40d9dc358d37a56254",
"level": 7381105,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -75,7 +75,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qz0rx0h3v8fyukfrr0npldrrzvpdg4wj2qxvg0kj",
"hash": "e67c4331aa79c85736c4d96cd7b1f3eaad80301bb8d5c181c67482e57ebf0565",
"level": 7381138,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -90,7 +90,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qzah5wn48ekakmq5405qvcg4czp8hjvrcvcywvhp",
"hash": "0558d39e2c5ebe187fc2802ab442faa548013b247b5de1fb1ef75862dad4fb23",
"level": 7380979,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -105,7 +105,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qzl58e7v7pk50h66s2tv3u9rzf87twp7pcv7hul6",
"hash": "ba8e25c66ae31fa0a0837a414359bc2318c6c849515ca3dc1ffa9eb0a1ab92b3",
"level": 7361579,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -120,7 +120,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qq3833fnmkqe94h0ca6w8qa84sq8pu92qsjmfayj",
"hash": "8894b8e9866f66efe291155646f1c09d69d7221449a8d9f758ad1d31f504df03",
"level": 7381163,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -135,7 +135,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qzr9p9fpjqekr8dev66wuaedcpq5n09hwvpkd4pg",
"hash": "d6298496fc19fd95fa1e2b245d1c33661b9ebd7ffb184280c363a31d13210c2a",
"level": 7381204,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -150,7 +150,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qz6k3gky5d43h70xh2c5vk5fztmzmxmmhc6rh72x",
"hash": "46583095fd80becc2683aacc67684170de8d6bc6eca5103d7ac543106d729a8f",
"level": 7381052,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -165,7 +165,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qpdlqz373hcqvafadd3lxptj42x84sws35s02r4r",
"hash": "5378750685efed957417abea41e7d96804264cb51d85dcee45494ef0ca2f31c7",
"level": 7368263,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -180,7 +180,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qzwl8jlxzwjgz2m6d3ns0vt9hzfp2h63qsxs76ys",
"hash": "86a303d9891bbefb0984b82dcc0a51ec190d383248b536dcb8bc9ca0404824f4",
"level": 7381231,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -195,7 +195,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qrvmxhcjpjvgel9dqfs6zrnza3hqjpa6ug2arc0d",
"hash": "2ac0a88ab2c85cef69905c8c9b3f639c5b3b15b969c334df5dcc4fa54f183a8a",
"level": 6251849,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -210,7 +210,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qp3rhyfjagkj65cnn6lt8ej305gh3kamsvzspluq",
"hash": "a62ebc4d30bc045f129f33a14d4019ec88e48c150980ed388d5f64b6e9476059",
"level": 4726356,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -225,7 +225,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qrd64zucfaugv677fwkhynte4dz450yffgp0k06t",
"hash": "09bfc632625d44fe96d4d31bacd12ed889231f77ed898cbcccf0dea7527a6237",
"level": 7396874,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand All @@ -240,7 +240,7 @@ exports[`oasisscan parse transaction list 1`] = `
"from": "oasis1qptn9zmdn5ksvq85vxg2mg84e9m6jp2875dyfl73",
"hash": "9c9fd0d2588a0108ec5f277f476483f17e2d8429e947c83f0096b0a7c351aa51",
"level": 7381114,
"nonce": undefined,
"nonce": "1",
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
Expand Down
13 changes: 13 additions & 0 deletions src/vendors/__tests__/oasisscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qz086axf5hreqpehv5hlgmtw7sfem79gz55v68wp',
to: 'oasis1qpm97z4c28juhdea220jtq2e3mz4gruyg54xktlm',
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=staking.AddEscrow&address=oasis1qz0rx0h3v8fyukfrr0npldrrzvpdg4wj2qxvg0kj
Expand All @@ -206,6 +207,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qz0rx0h3v8fyukfrr0npldrrzvpdg4wj2qxvg0kj',
to: 'oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm',
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=staking.ReclaimEscrow&address=oasis1qzah5wn48ekakmq5405qvcg4czp8hjvrcvcywvhp
Expand All @@ -222,6 +224,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qzah5wn48ekakmq5405qvcg4czp8hjvrcvcywvhp',
to: 'oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm',
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=staking.AmendCommissionSchedule&address=oasis1qzl58e7v7pk50h66s2tv3u9rzf87twp7pcv7hul6
Expand All @@ -238,6 +241,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qzl58e7v7pk50h66s2tv3u9rzf87twp7pcv7hul6',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=staking.Allow&address=oasis1qq3833fnmkqe94h0ca6w8qa84sq8pu92qsjmfayj
Expand All @@ -254,6 +258,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qq3833fnmkqe94h0ca6w8qa84sq8pu92qsjmfayj',
to: 'oasis1qzvlg0grjxwgjj58tx2xvmv26era6t2csqn22pte',
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=roothash.ExecutorCommit&address=oasis1qzr9p9fpjqekr8dev66wuaedcpq5n09hwvpkd4pg
Expand All @@ -270,6 +275,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qzr9p9fpjqekr8dev66wuaedcpq5n09hwvpkd4pg',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=roothash.ExecutorProposerTimeout&address=oasis1qz6k3gky5d43h70xh2c5vk5fztmzmxmmhc6rh72x
Expand All @@ -286,6 +292,7 @@ describe('oasisscan', () => {
status: false,
from: 'oasis1qz6k3gky5d43h70xh2c5vk5fztmzmxmmhc6rh72x',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=registry.RegisterEntity&address=oasis1qpdlqz373hcqvafadd3lxptj42x84sws35s02r4r
Expand All @@ -302,6 +309,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qpdlqz373hcqvafadd3lxptj42x84sws35s02r4r',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=registry.RegisterNode&address=oasis1qzwl8jlxzwjgz2m6d3ns0vt9hzfp2h63qsxs76ys
Expand All @@ -318,6 +326,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qzwl8jlxzwjgz2m6d3ns0vt9hzfp2h63qsxs76ys',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=registry.RegisterRuntime&address=oasis1qrvmxhcjpjvgel9dqfs6zrnza3hqjpa6ug2arc0d
Expand All @@ -334,6 +343,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qrvmxhcjpjvgel9dqfs6zrnza3hqjpa6ug2arc0d',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=governance.CastVote&address=oasis1qp3rhyfjagkj65cnn6lt8ej305gh3kamsvzspluq
Expand All @@ -350,6 +360,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qp3rhyfjagkj65cnn6lt8ej305gh3kamsvzspluq',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=beacon.PVSSCommit&address=oasis1qrd64zucfaugv677fwkhynte4dz450yffgp0k06t
Expand All @@ -366,6 +377,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qrd64zucfaugv677fwkhynte4dz450yffgp0k06t',
to: null,
nonce: 1,
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=beacon.PVSSReveal&address=oasis1qptn9zmdn5ksvq85vxg2mg84e9m6jp2875dyfl73
Expand All @@ -382,6 +394,7 @@ describe('oasisscan', () => {
status: true,
from: 'oasis1qptn9zmdn5ksvq85vxg2mg84e9m6jp2875dyfl73',
to: null,
nonce: 1,
},
]),
).toMatchSnapshot()
Expand Down
5 changes: 0 additions & 5 deletions src/vendors/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export function getMonitorAPIs(url: string | 'https://monitor.oasis.dev') {
return parseValidatorsList(validators)
}

async function getTransaction({ hash }: { hash: string }) {
throw new Error('Not implemented')
}

async function getTransactionsList(params: { accountId: string; limit: number }) {
const transactions = await operations.getTransactionsList({
accountId: params.accountId,
Expand Down Expand Up @@ -74,7 +70,6 @@ export function getMonitorAPIs(url: string | 'https://monitor.oasis.dev') {
blocks,
getAccount,
getAllValidators,
getTransaction,
getTransactionsList,
getDelegations,
}
Expand Down
29 changes: 15 additions & 14 deletions src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {

import { throwAPIErrors } from './helpers'

const getTransactionCacheMap: Record<string, Transaction> = {}
const getTransactionCacheMap: Record<string, OperationsEntity> = {}
const getRuntimeTransactionInfoCacheMap: Record<string, RuntimeTransactionInfoRow> = {}

export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainnet') {
Expand Down Expand Up @@ -85,18 +85,16 @@ export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainne
return getTransactionCacheMap[cacheId]
}

const transaction = await operationsEntity.getTransaction({
const { data, code } = await operationsEntity.getTransaction({
hash,
})

const [parsedTx] = parseTransactionsList([transaction.data ?? {}])

// returns {"code": 0,"data": null} for missing or unprocessed transactions, we want to skip caching those requests
if (transaction.code === 0 && !!transaction.data) {
getTransactionCacheMap[cacheId] = parsedTx
if (code === 0 && !!data) {
getTransactionCacheMap[cacheId] = data
}

return parsedTx
return data
}

async function getTransactionsList(params: { accountId: string; limit: number }) {
Expand All @@ -108,7 +106,14 @@ export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainne
if (!transactionsList || transactionsList.code !== 0) throw new Error('Wrong response code') // TODO

const list = await Promise.all(
transactionsList.data.list.map(async tx => (tx.runtimeId ? getRuntimeTransactionInfo(tx) : tx)),
transactionsList.data.list.map(async tx => {
if (tx.runtimeId) {
return await getRuntimeTransactionInfo(tx)
} else {
const { nonce } = await getTransaction({ hash: tx.txHash })
return { ...tx, nonce }
}
}),
)

return parseTransactionsList(list)
Expand All @@ -134,7 +139,6 @@ export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainne
operations,
getAccount,
getAllValidators,
getTransaction,
getTransactionsList,
getDelegations,
}
Expand Down Expand Up @@ -209,7 +213,7 @@ export const transactionMethodMap: {
}

export function parseTransactionsList(
list: (OperationsRow | RuntimeTransactionInfoRow | OperationsEntity)[],
list: ((OperationsRow & { nonce: number }) | RuntimeTransactionInfoRow)[],
): Transaction[] {
return list.map(t => {
if ('ctx' in t) {
Expand Down Expand Up @@ -243,10 +247,7 @@ export function parseTransactionsList(
runtimeName: undefined,
runtimeId: undefined,
round: undefined,
nonce:
(t as OperationsEntity).nonce == null
? undefined
: BigInt((t as OperationsEntity).nonce).toString(),
nonce: t.nonce == null ? undefined : BigInt(t.nonce).toString(),
}
return parsed
}
Expand Down

0 comments on commit 233651f

Please sign in to comment.