Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: types for sync_state_genSyncSpec #455

Merged
merged 1 commit into from
Dec 5, 2022
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
5 changes: 5 additions & 0 deletions effects/rpc_known_methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ export namespace payment {
"payment_queryInfo",
)
}
export namespace sync {
export namespace state {
export const genSyncSpec = rpcCall<[boolean], known.ChainSpec>("sync_state_genSyncSpec")
}
}
1 change: 0 additions & 1 deletion rpc/known/Readme.md

This file was deleted.

1 change: 1 addition & 0 deletions rpc/known/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export * from "./payment.ts"
export * as smoldot from "./smoldot.ts"
export * from "./state.ts"
export * from "./statemigration.ts"
export * from "./sync.ts"
export * from "./system.ts"
export * from "./utils.ts"
71 changes: 71 additions & 0 deletions rpc/known/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ChainType } from "./system.ts"
import { Hash, Hex, RpcResult } from "./utils.ts"

// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L161
/** A configuration of a client. Does not include runtime storage initialization. */
export interface ChainSpec {
// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L34
genesis: GenesisSource
name: string
id: string
chainType: ChainType
bootNodes: string[]
telemetryEndpoints: null | [string, number][]
protocolId: null | string
/**
* Arbitrary string. Nodes will only synchronize with other nodes that have the same value
* in their `fork_id`. This can be used in order to segregate nodes in cases when multiple
* chains have the same genesis hash.
*/
forkId?: string
properties?: {
ss58Format?: number
tokenDecimals: number
tokenSymbol: string
}
/**
* Mapping from `block_number` to `wasm_code`.
*
* The given `wasm_code` will be used to substitute the on-chain wasm code starting with the
* given block number until the `spec_version` on chain changes.
*/
codeSubstitutes: Record<string, Hex>
// Extensions, flattened into this structure by Serde: https://github.com/paritytech/substrate/blob/409167ef/bin/node/cli/src/chain_spec.rs#L55
/** Block numbers with known hashes. */
forkBlocks: null | string
/** Known bad block hashes. */
badBlocks: null | Hash[]
/** The light sync state extension used by the sync-state rpc. */
lightSyncState: LightSyncState
}

// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L34
export interface GenesisSource {
raw: RawGenesis
}

// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L142
/** Raw storage content for genesis block. */
export interface RawGenesis {
top: Hex[]
childrenDefault: Hex[]
}

// https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L111
export interface LightSyncState {
/** The header of the best finalized block. */
finalizedBlockHeader: Hex
/** The epoch changes tree for babe. */
babeEpochChanges: Hex
/** The babe weight of the finalized block. */
babeFinalizedBlockWeight: number
/** The authority set for grandpa. */
grandpaAuthoritySet: Hex
}

// https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L128
export type SyncRpc = {
// https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L131
/** Returns the JSON serialized chainspec running the node, with a sync state. */
system_gen_sync_spec(raw: boolean): RpcResult<ChainSpec>
}
6 changes: 6 additions & 0 deletions rpc/known/system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Hash, RpcResult, SerdeEnum } from "./utils.ts"

// https://github.com/paritytech/substrate/blob/57e3486/client/chain-spec/src/lib.rs#L198
/**
* The type of a chain.
*
* This can be used by tools to determine the type of a chain for displaying
* additional information or enabling additional features.
*/
export type ChainType = SerdeEnum<{
/** A development chain that runs mainly on one node. */
Development: void
Expand Down