Skip to content

Commit bf585cc

Browse files
committed
runtime/accounts: Include nonce in API response
1 parent c2885d0 commit bf585cc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

api/spec/v1.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,12 +3722,17 @@ components:
37223722

37233723
RuntimeAccount:
37243724
type: object
3725-
required: [address, balances, evm_balances, stats]
3725+
required: [address, nonce, balances, evm_balances, stats]
37263726
properties:
37273727
address:
37283728
type: string
37293729
description: The staking address for this account.
37303730
example: *staking_address_1
3731+
nonce:
3732+
type: integer
3733+
format: int64
3734+
description: The expected nonce for the next transaction (= last used nonce + 1)
3735+
example: 0
37313736
address_preimage:
37323737
allOf: [$ref: '#/components/schemas/AddressPreimage']
37333738
balances:

storage/client/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,17 @@ func (c *StorageClient) RuntimeAccount(ctx context.Context, runtime common.Runti
20572057
return nil, wrapError(err)
20582058
}
20592059

2060+
// Get the next expected nonce for this account.
2061+
err = c.db.QueryRow(
2062+
ctx,
2063+
queries.RuntimeAccountNonce,
2064+
runtime,
2065+
address.String(),
2066+
).Scan(&a.Nonce)
2067+
if err != nil {
2068+
return nil, wrapError(err)
2069+
}
2070+
20602071
return &a, nil
20612072
}
20622073

storage/client/queries/queries.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,13 @@ const (
882882
(runtime = $1) AND
883883
(address = $2::text)`
884884

885+
RuntimeAccountNonce = `
886+
SELECT COALESCE(MAX(nonce) + 1, 0)
887+
FROM chain.runtime_transaction_signers
888+
WHERE
889+
(runtime = $1) AND
890+
(signer_address = $2::text)`
891+
885892
RuntimeDelegations = `
886893
SELECT delegatee, shares, escrow_balance_active, escrow_total_shares_active
887894
FROM chain.runtime_accounts_delegations

0 commit comments

Comments
 (0)