Complexity cleanups (#1303)
* Complexity cleanups * Revert spread * Sig wrapping * Use InterfaceTypes in rpc definitions * Types for rpc definitions
This commit is contained in:
@@ -12,7 +12,6 @@ import createParam from './create/param';
|
||||
const getHeader: RpcMethodOpt = {
|
||||
description: 'Retrieves the header for a specific block',
|
||||
params: [
|
||||
// @ts-ignore srml types
|
||||
createParam('hash', 'Hash', { isOptional: true })
|
||||
],
|
||||
type: 'Header'
|
||||
@@ -21,7 +20,6 @@ const getHeader: RpcMethodOpt = {
|
||||
const getBlock: RpcMethodOpt = {
|
||||
description: 'Get header and body of a relay chain block',
|
||||
params: [
|
||||
// @ts-ignore srml types
|
||||
createParam('hash', 'Hash', { isOptional: true })
|
||||
],
|
||||
type: 'SignedBlock'
|
||||
@@ -30,24 +28,20 @@ const getBlock: RpcMethodOpt = {
|
||||
const getBlockHash: RpcMethodOpt = {
|
||||
description: 'Get the block hash for a specific block',
|
||||
params: [
|
||||
// @ts-ignore This whould be fixed if we can get types from srml strings
|
||||
createParam('blockNumber', 'BlockNumber', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore srml types
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getFinalizedHead: RpcMethodOpt = {
|
||||
description: 'Get hash of the last finalized block in the canon chain',
|
||||
params: [],
|
||||
// @ts-ignore srml types
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getRuntimeVersion: RpcMethodOpt = {
|
||||
description: 'Get the runtime version (alias of state_getRuntimeVersion)',
|
||||
params: [
|
||||
// @ts-ignore srml types
|
||||
createParam('hash', 'Hash', { isOptional: true })
|
||||
],
|
||||
type: 'RuntimeVersion'
|
||||
@@ -99,11 +93,9 @@ export default {
|
||||
methods: {
|
||||
getBlock: createMethod(section, 'getBlock', getBlock),
|
||||
getBlockHash: createMethod(section, 'getBlockHash', getBlockHash),
|
||||
// TODO US spelling
|
||||
getFinalizedHead: createMethod(section, 'getFinalizedHead', getFinalizedHead),
|
||||
getHeader: createMethod(section, 'getHeader', getHeader),
|
||||
getRuntimeVersion: createMethod(section, 'getRuntimeVersion', getRuntimeVersion),
|
||||
// TODO US spelling
|
||||
subscribeFinalizedHeads: createMethod(section, 'subscribeFinalizedHeads', subscribeFinalizedHeads),
|
||||
subscribeRuntimeVersion: createMethod(section, 'subscribeRuntimeVersion', subscribeRuntimeVersion),
|
||||
subscribeNewHead: createMethod(section, 'subscribeNewHead', subscribeNewHead)
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// FIXME Can be one of the injected types (as type below)
|
||||
// import { CodecTypes } from '@polkadot/types/classes';
|
||||
import { InterfaceTypes } from '@polkadot/types/types';
|
||||
import { RpcParam } from '../types';
|
||||
|
||||
interface RpcParamOptions {
|
||||
isOptional?: boolean;
|
||||
}
|
||||
|
||||
export default function createParam (name: string, type: string, { isOptional = false }: RpcParamOptions = { isOptional: false }): RpcParam {
|
||||
export default function createParam (name: string, type: InterfaceTypes, { isOptional = false }: RpcParamOptions = { isOptional: false }): RpcParam {
|
||||
return {
|
||||
isOptional,
|
||||
name,
|
||||
|
||||
@@ -14,113 +14,82 @@ const call: RpcMethodOpt = {
|
||||
params: [
|
||||
createParam('method', 'Text'),
|
||||
createParam('data', 'Bytes'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
type: 'Bytes'
|
||||
};
|
||||
|
||||
const KEY_QUERY_PARAMS = [
|
||||
createParam('key', 'StorageKey'),
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
];
|
||||
|
||||
const getKeys: RpcMethodOpt = {
|
||||
description: 'Retrieves the keys with a certain prefix',
|
||||
params: [
|
||||
createParam('prefix', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
params: KEY_QUERY_PARAMS,
|
||||
type: 'Vec<StorageKey>'
|
||||
};
|
||||
|
||||
const getStorage: RpcMethodOpt = {
|
||||
description: 'Retrieves the storage for a key',
|
||||
params: [
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
params: KEY_QUERY_PARAMS,
|
||||
type: 'StorageData'
|
||||
};
|
||||
|
||||
const getStorageHash: RpcMethodOpt = {
|
||||
description: 'Retrieves the storage hash',
|
||||
params: [
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore srml types
|
||||
params: KEY_QUERY_PARAMS,
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getStorageSize: RpcMethodOpt = {
|
||||
description: 'Retrieves the storage size',
|
||||
params: [
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
params: KEY_QUERY_PARAMS,
|
||||
type: 'u64'
|
||||
};
|
||||
|
||||
const CHILD_QUERY_PARAMS = [
|
||||
createParam('childStorageKey', 'StorageKey'),
|
||||
createParam('key', 'StorageKey'),
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
];
|
||||
|
||||
const getChildKeys: RpcMethodOpt = {
|
||||
description: 'Retrieves the keys with prefix of a specific child storage',
|
||||
params: [
|
||||
createParam('childStorageKey', 'StorageKey'),
|
||||
createParam('prefix', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
params: CHILD_QUERY_PARAMS,
|
||||
type: 'Vec<StorageKey>'
|
||||
};
|
||||
|
||||
const getChildStorage: RpcMethodOpt = {
|
||||
description: 'Retrieves the child storage for a key',
|
||||
params: [
|
||||
createParam('childStorageKey', 'StorageKey'),
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
params: CHILD_QUERY_PARAMS,
|
||||
type: 'StorageData'
|
||||
};
|
||||
|
||||
const getChildStorageHash: RpcMethodOpt = {
|
||||
description: 'Retrieves the child storage hash',
|
||||
params: [
|
||||
createParam('childStorageKey', 'StorageKey'),
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore srml types
|
||||
params: CHILD_QUERY_PARAMS,
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getChildStorageSize: RpcMethodOpt = {
|
||||
description: 'Retrieves the child storage size',
|
||||
params: [
|
||||
createParam('childStorageKey', 'StorageKey'),
|
||||
createParam('key', 'StorageKey'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
params: CHILD_QUERY_PARAMS,
|
||||
type: 'u64'
|
||||
};
|
||||
|
||||
const getMetadata: RpcMethodOpt = {
|
||||
description: 'Returns the runtime metadata',
|
||||
params: [
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore This is not part of InterfaceTypes
|
||||
type: 'Metadata'
|
||||
};
|
||||
|
||||
const getRuntimeVersion: RpcMethodOpt = {
|
||||
description: 'Get the runtime version',
|
||||
params: [
|
||||
// @ts-ignore srml types
|
||||
createParam('hash', 'Hash', { isOptional: true })
|
||||
],
|
||||
type: 'RuntimeVersion'
|
||||
@@ -129,21 +98,16 @@ const getRuntimeVersion: RpcMethodOpt = {
|
||||
const queryStorage: RpcMethodOpt = {
|
||||
description: 'Query historical storage entries (by key) starting from a start block',
|
||||
params: [
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
createParam('keys', 'Vec<StorageKey>'),
|
||||
// @ts-ignore srml types
|
||||
createParam('startBlock', 'Hash'),
|
||||
// @ts-ignore srml types
|
||||
createParam('block', 'Hash', { isOptional: true })
|
||||
],
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
type: 'Vec<StorageChangeSet>'
|
||||
};
|
||||
|
||||
const subscribeStorage: RpcMethodOpt = {
|
||||
description: 'Subscribes to storage changes for the provided keys',
|
||||
params: [
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
createParam('keys', 'Vec<StorageKey>')
|
||||
],
|
||||
pubsub: [
|
||||
|
||||
@@ -41,7 +41,6 @@ const health: RpcMethodOpt = {
|
||||
const peers: RpcMethodOpt = {
|
||||
description: 'Returns the currently connected peers',
|
||||
params: [],
|
||||
// @ts-ignore the Vec<> wrap is fine
|
||||
type: 'Vec<PeerInfo>'
|
||||
};
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// import { CodecTypes } from '@polkadot/types/classes';
|
||||
import { InterfaceTypes } from '@polkadot/types/types';
|
||||
|
||||
type PubSub = [string, string, string];
|
||||
|
||||
export interface RpcParam {
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
type: string; // CodecTypes;
|
||||
type: InterfaceTypes;
|
||||
}
|
||||
|
||||
export interface RpcMethodOpt {
|
||||
@@ -20,7 +20,7 @@ export interface RpcMethodOpt {
|
||||
isSubscription?: boolean;
|
||||
params: RpcParam[];
|
||||
pubsub?: PubSub;
|
||||
type: string; // CodecTypes;
|
||||
type: InterfaceTypes;
|
||||
}
|
||||
|
||||
export interface RpcMethod {
|
||||
@@ -34,7 +34,7 @@ export interface RpcMethod {
|
||||
params: RpcParam[];
|
||||
pubsub: PubSub;
|
||||
section: string;
|
||||
type: string; // CodecTypes;
|
||||
type: InterfaceTypes;
|
||||
}
|
||||
|
||||
export interface RpcSection {
|
||||
|
||||
Reference in New Issue
Block a user