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

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Oct 22, 2022
1 parent 237b337 commit 77399da
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 62 deletions.
21 changes: 11 additions & 10 deletions known/rpc/author.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hash, Hex, Result, SerdeEnum, Subscription } from "./utils.ts";
import { Hash, Hex, RpcResult, SerdeEnum, Subscription } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/e0ccd00/client/transaction-pool/api/src/lib.rs#L104
/**
Expand Down Expand Up @@ -78,6 +78,7 @@ export type TransactionStatus = SerdeEnum<{
invalid: void;
}>;

// https://github.com/paritytech/substrate/blob/e0ccd00/client/rpc-api/src/author/hash.rs
/**
* RPC Extrinsic or hash
*
Expand All @@ -93,26 +94,26 @@ export type ExtrinsicOrHash = SerdeEnum<{
// https://github.com/paritytech/substrate/blob/e0ccd00/client/rpc-api/src/author/mod.rs#L30
export type AuthorRpc = {
/** Submit hex-encoded extrinsic for inclusion in block. */
author_submitExtrinsic(extrinsic: Hex): Result<Hash>;
author_submitExtrinsic(extrinsic: Hex): RpcResult<Hash>;
/** Insert a key into the keystore. */
author_insertKey(keyType: string, suri: string, publicKey: Hex): Result<null>;
author_insertKey(keyType: string, suri: string, publicKey: Hex): RpcResult<null>;
/** Generate new session keys and returns the corresponding public keys. */
author_rotateKeys(): Result<Hex>;
author_rotateKeys(): RpcResult<Hex>;
/**
* Checks if the keystore has private keys for the given session public keys.
* `sessionKeys` is the SCALE encoded session keys object from the runtime.
* Returns `true` iff all private keys could be found.
*/
author_hasSessionKeys(sessionsKeys: Hex): Result<boolean>;
author_hasSessionKeys(sessionsKeys: Hex): RpcResult<boolean>;
/**
* Checks if the keystore has private keys for the given public key and key type.
* Returns `true` if a private key could be found.
*/
author_hasKey(pubKey: Hex, keyType: string): Result<boolean>;
author_hasKey(pubKey: Hex, keyType: string): RpcResult<boolean>;
/** Returns all pending extrinsics, potentially grouped by sender. */
author_pendingExtrinsics(): Result<Hex[]>;
author_pendingExtrinsics(): RpcResult<Hex[]>;
/** Remove given extrinsic from the pool and temporarily ban it to prevent reimporting. */
author_removeExtrinsic(extrinsics: ExtrinsicOrHash[]): Result<Hex[]>; // todo
author_removeExtrinsic(extrinsics: ExtrinsicOrHash[]): RpcResult<Hex[]>; // todo
/**
* Submit an extrinsic to watch.
*
Expand All @@ -121,8 +122,8 @@ export type AuthorRpc = {
*/
author_submitAndWatchExtrinsic(
extrinsic: Hex,
): Result<Subscription<"author_submitAndWatchExtrinsic", TransactionStatus>>;
): RpcResult<Subscription<"author_submitAndWatchExtrinsic", TransactionStatus>>;
author_unwatchExtrinsic(
subscription: Subscription<"author_submitAndWatchExtrinsic", TransactionStatus>,
): Result<void>;
): RpcResult<void>;
};
22 changes: 11 additions & 11 deletions known/rpc/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HexEncoded } from "../../util/branded.ts";
import { Hash, Hex, ListOrValue, NumberOrHex, Result, Subscription } from "./utils.ts";
import { Hash, Hex, ListOrValue, NumberOrHex, RpcResult, Subscription } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/0ba251c/primitives/runtime/src/generic/digest.rs
/** Generic header digest. */
Expand Down Expand Up @@ -43,34 +43,34 @@ export interface Block {
// https://github.com/paritytech/substrate/blob/934fbfd/client/rpc-api/src/chain/mod.rs#L27
export type ChainRpc = {
/** Get header. */
chain_getHeader(hash?: Hash): Result<Header | null>;
chain_getHeader(hash?: Hash): RpcResult<Header | null>;
/** Get header and body of a relay chain block. */
chain_getBlock(hash?: Hash): Result<SignedBlock | null>;
chain_getBlock(hash?: Hash): RpcResult<SignedBlock | null>;
/**
* Get hash of the n-th block in the canon chain.
*
* By default returns latest block hash.
*/
chain_getBlockHash(height?: ListOrValue<NumberOrHex>): Result<ListOrValue<Hash | null>>;
chain_getBlockHash(height?: ListOrValue<NumberOrHex>): RpcResult<ListOrValue<Hash | null>>;
chain_getHead: ChainRpc["chain_getBlockHash"];
/** Get hash of the last finalized block in the canon chain. */
chain_getFinalizedHead(): Result<Hash>;
chain_getFinalizedHead(): RpcResult<Hash>;
chain_getFinalisedHead: ChainRpc["chain_getFinalizedHead"];
/** All head subscription. */
chain_subscribeAllHeads(): Result<Subscription<"chain_subscribeAllHeads", Header>>;
chain_subscribeAllHeads(): RpcResult<Subscription<"chain_subscribeAllHeads", Header>>;
chain_unsubscribeAllHeads(
subscription: Subscription<"chain_subscribeAllHeads", Header>,
): Result<void>;
): RpcResult<void>;
/** New head subscription. */
chain_subscribeNewHeads(): Result<Subscription<"chain_subscribeAllHeads", Header>>;
chain_subscribeNewHeads(): RpcResult<Subscription<"chain_subscribeAllHeads", Header>>;
chain_unsubscribeNewHeads(
subscription: Subscription<"chain_subscribeAllHeads", Header>,
): Result<void>;
): RpcResult<void>;
/** Finalized head subscription. */
chain_subscribeFinalizedHeads(): Result<Subscription<"chain_subscribeAllHeads", Header>>;
chain_subscribeFinalizedHeads(): RpcResult<Subscription<"chain_subscribeAllHeads", Header>>;
chain_unsubscribeFinalizedHeads(
subscription: Subscription<"chain_subscribeAllHeads", Header>,
): Result<void>;
): RpcResult<void>;
chain_subscribeFinalisedHeads: ChainRpc["chain_subscribeFinalizedHeads"];
chain_unsubscribeFinalisedHeads: ChainRpc["chain_unsubscribeFinalizedHeads"];
};
6 changes: 3 additions & 3 deletions known/rpc/mmr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hash, Hex, Result } from "./utils.ts";
import { Hash, Hex, RpcResult } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/6c5ac31/primitives/merkle-mountain-range/src/lib.rs#L37
/**
Expand Down Expand Up @@ -44,7 +44,7 @@ export type MmrRpc = {
* Returns the (full) leaf itself and a proof for this leaf (compact encoding, i.e. hash of
* the leaf). Both parameters are SCALE-encoded.
*/
mmr_generateProof(leafIndex: LeafIndex, at?: Hash): Result<LeafProof>;
mmr_generateProof(leafIndex: LeafIndex, at?: Hash): RpcResult<LeafProof>;
/**
* Generate MMR proof for the given leaf indices.
*
Expand All @@ -57,5 +57,5 @@ export type MmrRpc = {
* The order of entries in the `leaves` field of the returned struct
* is the same as the order of the entries in `leaf_indices` supplied
*/
mmr_generateBatchProof(leafIndices: LeafIndex[], at?: Hash): Result<LeafBatchProof>;
mmr_generateBatchProof(leafIndices: LeafIndex[], at?: Hash): RpcResult<LeafBatchProof>;
};
36 changes: 18 additions & 18 deletions known/rpc/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReadProof, StorageData, StorageKey } from "./childstate.ts";
import { Hash, Hex, Result, SerdeEnum, Subscription } from "./utils.ts";
import { Hash, Hex, RpcResult, SerdeEnum, Subscription } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/01a3ad65/primitives/version/src/lib.rs#L161
/**
Expand Down Expand Up @@ -162,15 +162,15 @@ export interface Span {
// https://github.com/paritytech/substrate/blob/28ac0a8/client/rpc-api/src/state/mod.rs#L35
export type StateRpc = {
/** Call a contract at a block's state. */
state_call(name: string, bytes: Hex, at?: Hash): Result<Hex>;
state_call(name: string, bytes: Hex, at?: Hash): RpcResult<Hex>;
state_callAt: StateRpc["state_call"];
/**
* Returns the keys with prefix, leave empty to get all the keys.
* @deprecated [2.0.0] Please use `getKeysPaged` with proper paging support
*/
state_getKeys(prefix: StorageKey, at?: Hash): Result<StorageKey[]>;
state_getKeys(prefix: StorageKey, at?: Hash): RpcResult<StorageKey[]>;
/** Returns the keys with prefix, leave empty to get all the keys */
state_getPairs(prefix: StorageKey, at?: Hash): Result<[StorageKey, StorageData][]>;
state_getPairs(prefix: StorageKey, at?: Hash): RpcResult<[StorageKey, StorageData][]>;
/**
* Returns the keys with prefix with pagination support.
* Up to `count` keys will be returned.
Expand All @@ -181,21 +181,21 @@ export type StateRpc = {
count: number,
startKey?: StorageKey,
at?: Hash,
): Result<StorageKey[]>;
): RpcResult<StorageKey[]>;
state_getKeysPagedAt: StateRpc["state_getKeysPaged"];
/** Returns a storage entry at a specific block's state. */
state_getStorage(key: StorageKey, at?: Hash): Result<StorageData | null>;
state_getStorage(key: StorageKey, at?: Hash): RpcResult<StorageData | null>;
state_getStorageAt: StateRpc["state_getStorage"];
/** Returns the hash of a storage entry at a block's state. */
state_getStorageHash(key: StorageKey, at?: Hash): Result<Hash | null>;
state_getStorageHash(key: StorageKey, at?: Hash): RpcResult<Hash | null>;
state_getStorageHashAt: StateRpc["state_getStorageHash"];
/** Returns the size of a storage entry at a block's state. */
state_getStorageSize(key: StorageKey, at?: Hash): Result<number | null>;
state_getStorageSize(key: StorageKey, at?: Hash): RpcResult<number | null>;
state_getStorageSizeAt: StateRpc["state_getStorageSize"];
/** Returns the runtime metadata as an opaque blob. */
state_getMetadata(at?: Hash): Result<Hex | null>;
state_getMetadata(at?: Hash): RpcResult<Hex | null>;
/** Get the runtime version. */
state_getRuntimeVersion(at?: Hash): Result<RuntimeVersion>;
state_getRuntimeVersion(at?: Hash): RpcResult<RuntimeVersion>;
chain_getRuntimeVersion: StateRpc["state_getRuntimeVersion"];
/**
* Query historical storage entries (by key) starting from a block given as the second
Expand All @@ -204,32 +204,32 @@ export type StateRpc = {
* NOTE This first returned result contains the initial state of storage for all keys.
* Subsequent values in the vector represent changes to the previous state (diffs).
*/
state_queryStorage(keys: StorageKey[], block: Hash, at?: Hash): Result<StorageChangeSet[]>;
state_queryStorage(keys: StorageKey[], block: Hash, at?: Hash): RpcResult<StorageChangeSet[]>;
/** Query storage entries (by key) starting at block hash given as the second parameter. */
state_queryStorageAt(keys: StorageKey[], at?: Hash): Result<StorageChangeSet[]>;
state_queryStorageAt(keys: StorageKey[], at?: Hash): RpcResult<StorageChangeSet[]>;
/** Returns proof of storage entries at a specific block's state. */
state_getReadProof(keys: StorageKey[], at?: Hash): Result<ReadProof>;
state_getReadProof(keys: StorageKey[], at?: Hash): RpcResult<ReadProof>;
/** New runtime version subscription */
state_subscribeRuntimeVersion(): Result<
state_subscribeRuntimeVersion(): RpcResult<
Subscription<"state_subscribeRuntimeVersion", RuntimeVersion>
>;
state_unsubscribeRuntimeVersion(
subscription: Subscription<"state_subscribeRuntimeVersion", RuntimeVersion>,
): Result<void>;
): RpcResult<void>;
chain_subscribeRuntimeVersion: StateRpc["state_subscribeRuntimeVersion"];
chain_unsubscribeRuntimeVersion: StateRpc["state_unsubscribeRuntimeVersion"];
/** New storage subscription */
state_subscribeStorage(
keys: StorageKey[] | null,
): Result<Subscription<"state_subscribeStorage", StorageChangeSet>>;
): RpcResult<Subscription<"state_subscribeStorage", StorageChangeSet>>;
state_unsubscribeStorage(
subscription: Subscription<"state_subscribeStorage", StorageChangeSet>,
): Result<void>;
): RpcResult<void>;
/** See https://paritytech.github.io/substrate/master/sc_rpc_api/state/trait.StateApiServer.html#tymethod.trace_block */
state_traceBlock(
block: Hash,
targets?: string,
storageKeys?: string,
methods?: string,
): Result<TraceBlockResponse>;
): RpcResult<TraceBlockResponse>;
};
36 changes: 18 additions & 18 deletions known/rpc/system.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hash, Result, SerdeEnum } from "./utils.ts";
import { Hash, RpcResult, SerdeEnum } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/57e3486/client/chain-spec/src/lib.rs#L198
export type ChainType = SerdeEnum<{
Expand Down Expand Up @@ -62,34 +62,34 @@ export interface SyncState {
// https://github.com/paritytech/substrate/blob/e0ccd00/client/rpc-api/src/system/mod.rs#L33
export type SystemRpc = {
/** Get the node's implementation name. Plain old string. */
system_name(): Result<string>;
system_name(): RpcResult<string>;
/** Get the node implementation's version. Should be a semver string. */
system_version(): Result<string>;
system_version(): RpcResult<string>;
/** Get the chain's name. Given as a string identifier. */
system_chain(): Result<string>;
system_chain(): RpcResult<string>;
/** Get the chain's type. */
system_chainType(): Result<ChainType>;
system_chainType(): RpcResult<ChainType>;
/** Get a custom set of properties as a JSON object, defined in the chain spec. */
system_properties(): Result<Record<string, unknown>>;
system_properties(): RpcResult<Record<string, unknown>>;
/**
* Return health status of the node.
*
* Node is considered healthy if it is:
* - connected to some peers (unless running in dev mode)
* - not performing a major sync
*/
system_health(): Result<Health>;
system_health(): RpcResult<Health>;
/** Returns the base58-encoded PeerId of the node. */
system_localPeerId(): Result<string>;
system_localPeerId(): RpcResult<string>;
/**
* Returns the multi-addresses that the local node is listening on
*
* The addresses include a trailing `/p2p/` with the local PeerId, and are thus suitable to
* be passed to `addReservedPeer` or as a bootnode address for example.
*/
system_localListenAddresses(): Result<string[]>;
system_localListenAddresses(): RpcResult<string[]>;
/** Returns currently connected peers */
system_peers(): Result<PeerInfo[]>;
system_peers(): RpcResult<PeerInfo[]>;
/**
* Returns current state of the network.
*
Expand All @@ -98,37 +98,37 @@ export type SystemRpc = {
*/
// TODO: the future of this call is uncertain: https://github.com/paritytech/substrate/issues/1890
// https://github.com/paritytech/substrate/issues/5541
system_networkState(): Result<unknown>;
system_networkState(): RpcResult<unknown>;
/**
* Adds a reserved peer. Returns the empty string or an error. The string
* parameter should encode a `p2p` multiaddr.
*
* `/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV`
* is an example of a valid, passing multiaddr with PeerId attached.
*/
system_addReservedPeer(peer: string): Result<void>;
system_addReservedPeer(peer: string): RpcResult<void>;
/**
* Remove a reserved peer. Returns the empty string or an error. The string
* should encode only the PeerId e.g. `QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV`.
*/
system_removeReservedPeer(peerId: string): Result<void>;
system_removeReservedPeer(peerId: string): RpcResult<void>;
/** Returns the list of reserved peers */
system_reservedPeers(): Result<string[]>;
system_reservedPeers(): RpcResult<string[]>;
/** Returns the roles the node is running as. */
system_nodeRoles(): Result<NodeRole[]>;
system_nodeRoles(): RpcResult<NodeRole[]>;
/**
* Returns the state of the syncing of the node: starting block, current best block, highest
* known block.
*/
system_syncState(): Result<SyncState>;
system_syncState(): RpcResult<SyncState>;
/**
* Adds the supplied directives to the current log filter
*
* The syntax is identical to the CLI `<target>=<level>`:
*
* `sync=debug,state=trace`
*/
system_addLogFilter(directives: string): Result<void>;
system_addLogFilter(directives: string): RpcResult<void>;
/** Resets the log filter to Substrate defaults */
system_resetLogFilter(): Result<void>;
system_resetLogFilter(): RpcResult<void>;
};
4 changes: 2 additions & 2 deletions known/rpc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Hex = U.Hex;
export type Hash = U.HexHash;
export type SubId = string;
export type AccountId = string;
export type Subscription<T, U> = null;
export type Subscription<T, U> = string & { _subscription: [T, U] };
export type NumberOrHex = U.HexEncoded<bigint> | number;
export type ListOrValue<T> = T | T[];
export type Result<T> = T;
export type RpcResult<T> = T;

0 comments on commit 77399da

Please sign in to comment.