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

feat: add chainSpec_v1 group of functions #820

Merged
merged 2 commits into from
Sep 15, 2024
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
19 changes: 19 additions & 0 deletions packages/core/src/rpc/rpc-spec/chainSpec_v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ChainProperties } from '../../index.js'
import { Handler, ResponseError } from '../shared.js'
import { HexString } from '@polkadot/util/types'

export const chainSpec_v1_chainName: Handler<[], string> = async (context) => {
return context.chain.api.getSystemChain()
}

export const chainSpec_v1_genesisHash: Handler<[], HexString> = async (context) => {
const genesisHash = await context.chain.api.getBlockHash(0)
if (genesisHash === null) {
throw new ResponseError(1, 'Unexpected null genesis hash')
}
return genesisHash
}

export const chainSpec_v1_properties: Handler<[], ChainProperties> = async (context) => {
return context.chain.api.getSystemProperties()
}
4 changes: 3 additions & 1 deletion packages/core/src/rpc/rpc-spec/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as ChainHeadV1RPC from './chainHead_v1.js'
import * as ChainSpecV1RPC from './chainSpec_v1.js'
import * as TransactionV1RPC from './transaction_v1.js'

export { ChainHeadV1RPC, TransactionV1RPC }
export { ChainHeadV1RPC, TransactionV1RPC, ChainSpecV1RPC }

const handlers = {
...ChainHeadV1RPC,
...TransactionV1RPC,
...ChainSpecV1RPC,
}

export default handlers
23 changes: 23 additions & 0 deletions packages/e2e/src/__snapshots__/rpc-spec.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`chainSpec_v1 > retrieves the chainSpec data 1`] = `
{
"genesisHash": "0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c",
"name": "Acala",
"properties": {
"ss58Format": 10,
"tokenDecimals": [
12,
12,
10,
10,
],
"tokenSymbol": [
"ACA",
"AUSD",
"DOT",
"LDOT",
],
},
}
`;
6 changes: 6 additions & 0 deletions packages/e2e/src/rpc-spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ describe('transaction_v1', async () => {
})
})

describe('chainSpec_v1', () => {
it('retrieves the chainSpec data', async () => {
expect(await testApi.substrateClient.getChainSpecData()).toMatchSnapshot()
})
})

const INITIAL_ACCOUNT_VALUE = 100_000_000_000_000n
async function prepareChainForTx() {
const api = await ApiPromise.create({
Expand Down
Loading