diff --git a/known/rpc/author.ts b/known/rpc/author.ts index bb3ba2e40..3fee6778b 100644 --- a/known/rpc/author.ts +++ b/known/rpc/author.ts @@ -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 /** @@ -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 * @@ -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; + author_submitExtrinsic(extrinsic: Hex): RpcResult; /** Insert a key into the keystore. */ - author_insertKey(keyType: string, suri: string, publicKey: Hex): Result; + author_insertKey(keyType: string, suri: string, publicKey: Hex): RpcResult; /** Generate new session keys and returns the corresponding public keys. */ - author_rotateKeys(): Result; + author_rotateKeys(): RpcResult; /** * 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; + author_hasSessionKeys(sessionsKeys: Hex): RpcResult; /** * 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; + author_hasKey(pubKey: Hex, keyType: string): RpcResult; /** Returns all pending extrinsics, potentially grouped by sender. */ - author_pendingExtrinsics(): Result; + author_pendingExtrinsics(): RpcResult; /** Remove given extrinsic from the pool and temporarily ban it to prevent reimporting. */ - author_removeExtrinsic(extrinsics: ExtrinsicOrHash[]): Result; // todo + author_removeExtrinsic(extrinsics: ExtrinsicOrHash[]): RpcResult; // todo /** * Submit an extrinsic to watch. * @@ -121,8 +122,8 @@ export type AuthorRpc = { */ author_submitAndWatchExtrinsic( extrinsic: Hex, - ): Result>; + ): RpcResult>; author_unwatchExtrinsic( subscription: Subscription<"author_submitAndWatchExtrinsic", TransactionStatus>, - ): Result; + ): RpcResult; }; diff --git a/known/rpc/chain.ts b/known/rpc/chain.ts index 51d8581f0..1343d0afb 100644 --- a/known/rpc/chain.ts +++ b/known/rpc/chain.ts @@ -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. */ @@ -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
; + chain_getHeader(hash?: Hash): RpcResult
; /** Get header and body of a relay chain block. */ - chain_getBlock(hash?: Hash): Result; + chain_getBlock(hash?: Hash): RpcResult; /** * Get hash of the n-th block in the canon chain. * * By default returns latest block hash. */ - chain_getBlockHash(height?: ListOrValue): Result>; + chain_getBlockHash(height?: ListOrValue): RpcResult>; chain_getHead: ChainRpc["chain_getBlockHash"]; /** Get hash of the last finalized block in the canon chain. */ - chain_getFinalizedHead(): Result; + chain_getFinalizedHead(): RpcResult; chain_getFinalisedHead: ChainRpc["chain_getFinalizedHead"]; /** All head subscription. */ - chain_subscribeAllHeads(): Result>; + chain_subscribeAllHeads(): RpcResult>; chain_unsubscribeAllHeads( subscription: Subscription<"chain_subscribeAllHeads", Header>, - ): Result; + ): RpcResult; /** New head subscription. */ - chain_subscribeNewHeads(): Result>; + chain_subscribeNewHeads(): RpcResult>; chain_unsubscribeNewHeads( subscription: Subscription<"chain_subscribeAllHeads", Header>, - ): Result; + ): RpcResult; /** Finalized head subscription. */ - chain_subscribeFinalizedHeads(): Result>; + chain_subscribeFinalizedHeads(): RpcResult>; chain_unsubscribeFinalizedHeads( subscription: Subscription<"chain_subscribeAllHeads", Header>, - ): Result; + ): RpcResult; chain_subscribeFinalisedHeads: ChainRpc["chain_subscribeFinalizedHeads"]; chain_unsubscribeFinalisedHeads: ChainRpc["chain_unsubscribeFinalizedHeads"]; }; diff --git a/known/rpc/mmr.ts b/known/rpc/mmr.ts index 539943f27..245b0684d 100644 --- a/known/rpc/mmr.ts +++ b/known/rpc/mmr.ts @@ -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 /** @@ -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; + mmr_generateProof(leafIndex: LeafIndex, at?: Hash): RpcResult; /** * Generate MMR proof for the given leaf indices. * @@ -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; + mmr_generateBatchProof(leafIndices: LeafIndex[], at?: Hash): RpcResult; }; diff --git a/known/rpc/state.ts b/known/rpc/state.ts index ef848eb27..6ef24be2c 100644 --- a/known/rpc/state.ts +++ b/known/rpc/state.ts @@ -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 /** @@ -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; + state_call(name: string, bytes: Hex, at?: Hash): RpcResult; 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; + state_getKeys(prefix: StorageKey, at?: Hash): RpcResult; /** 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. @@ -181,21 +181,21 @@ export type StateRpc = { count: number, startKey?: StorageKey, at?: Hash, - ): Result; + ): RpcResult; state_getKeysPagedAt: StateRpc["state_getKeysPaged"]; /** Returns a storage entry at a specific block's state. */ - state_getStorage(key: StorageKey, at?: Hash): Result; + state_getStorage(key: StorageKey, at?: Hash): RpcResult; state_getStorageAt: StateRpc["state_getStorage"]; /** Returns the hash of a storage entry at a block's state. */ - state_getStorageHash(key: StorageKey, at?: Hash): Result; + state_getStorageHash(key: StorageKey, at?: Hash): RpcResult; state_getStorageHashAt: StateRpc["state_getStorageHash"]; /** Returns the size of a storage entry at a block's state. */ - state_getStorageSize(key: StorageKey, at?: Hash): Result; + state_getStorageSize(key: StorageKey, at?: Hash): RpcResult; state_getStorageSizeAt: StateRpc["state_getStorageSize"]; /** Returns the runtime metadata as an opaque blob. */ - state_getMetadata(at?: Hash): Result; + state_getMetadata(at?: Hash): RpcResult; /** Get the runtime version. */ - state_getRuntimeVersion(at?: Hash): Result; + state_getRuntimeVersion(at?: Hash): RpcResult; chain_getRuntimeVersion: StateRpc["state_getRuntimeVersion"]; /** * Query historical storage entries (by key) starting from a block given as the second @@ -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; + state_queryStorage(keys: StorageKey[], block: Hash, at?: Hash): RpcResult; /** Query storage entries (by key) starting at block hash given as the second parameter. */ - state_queryStorageAt(keys: StorageKey[], at?: Hash): Result; + state_queryStorageAt(keys: StorageKey[], at?: Hash): RpcResult; /** Returns proof of storage entries at a specific block's state. */ - state_getReadProof(keys: StorageKey[], at?: Hash): Result; + state_getReadProof(keys: StorageKey[], at?: Hash): RpcResult; /** New runtime version subscription */ - state_subscribeRuntimeVersion(): Result< + state_subscribeRuntimeVersion(): RpcResult< Subscription<"state_subscribeRuntimeVersion", RuntimeVersion> >; state_unsubscribeRuntimeVersion( subscription: Subscription<"state_subscribeRuntimeVersion", RuntimeVersion>, - ): Result; + ): RpcResult; chain_subscribeRuntimeVersion: StateRpc["state_subscribeRuntimeVersion"]; chain_unsubscribeRuntimeVersion: StateRpc["state_unsubscribeRuntimeVersion"]; /** New storage subscription */ state_subscribeStorage( keys: StorageKey[] | null, - ): Result>; + ): RpcResult>; state_unsubscribeStorage( subscription: Subscription<"state_subscribeStorage", StorageChangeSet>, - ): Result; + ): RpcResult; /** 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; + ): RpcResult; }; diff --git a/known/rpc/system.ts b/known/rpc/system.ts index 1faa1c142..18b3661e3 100644 --- a/known/rpc/system.ts +++ b/known/rpc/system.ts @@ -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<{ @@ -62,15 +62,15 @@ 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; + system_name(): RpcResult; /** Get the node implementation's version. Should be a semver string. */ - system_version(): Result; + system_version(): RpcResult; /** Get the chain's name. Given as a string identifier. */ - system_chain(): Result; + system_chain(): RpcResult; /** Get the chain's type. */ - system_chainType(): Result; + system_chainType(): RpcResult; /** Get a custom set of properties as a JSON object, defined in the chain spec. */ - system_properties(): Result>; + system_properties(): RpcResult>; /** * Return health status of the node. * @@ -78,18 +78,18 @@ export type SystemRpc = { * - connected to some peers (unless running in dev mode) * - not performing a major sync */ - system_health(): Result; + system_health(): RpcResult; /** Returns the base58-encoded PeerId of the node. */ - system_localPeerId(): Result; + system_localPeerId(): RpcResult; /** * 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; + system_localListenAddresses(): RpcResult; /** Returns currently connected peers */ - system_peers(): Result; + system_peers(): RpcResult; /** * Returns current state of the network. * @@ -98,7 +98,7 @@ 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; + system_networkState(): RpcResult; /** * Adds a reserved peer. Returns the empty string or an error. The string * parameter should encode a `p2p` multiaddr. @@ -106,21 +106,21 @@ export type SystemRpc = { * `/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; + system_addReservedPeer(peer: string): RpcResult; /** * 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; + system_removeReservedPeer(peerId: string): RpcResult; /** Returns the list of reserved peers */ - system_reservedPeers(): Result; + system_reservedPeers(): RpcResult; /** Returns the roles the node is running as. */ - system_nodeRoles(): Result; + system_nodeRoles(): RpcResult; /** * Returns the state of the syncing of the node: starting block, current best block, highest * known block. */ - system_syncState(): Result; + system_syncState(): RpcResult; /** * Adds the supplied directives to the current log filter * @@ -128,7 +128,7 @@ export type SystemRpc = { * * `sync=debug,state=trace` */ - system_addLogFilter(directives: string): Result; + system_addLogFilter(directives: string): RpcResult; /** Resets the log filter to Substrate defaults */ - system_resetLogFilter(): Result; + system_resetLogFilter(): RpcResult; }; diff --git a/known/rpc/utils.ts b/known/rpc/utils.ts index fdb3707bc..19094b882 100644 --- a/known/rpc/utils.ts +++ b/known/rpc/utils.ts @@ -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 = null; +export type Subscription = string & { _subscription: [T, U] }; export type NumberOrHex = U.HexEncoded | number; export type ListOrValue = T | T[]; -export type Result = T; +export type RpcResult = T;