Skip to content

Commit

Permalink
fix header rpc response (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Mar 6, 2024
1 parent 3b4acb7 commit 3fc61b9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
26 changes: 2 additions & 24 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types'
import { HexString } from '@polkadot/util/types'
import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types'
import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index.js'
import _ from 'lodash'

export type ChainProperties = {
ss58Format?: number
tokenDecimals?: number[]
tokenSymbol?: string[]
}

type Header = {
parentHash: HexString
number: HexString
stateRoot: HexString
extrinsicsRoot: HexString
digest: {
logs: HexString[]
}
}

type SignedBlock = {
block: {
header: Header
extrinsics: HexString[]
}
justifications?: HexString[]
}
import { ChainProperties, Header, SignedBlock } from './index.js'
import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index.js'

/**
* API class. Calls provider to get on-chain data.
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@
*
* @packageDocumentation
*/

import { HexString } from '@polkadot/util/types'

export type ChainProperties = {
ss58Format?: number
tokenDecimals?: number[]
tokenSymbol?: string[]
}

export type Header = {
parentHash: HexString
number: HexString
stateRoot: HexString
extrinsicsRoot: HexString
digest: {
logs: HexString[]
}
}

export type SignedBlock = {
block: {
header: Header
extrinsics: HexString[]
}
justifications?: HexString[]
}

export * from './api.js'
export * from './blockchain/index.js'
export * from './blockchain/block.js'
Expand Down
17 changes: 12 additions & 5 deletions packages/core/src/rpc/substrate/chain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Header } from '@polkadot/types/interfaces'
import { Header as CodecHeader } from '@polkadot/types/interfaces'
import { HexString } from '@polkadot/util/types'

import { Handler, ResponseError } from '../shared.js'
import type { Header } from '../../index.js'

const processHeader = (header: Header) => {
const res = header.toJSON() as any
res.number = '0x' + res.number.toString(16) // number is hex format
return res
const processHeader = ({ parentHash, number, stateRoot, extrinsicsRoot, digest }: CodecHeader) => {
return {
parentHash: parentHash.toHex(),
number: number.toHex(),
stateRoot: stateRoot.toHex(),
extrinsicsRoot: extrinsicsRoot.toHex(),
digest: {
logs: digest.logs.map((log) => log.toHex()),
},
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/rpc/substrate/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HexString } from '@polkadot/util/types'
import { Index } from '@polkadot/types/interfaces'
import { hexToU8a } from '@polkadot/util'

import { ChainProperties } from '../../api.js'
import { ChainProperties } from '../../index.js'
import { Handler } from '../shared.js'

export const system_localPeerId = async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
Expand Down

0 comments on commit 3fc61b9

Please sign in to comment.