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 5cb16d7
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 92 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>;
};
4 changes: 2 additions & 2 deletions known/rpc/babe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountId, Result } from "./utils.ts";
import { AccountId, RpcResult } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/9b01569/client/consensus/babe/rpc/src/lib.rs#L154
/** Holds information about the `slot`'s that can be claimed by a given key. */
Expand All @@ -17,5 +17,5 @@ export type BabeRpc = {
* Returns data about which slots (primary or secondary) can be claimed in
* the current epoch with the keys in the keystore.
*/
babe_epochAuthorship(): Result<Record<AccountId, EpochAuthorship>>;
babe_epochAuthorship(): RpcResult<Record<AccountId, EpochAuthorship>>;
};
6 changes: 3 additions & 3 deletions known/rpc/beefy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Hash, Hex, Result, Subscription } from "./utils.ts";
import { Hash, Hex, RpcResult, Subscription } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/317808a/client/beefy/rpc/src/lib.rs#L84
export type BeefyRpc = {
/** Returns the block most recently finalized by BEEFY, alongside side its justification. */
beefy_subscribeJustifications(): Result<
beefy_subscribeJustifications(): RpcResult<
Subscription<"beefy_subscribeJustifications", Hex>
>;
/**
Expand All @@ -13,5 +13,5 @@ export type BeefyRpc = {
* in the network or if the client is still initializing or syncing with the network.
* In such case an error would be returned.
*/
beefy_getFinalizedHead(): Result<Hash>;
beefy_getFinalizedHead(): RpcResult<Hash>;
};
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"];
};
16 changes: 8 additions & 8 deletions known/rpc/childstate.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/4d04aba/primitives/storage/src/lib.rs
export type StorageKey = Hex;
Expand All @@ -23,7 +23,7 @@ export type ChildStateRpc = {
childStorageKey: PrefixedStorageKey,
prefix: StorageKey,
hash?: Hash,
): Result<StorageKey[]>;
): RpcResult<StorageKey[]>;
/**
* Returns the keys with prefix from a child storage with pagination support.
* Up to `count` keys will be returned.
Expand All @@ -35,35 +35,35 @@ export type ChildStateRpc = {
count: number,
startKey?: StorageKey,
hash?: Hash,
): Result<StorageKey[]>;
): RpcResult<StorageKey[]>;
/** Returns a child storage entry at a specific block's state. */
childState_getStorage(
childStorageKey: PrefixedStorageKey,
key: StorageKey,
hash?: Hash,
): Result<StorageData | null>;
): RpcResult<StorageData | null>;
/** Returns child storage entries for multiple keys at a specific block's state. */
childState_getStorageEntries(
childStorageKey: PrefixedStorageKey,
keys: StorageKey[],
hash?: Hash,
): Result<(StorageData | null)[]>;
): RpcResult<(StorageData | null)[]>;
/** Returns the hash of a child storage entry at a block's state. */
childState_getStorageHash(
childStorageKey: PrefixedStorageKey,
key: StorageKey,
hash?: Hash,
): Result<Hash | null>;
): RpcResult<Hash | null>;
/** Returns the size of a child storage entry at a block's state. */
childState_getStorageSize(
childStorageKey: PrefixedStorageKey,
key: StorageKey,
hash?: Hash,
): Result<number | null>;
): RpcResult<number | null>;
/** Returns proof of storage for child key entries at a specific block's state. */
state_getChildReadProof(
childStorageKey: PrefixedStorageKey,
keys: StorageKey[],
hash?: Hash,
): Result<ReadProof>;
): RpcResult<ReadProof>;
};
10 changes: 5 additions & 5 deletions known/rpc/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountId, Hash, Hex, NumberOrHex, Result, SerdeEnum, SerdeResult } from "./utils.ts";
import { AccountId, Hash, Hex, NumberOrHex, RpcResult, SerdeEnum, SerdeResult } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/0246883/frame/contracts/rpc/src/lib.rs#L92
/** A struct that encodes RPC parameters required for a call to a smart-contract. */
Expand Down Expand Up @@ -233,7 +233,7 @@ export type ContractsRpc = {
contracts_call(
callRequest: CallRequest,
at?: Hash,
): Result<ContractResult<SerdeResult<ExecReturnValue, DispatchError>>>;
): RpcResult<ContractResult<SerdeResult<ExecReturnValue, DispatchError>>>;
/**
* Instantiate a new contract.
*
Expand All @@ -244,7 +244,7 @@ export type ContractsRpc = {
*/
contracts_instantiate(
instantiateRequest: InstantiateRequest,
): Result<ContractResult<SerdeResult<InstantiateReturnValue, DispatchError>>>;
): RpcResult<ContractResult<SerdeResult<InstantiateReturnValue, DispatchError>>>;
/**
* Upload new code without instantiating a contract from it.
*
Expand All @@ -256,7 +256,7 @@ export type ContractsRpc = {
contracts_upload_code(
uploadRequest: CodeUploadRequest,
at?: Hash,
): Result<SerdeResult<CodeUploadReturnValue, DispatchError>>;
): RpcResult<SerdeResult<CodeUploadReturnValue, DispatchError>>;
/**
* Returns the value under a specified storage `key` in a contract given by `address` param,
* or `None` if it is not set.
Expand All @@ -265,5 +265,5 @@ export type ContractsRpc = {
accountId: AccountId,
key: Hex,
aat?: Hash,
): Result<Hex | null>;
): RpcResult<Hex | null>;
};
6 changes: 3 additions & 3 deletions known/rpc/framesystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountId, Hash, Hex, Result } from "./utils.ts";
import { AccountId, Hash, Hex, RpcResult } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/eddf888/utils/frame/rpc/system/src/lib.rs#L41
export type FrameSystemRpc = {
Expand All @@ -9,9 +9,9 @@ export type FrameSystemRpc = {
* currently in the pool and if no transactions are found in the pool
* it fallbacks to query the index from the runtime (aka. state nonce).
*/
system_accountNextIndex(account: AccountId): Result<number>;
system_accountNextIndex(account: AccountId): RpcResult<number>;
account_nextIndex: FrameSystemRpc["system_accountNextIndex"];
/** Dry run an extrinsic at a given block. Return SCALE encoded ApplyExtrinsicResult. */
system_dryRun(extrinsic: Hex, at?: Hash): Result<Hex>;
system_dryRun(extrinsic: Hex, at?: Hash): RpcResult<Hex>;
system_dryRunAt: FrameSystemRpc["system_dryRun"];
};
8 changes: 4 additions & 4 deletions known/rpc/grandpa.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hex, Result, Subscription } from "./utils.ts";
import { Hex, RpcResult, Subscription } from "./utils.ts";

