Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc system nonce #155

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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