Add rpc_methods (#1397)

* Add rpc_methods

* Adjust interface tests

* Add account_nextIndex & contracts_call, filter

* Rework AbstractArray includes with some

* Adjust tests

* Ordering

* Correct definitions (pull in from methods)

* Be agressive on filtering, regardless of isOptional

* async/await in filterRpcMethods

* map Text[] -> string[]

* Correct naming for account_nextIndex

* Remove/don't remove rpc_methods as applicable

* Cleanup method handling errors
This commit is contained in:
Jaco Greeff
2019-09-16 11:40:54 +02:00
committed by GitHub
parent 5576dacd9a
commit bed3f9f4c5
18 changed files with 262 additions and 12 deletions
+34
View File
@@ -0,0 +1,34 @@
// Copyright 2017-2019 @polkadot/jsonrpc authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethodOpt } from './types';
import createMethod from './create/method';
import createParam from './create/param';
// NOTE order here is the same as in Rust, alphabetical below
const nextIndex: RpcMethodOpt = {
description: 'Retrieves the next accountIndex as available on the node',
isOptional: true,
params: [
createParam('accountId', 'AccountId')
],
type: 'Index'
};
const section = 'account';
/**
* @summary Calls to retrieve system info.
*/
export default {
isDeprecated: false,
isHidden: false,
description: '(Optional) Methods that retrieves account-specific information',
section,
methods: {
nextIndex: createMethod(section, 'nextIndex', nextIndex)
}
};
+35
View File
@@ -0,0 +1,35 @@
// Copyright 2017-2019 @polkadot/jsonrpc authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethodOpt } from './types';
import createMethod from './create/method';
import createParam from './create/param';
// NOTE order here is the same as in Rust, alphabetical below
const call: RpcMethodOpt = {
description: 'Executes a call to a contract',
isOptional: true,
params: [
createParam('callRequest', 'ContractCallRequest'),
createParam('at', 'Hash', { isOptional: true })
],
type: 'ContractExecResult'
};
const section = 'contracts';
/**
* @summary Calls to retrieve system info.
*/
export default {
isDeprecated: false,
isHidden: false,
description: '(Optional) Methods that performs actions on contracts',
section,
methods: {
call: createMethod(section, 'call', call)
}
};
+2 -1
View File
@@ -6,11 +6,12 @@ import { RpcMethodOpt, RpcMethod } from '../types';
import { isUndefined } from '@polkadot/util';
export default function createMethod (section: string, method: string, { description, isDeprecated = false, isHidden = false, isSigned = false, params, pubsub, type }: RpcMethodOpt): RpcMethod {
export default function createMethod (section: string, method: string, { description, isDeprecated = false, isHidden = false, isOptional = false, isSigned = false, params, pubsub, type }: RpcMethodOpt): RpcMethod {
return {
description,
isDeprecated,
isHidden,
isOptional,
isSigned,
isSubscription: !isUndefined(pubsub),
method,
+6
View File
@@ -4,14 +4,20 @@
import { RpcSection } from './types';
import account from './account';
import author from './author';
import chain from './chain';
import contracts from './contracts';
import rpc from './rpc';
import state from './state';
import system from './system';
const interfaces: Record<string, RpcSection> = {
account,
author,
chain,
contracts,
rpc,
state,
system
};
+30
View File
@@ -0,0 +1,30 @@
// Copyright 2017-2019 @polkadot/jsonrpc authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { RpcMethodOpt } from './types';
import createMethod from './create/method';
// NOTE order here is the same as in Rust, alphabetical below
const methods: RpcMethodOpt = {
description: 'Retrieves the list of RPC methods that are exposed by the node',
params: [],
type: 'RpcMethods'
};
const section = 'rpc';
/**
* @summary Calls to retrieve system info.
*/
export default {
isDeprecated: false,
isHidden: false,
description: 'Retrieves information about the RPC endpoints',
section,
methods: {
methods: createMethod(section, 'methods', methods)
}
};
+2
View File
@@ -16,6 +16,7 @@ export interface RpcMethodOpt {
description: string;
isDeprecated?: boolean;
isHidden?: boolean;
isOptional?: boolean;
isSigned?: boolean;
isSubscription?: boolean;
params: RpcParam[];
@@ -28,6 +29,7 @@ export interface RpcMethod {
description: string;
isDeprecated: boolean;
isHidden: boolean;
isOptional: boolean;
isSigned: boolean;
isSubscription: boolean;
method: string;