Skip to content

Commit

Permalink
rpc system nonce (#155)
Browse files Browse the repository at this point in the history
* add system_account_nonce rpc

* fix type

* update toolchain
  • Loading branch information
ermalkaleci authored Jan 20, 2023
1 parent 213170c commit e89bc4a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly-2022-10-16
toolchain: nightly-2022-10-30
components: rustfmt
target: wasm32-unknown-unknown
- name: Use Node.js
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly-2022-10-16
toolchain: nightly-2022-10-30
components: rustfmt
target: wasm32-unknown-unknown
- name: Use Node.js
Expand Down
3 changes: 3 additions & 0 deletions e2e/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ describe('system rpc', () => {
isSyncing: false,
shouldHavePeers: false,
})
expect((await api.rpc.system.accountNextIndex('5EYCAe5fiQJsoMt16QywpBQwyn5cgfkXFFJApwwKPXFoF2h7')).toNumber()).toBe(
0
)
})
})
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2022-10-16"
channel = "nightly-2022-10-30"
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
14 changes: 13 additions & 1 deletion src/rpc/substrate/system.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Index } from '@polkadot/types/interfaces'
import { hexToU8a } from '@polkadot/util'
import { readFileSync } from 'node:fs'

import { Handlers } from '../shared'

const handlers: Handlers = {
Expand All @@ -11,7 +15,8 @@ const handlers: Handlers = {
return context.chain.api.getSystemName()
},
system_version: async (_context) => {
return 'chopsticks-1.1.0'
const { version } = JSON.parse(readFileSync('package.json', 'utf-8'))
return `chopsticks-v${version}`
},
system_chainType: async (_context) => {
return 'Development'
Expand All @@ -27,6 +32,13 @@ const handlers: Handlers = {
const { outcome } = await context.chain.dryRunExtrinsic(extrinsic, at)
return outcome.toHex()
},
system_accountNextIndex: async (context, [address]) => {
const head = context.chain.head
const registry = await head.registry
const account = registry.createType('AccountId32', address)
const result = await head.call('AccountNonceApi_account_nonce', account.toHex())
return registry.createType<Index>('Index', hexToU8a(result.result)).toNumber()
},
}

export default handlers

0 comments on commit e89bc4a

Please sign in to comment.