// https://github.com/paritytech/substrate/blob/0ba251c/client/finality-grandpa/rpc/src/report.rs#L116
/**
Expand Down Expand Up @@ -45,12 +45,12 @@ export type GrandpaRpc = {
* Returns the state of the current best round state as well as the
* ongoing background rounds.
*/
grandpa_roundState(): Result<ReportedRoundStates>;
grandpa_roundState(): RpcResult<ReportedRoundStates>;
/**
* Returns the block most recently finalized by Grandpa, alongside
* side its justification.
*/
grandpa_subscribeJustifications(): Result<
grandpa_subscribeJustifications(): RpcResult<
Subscription<"grandpa_subscribeJustifications", JustificationNotification>
>;
grandpa_unsubscribeJustifications(
Expand All @@ -60,5 +60,5 @@ export type GrandpaRpc = {
* Prove finality for the given block number by returning the Justification for the last block
* in the set and all the intermediary headers to link them together.
*/
grandpa_proveFinality(block: number): Result<EncodedFinalityProof | null>;
grandpa_proveFinality(block: number): RpcResult<EncodedFinalityProof | null>;
};
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>;
};
6 changes: 3 additions & 3 deletions known/rpc/offchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hex, Result, SerdeEnum } from "./utils.ts";
import { Hex, RpcResult, SerdeEnum } from "./utils.ts";

/** A type of supported crypto. */
export type StorageKind = SerdeEnum<{
Expand All @@ -23,7 +23,7 @@ export type StorageKind = SerdeEnum<{
// https://github.com/paritytech/substrate/blob/7d233c2/client/rpc-api/src/offchain/mod.rs#L28
export type OffchainRpc = {
/** Set offchain local storage under given key and prefix. */
offchain_localStorageSet(kind: StorageKind, key: Hex, value: Hex): Result<null>;
offchain_localStorageSet(kind: StorageKind, key: Hex, value: Hex): RpcResult<null>;
/** Get offchain local storage under given key and prefix. */
offchain_localStorageGet(kind: StorageKind, key: Hex): Result<Hex | null>;
offchain_localStorageGet(kind: StorageKind, key: Hex): RpcResult<Hex | null>;
};
Loading

0 comments on commit 5cb16d7

Please sign in to comment.