Cleanup jsonrpc, refer to api-codec (#174)
* Cleanup jsonrpc, refer to api-codec * Move storagekey legacy into type-params (legacy) * Remove misplaced debug log * Remove header encoding, use api-codec/Header * Remove legacy types * Add metadat array (hack around json import) * Move json metadata to ts
This commit is contained in:
@@ -2,45 +2,43 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section, SectionItems } from '@polkadot/params/types';
|
||||
import { Interfaces, Interface$Sections } from './types';
|
||||
import { MethodOpt, Section, SectionMethods } from './types';
|
||||
|
||||
import param from '@polkadot/params/param';
|
||||
import createSection from '@polkadot/params/section';
|
||||
import createMethod from './create/method';
|
||||
import createParam from './create/param';
|
||||
|
||||
const pendingExtrinsics: CreateItemOptions = {
|
||||
const pendingExtrinsics: MethodOpt = {
|
||||
description: 'Returns all pending extrinsics, potentially grouped by sender',
|
||||
params: [],
|
||||
type: 'PendingExtrinsics'
|
||||
};
|
||||
|
||||
const submitExtrinsic: CreateItemOptions = {
|
||||
const submitExtrinsic: MethodOpt = {
|
||||
isSigned: true,
|
||||
description: 'Submit a fully formatted extrinsic for block inclusion',
|
||||
params: [
|
||||
param('extrinsic', 'Bytes')
|
||||
createParam('extrinsic', 'Bytes')
|
||||
],
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const privateMethods: CreateItemOptionsMap = {};
|
||||
|
||||
const publicMethods: CreateItemOptionsMap = {
|
||||
const methods: { [index: string]: MethodOpt } = {
|
||||
pendingExtrinsics, submitExtrinsic
|
||||
};
|
||||
|
||||
export type PrivateMethods = typeof privateMethods;
|
||||
export type PublicMethods = typeof publicMethods;
|
||||
export type Methods = typeof methods;
|
||||
|
||||
/**
|
||||
* @summary Methods to work with authors & contributors.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Authoring of network items',
|
||||
public: Object.keys(publicMethods).reduce((result, key) => {
|
||||
result[key] = createMethod(key)(publicMethods[key]);
|
||||
export default {
|
||||
isDeprecated: false,
|
||||
isHidden: false,
|
||||
description: 'Authoring of network items',
|
||||
name: 'author',
|
||||
methods: Object.keys(methods).reduce((result, key) => {
|
||||
result[key] = createMethod('author', key, methods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionItems<Interfaces, PublicMethods>)
|
||||
}));
|
||||
return result;
|
||||
}, {} as SectionMethods<Methods>)
|
||||
} as Section<Methods>;
|
||||
|
||||
@@ -2,49 +2,48 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section, SectionItems } from '@polkadot/params/types';
|
||||
import { Interfaces, Interface$Sections } from './types';
|
||||
import { MethodOpt, Section, SectionMethods } from './types';
|
||||
|
||||
import param from '@polkadot/params/param';
|
||||
import createSection from '@polkadot/params/section';
|
||||
import createMethod from './create/method';
|
||||
import createParam from './create/param';
|
||||
|
||||
const getBlock: CreateItemOptions = {
|
||||
const getBlock: MethodOpt = {
|
||||
description: 'Get header and body of a relay chain block',
|
||||
params: [
|
||||
param('hash', 'Hash')
|
||||
createParam('hash', 'Hash')
|
||||
],
|
||||
type: 'SignedBlock'
|
||||
};
|
||||
|
||||
const getHead: CreateItemOptions = {
|
||||
const getHead: MethodOpt = {
|
||||
description: 'Retrieves the best headerHash',
|
||||
params: [],
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getHeader: CreateItemOptions = {
|
||||
const getHeader: MethodOpt = {
|
||||
description: 'Retrieves the header for a specific block',
|
||||
params: [
|
||||
param('hash', 'Hash')
|
||||
createParam('hash', 'Hash')
|
||||
],
|
||||
type: 'Header'
|
||||
};
|
||||
|
||||
const getRuntimeVersion: CreateItemOptions = {
|
||||
const getRuntimeVersion: MethodOpt = {
|
||||
description: ' Get the runtime version',
|
||||
params: [],
|
||||
type: 'RuntimeVersion'
|
||||
};
|
||||
|
||||
const getRuntimeVersionAt: CreateItemOptions = {
|
||||
const getRuntimeVersionAt: MethodOpt = {
|
||||
description: ' Get the runtime version at a specific block',
|
||||
params: [
|
||||
param('hash', 'Hash')
|
||||
createParam('hash', 'Hash')
|
||||
],
|
||||
type: 'RuntimeVersion'
|
||||
};
|
||||
|
||||
const newHead: CreateItemOptions = {
|
||||
const newHead: MethodOpt = {
|
||||
description: 'Retrieves the best header via subscription',
|
||||
subscribe: [
|
||||
'chain_subscribeNewHead',
|
||||
@@ -54,24 +53,23 @@ const newHead: CreateItemOptions = {
|
||||
type: 'Header'
|
||||
};
|
||||
|
||||
const privateMethods: CreateItemOptionsMap = {};
|
||||
|
||||
const publicMethods: CreateItemOptionsMap = {
|
||||
const methods: { [index: string]: MethodOpt } = {
|
||||
getBlock, getHead, getHeader, getRuntimeVersion, getRuntimeVersionAt, newHead
|
||||
};
|
||||
|
||||
export type PublicMethods = typeof publicMethods;
|
||||
export type PrivateMethods = typeof privateMethods;
|
||||
export type Methods = typeof methods;
|
||||
|
||||
/**
|
||||
* @summary Methods to retrieve chain data.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Retrieval of chain data',
|
||||
public: Object.keys(publicMethods).reduce((result, key) => {
|
||||
result[key] = createMethod(key)(publicMethods[key]);
|
||||
export default {
|
||||
isDeprecated: false,
|
||||
isHidden: false,
|
||||
description: 'Retrieval of chain data',
|
||||
name: 'chain',
|
||||
methods: Object.keys(methods).reduce((result, key) => {
|
||||
result[key] = createMethod('chain', key, methods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionItems<Interfaces, PublicMethods>)
|
||||
}));
|
||||
return result;
|
||||
}, {} as SectionMethods<Methods>)
|
||||
} as Section<Methods>;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2018 @polkadot/jsonrpc authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { MethodOpt, Method } from '../types';
|
||||
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
|
||||
export default function createMethod (section: string, name: string, { description, params, type, isDeprecated = false, isHidden = false, isSigned = false, subscribe }: MethodOpt): Method {
|
||||
return {
|
||||
description,
|
||||
isDeprecated,
|
||||
isHidden,
|
||||
isSigned,
|
||||
isSubscription: !isUndefined(subscribe),
|
||||
name,
|
||||
params,
|
||||
section,
|
||||
subscribe: subscribe || ['', ''],
|
||||
type
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2018 @polkadot/jsonrpc authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CodecTypes } from '@polkadot/api-codec/types';
|
||||
import { Param } from '../types';
|
||||
|
||||
type ParamOptions = {
|
||||
isOptional?: boolean
|
||||
};
|
||||
|
||||
export default function createParam (name: string, type: CodecTypes, { isOptional = false }: ParamOptions = { isOptional: false }): Param {
|
||||
return {
|
||||
isOptional,
|
||||
name,
|
||||
type
|
||||
};
|
||||
}
|
||||
@@ -2,18 +2,16 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interfaces } from './types';
|
||||
|
||||
import author from './author';
|
||||
import chain from './chain';
|
||||
import state from './state';
|
||||
import system from './system';
|
||||
|
||||
const interfaces: Interfaces = {
|
||||
author: author('author'),
|
||||
chain: chain('chain'),
|
||||
state: state('state'),
|
||||
system: system('system')
|
||||
const interfaces = {
|
||||
author,
|
||||
chain,
|
||||
state,
|
||||
system
|
||||
};
|
||||
|
||||
export default interfaces;
|
||||
|
||||
@@ -2,145 +2,125 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section } from '@polkadot/params/types';
|
||||
import { Interfaces, Interface$Sections } from './types';
|
||||
import { MethodOpt, Section, SectionMethods } from './types';
|
||||
|
||||
import param from '@polkadot/params/param';
|
||||
import createSection from '@polkadot/params/section';
|
||||
import createMethod from './create/method';
|
||||
import createParam from './create/param';
|
||||
|
||||
const call: CreateItemOptions = {
|
||||
const call: MethodOpt = {
|
||||
description: 'Perform a call to a builtin on the chain',
|
||||
params: [
|
||||
param('method', 'String'),
|
||||
param('data', 'Bytes')
|
||||
createParam('method', 'Text'),
|
||||
createParam('data', 'Bytes')
|
||||
],
|
||||
type: 'Bytes'
|
||||
};
|
||||
|
||||
const callAt: CreateItemOptions = {
|
||||
const callAt: MethodOpt = {
|
||||
description: 'Perform a call to a builtin on the chain (At block)',
|
||||
params: [
|
||||
param('method', 'String'),
|
||||
param('data', 'Bytes'),
|
||||
param('block', 'Hash')
|
||||
createParam('method', 'Text'),
|
||||
createParam('data', 'Bytes'),
|
||||
createParam('block', 'Hash')
|
||||
],
|
||||
type: 'Bytes'
|
||||
};
|
||||
|
||||
const getMetadata: CreateItemOptions = {
|
||||
const getMetadata: MethodOpt = {
|
||||
description: 'Returns the runtime metadata',
|
||||
params: [],
|
||||
type: 'Metadata'
|
||||
};
|
||||
|
||||
const getMetadataAt: CreateItemOptions = {
|
||||
const getMetadataAt: MethodOpt = {
|
||||
description: 'Returns the runtime metadata',
|
||||
params: [
|
||||
param('block', 'Hash')
|
||||
createParam('block', 'Hash')
|
||||
],
|
||||
type: 'Metadata'
|
||||
};
|
||||
|
||||
const getStorage: CreateItemOptions = {
|
||||
const getStorage: MethodOpt = {
|
||||
description: 'Retrieves the storage for a key',
|
||||
params: [
|
||||
param('key', 'StorageKey')
|
||||
createParam('key', 'StorageKey')
|
||||
],
|
||||
type: 'StorageData'
|
||||
};
|
||||
|
||||
const getStorageAt: CreateItemOptions = {
|
||||
const getStorageAt: MethodOpt = {
|
||||
description: 'Retrieves the storage for a key at a specific block',
|
||||
params: [
|
||||
param('key', 'Bytes'),
|
||||
param('block', 'Hash')
|
||||
createParam('key', 'Bytes'),
|
||||
createParam('block', 'Hash')
|
||||
],
|
||||
type: 'Bytes'
|
||||
};
|
||||
|
||||
const getStorageHash: CreateItemOptions = {
|
||||
const getStorageHash: MethodOpt = {
|
||||
description: 'Retrieves the storage hash',
|
||||
params: [
|
||||
param('key', 'Bytes')
|
||||
createParam('key', 'Bytes')
|
||||
],
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getStorageHashAt: CreateItemOptions = {
|
||||
const getStorageHashAt: MethodOpt = {
|
||||
description: 'Retrieves the storage hash at a specific block',
|
||||
params: [
|
||||
param('key', 'Bytes'),
|
||||
param('block', 'Hash')
|
||||
createParam('key', 'Bytes'),
|
||||
createParam('block', 'Hash')
|
||||
],
|
||||
type: 'Hash'
|
||||
};
|
||||
|
||||
const getStorageSize: CreateItemOptions = {
|
||||
const getStorageSize: MethodOpt = {
|
||||
description: 'Retrieves the storage size',
|
||||
params: [
|
||||
param('key', 'Bytes')
|
||||
createParam('key', 'Bytes')
|
||||
],
|
||||
type: 'u64'
|
||||
};
|
||||
|
||||
const getStorageSizeAt: CreateItemOptions = {
|
||||
const getStorageSizeAt: MethodOpt = {
|
||||
description: 'Retrieves the storage size at a specific block',
|
||||
params: [
|
||||
param('key', 'Bytes'),
|
||||
param('block', 'Hash')
|
||||
createParam('key', 'Bytes'),
|
||||
createParam('block', 'Hash')
|
||||
],
|
||||
type: 'u64'
|
||||
};
|
||||
|
||||
const storage: CreateItemOptions = {
|
||||
const storage: MethodOpt = {
|
||||
description: 'Subscribes to storage changes for the provided keys',
|
||||
subscribe: [
|
||||
'state_subscribeStorage',
|
||||
'state_unsubscribeStorage'
|
||||
],
|
||||
params: [
|
||||
param('keys', 'Vec<StorageKey>')
|
||||
// @ts-ignore The Vec<> wrap is fine
|
||||
createParam('keys', 'Vec<StorageKey>')
|
||||
],
|
||||
type: 'StorageChangeSet'
|
||||
};
|
||||
|
||||
const privateMethods: CreateItemOptionsMap = {};
|
||||
|
||||
const publicMethods: CreateItemOptionsMap = {
|
||||
call, callAt, getStorage, getStorageAt, getStorageHash, getStorageHashAt, getStorageSize, getStorageSizeAt, storage
|
||||
const methods: { [index: string]: MethodOpt } = {
|
||||
call, callAt, getMetadata, getMetadataAt, getStorage, getStorageAt, getStorageHash, getStorageHashAt, getStorageSize, getStorageSizeAt, storage
|
||||
};
|
||||
|
||||
export type PrivateMethods = typeof privateMethods;
|
||||
export type PublicMethods = typeof publicMethods;
|
||||
export type Methods = typeof methods;
|
||||
|
||||
/**
|
||||
* @summary Query the state and state storage.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Query of state',
|
||||
public: {
|
||||
call:
|
||||
createMethod('call')(call),
|
||||
callAt:
|
||||
createMethod('callAt')(callAt),
|
||||
getMetadata:
|
||||
createMethod('getMetadata')(getMetadata),
|
||||
getMetadataAt:
|
||||
createMethod('getMetadataAt')(getMetadataAt),
|
||||
getStorage:
|
||||
createMethod('getStorage')(getStorage),
|
||||
getStorageAt:
|
||||
createMethod('getStorageAt')(getStorageAt),
|
||||
getStorageHash:
|
||||
createMethod('getStorageHash')(getStorageHash),
|
||||
getStorageHashAt:
|
||||
createMethod('getStrorageHashAt')(getStorageHashAt),
|
||||
getStorageSize:
|
||||
createMethod('getStorageSize')(getStorageSize),
|
||||
getStorageSizeAt:
|
||||
createMethod('getStorageSizeAt')(getStorageSizeAt),
|
||||
storage:
|
||||
createMethod('storage')(storage)
|
||||
}
|
||||
}));
|
||||
export default {
|
||||
isDeprecated: false,
|
||||
isHidden: false,
|
||||
description: 'Query of state',
|
||||
name: 'state',
|
||||
methods: Object.keys(methods).reduce((result, key) => {
|
||||
result[key] = createMethod('state', key, methods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionMethods<Methods>)
|
||||
} as Section<Methods>;
|
||||
|
||||
@@ -2,50 +2,45 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section } from '@polkadot/params/types';
|
||||
import { Interfaces, Interface$Sections } from './types';
|
||||
import { MethodOpt, Section, SectionMethods } from './types';
|
||||
|
||||
import createSection from '@polkadot/params/section';
|
||||
import createMethod from './create/method';
|
||||
|
||||
const chain: CreateItemOptions = {
|
||||
const chain: MethodOpt = {
|
||||
description: 'Retrieves the chain',
|
||||
params: [],
|
||||
type: 'String'
|
||||
type: 'Text'
|
||||
};
|
||||
|
||||
const name: CreateItemOptions = {
|
||||
const name: MethodOpt = {
|
||||
description: 'Retrieves the node name',
|
||||
params: [],
|
||||
type: 'String'
|
||||
type: 'Text'
|
||||
};
|
||||
|
||||
const version: CreateItemOptions = {
|
||||
const version: MethodOpt = {
|
||||
description: 'Retrieves the version of the node',
|
||||
params: [],
|
||||
type: 'String'
|
||||
type: 'Text'
|
||||
};
|
||||
|
||||
const privateMethods: CreateItemOptionsMap = {};
|
||||
|
||||
const publicMethods: CreateItemOptionsMap = {
|
||||
const methods: { [index: string]: MethodOpt } = {
|
||||
chain, name, version
|
||||
};
|
||||
|
||||
export type PrivateMethods = typeof privateMethods;
|
||||
export type PublicMethods = typeof publicMethods;
|
||||
export type Methods = typeof methods;
|
||||
|
||||
/**
|
||||
* @summary Methods to retrieve system info.
|
||||
*/
|
||||
export default (sname: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(sname)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Methods to retrieve system info',
|
||||
public: {
|
||||
chain:
|
||||
createMethod('chain')(chain),
|
||||
name:
|
||||
createMethod('name')(name),
|
||||
version:
|
||||
createMethod('version')(version)
|
||||
}
|
||||
}));
|
||||
export default {
|
||||
isDeprecated: false,
|
||||
isHidden: false,
|
||||
description: 'Methods to retrieve system info',
|
||||
name: 'system',
|
||||
methods: Object.keys(methods).reduce((result, key) => {
|
||||
result[key] = createMethod('system', key, methods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionMethods<Methods>)
|
||||
} as Section<Methods>;
|
||||
|
||||
Vendored
+41
-12
@@ -2,17 +2,46 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Section } from '@polkadot/params/types';
|
||||
import { PrivateMethods as AuthorPrivate, PublicMethods as AuthorPublic} from './author';
|
||||
import { PrivateMethods as ChainPrivate, PublicMethods as ChainPublic} from './chain';
|
||||
import { PrivateMethods as StatePrivate, PublicMethods as StatePublic} from './state';
|
||||
import { PrivateMethods as SystemPrivate, PublicMethods as SystemPublic} from './system';
|
||||
import { CodecTypes } from '@polkadot/api-codec/types';
|
||||
|
||||
export type Interfaces = {
|
||||
author: Section<Interfaces, AuthorPrivate, AuthorPrivate>,
|
||||
chain: Section<Interfaces, ChainPrivate, ChainPublic>,
|
||||
state: Section<Interfaces, StatePrivate, StatePublic>,
|
||||
system: Section<Interfaces, SystemPrivate, SystemPublic>
|
||||
}
|
||||
export type Param = {
|
||||
isOptional: boolean,
|
||||
name: string,
|
||||
type: CodecTypes
|
||||
};
|
||||
|
||||
export type Interface$Sections = keyof Interfaces;
|
||||
export type MethodOpt = {
|
||||
description: string,
|
||||
isDeprecated?: boolean,
|
||||
isHidden?: boolean,
|
||||
isSigned?: boolean,
|
||||
isSubscription?: boolean,
|
||||
params: Array<Param>,
|
||||
subscribe?: [string, string],
|
||||
type: CodecTypes
|
||||
};
|
||||
|
||||
export type Method = {
|
||||
description: string,
|
||||
isDeprecated: boolean,
|
||||
isHidden: boolean,
|
||||
isSigned: boolean,
|
||||
isSubscription: boolean,
|
||||
name: string,
|
||||
params: Array<Param>,
|
||||
section: string,
|
||||
subscribe: [string, string],
|
||||
type: CodecTypes
|
||||
};
|
||||
|
||||
export type SectionMethods<M> = {
|
||||
[key in keyof M]: Method
|
||||
};
|
||||
|
||||
export type Section<M> = {
|
||||
isDeprecated: boolean,
|
||||
isHidden: boolean,
|
||||
description: string,
|
||||
name: string,
|
||||
methods: SectionMethods<M>
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user