Mortal -> Extrinsic, expand for decoding start (#212)
* Mortal -> Extrinsic, expand for decoding start
* Method, Section -> Rpc{Method, Section}
* Only expose callIndex
* CallIndex -> MethodIndex in spec
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { ProviderInterface, ProviderInterface$Callback } from '@polkadot/api-provider/types';
|
||||
import { Section, Method } from '@polkadot/jsonrpc/types';
|
||||
import { RpcSection, RpcMethod } from '@polkadot/jsonrpc/types';
|
||||
import { ApiInterface, ApiInterface$Section, ApiInterface$Section$Method } from './types';
|
||||
|
||||
import { Base, Vector, createType } from '@polkadot/types/codec';
|
||||
@@ -62,7 +62,7 @@ export default class Api implements ApiInterface {
|
||||
* Api.signature({ name: 'test_method', params: [ { name: 'dest', type: 'Address' } ], type: 'Address' }); // => test_method (dest: Address): Address
|
||||
* </CODE></PRE>
|
||||
*/
|
||||
static signature ({ method, params, type }: Method): string {
|
||||
static signature ({ method, params, type }: RpcMethod): string {
|
||||
const inputs = params.map(({ name, type }) =>
|
||||
`${name}: ${type}`
|
||||
).join(', ');
|
||||
@@ -70,7 +70,7 @@ export default class Api implements ApiInterface {
|
||||
return `${method} (${inputs}): ${type}`;
|
||||
}
|
||||
|
||||
private createInterface ({ methods, section }: Section): ApiInterface$Section {
|
||||
private createInterface ({ methods, section }: RpcSection): ApiInterface$Section {
|
||||
return Object
|
||||
.keys(methods)
|
||||
.reduce((exposed, method) => {
|
||||
@@ -85,7 +85,7 @@ export default class Api implements ApiInterface {
|
||||
}, {} as ApiInterface$Section);
|
||||
}
|
||||
|
||||
private createMethodSend (rpcName: string, method: Method): ApiInterface$Section$Method {
|
||||
private createMethodSend (rpcName: string, method: RpcMethod): ApiInterface$Section$Method {
|
||||
const call = async (...values: Array<any>): Promise<any> => {
|
||||
// TODO Warn on deprecated methods
|
||||
try {
|
||||
@@ -106,7 +106,7 @@ export default class Api implements ApiInterface {
|
||||
return call as ApiInterface$Section$Method;
|
||||
}
|
||||
|
||||
private createMethodSubscribe (rpcName: string, method: Method): ApiInterface$Section$Method {
|
||||
private createMethodSubscribe (rpcName: string, method: RpcMethod): ApiInterface$Section$Method {
|
||||
const unsubscribe = (subscriptionId: any): Promise<any> =>
|
||||
this._provider.unsubscribe(rpcName, method.subscribe[1], subscriptionId);
|
||||
const _call = async (...values: Array<any>): Promise<any> => {
|
||||
@@ -138,7 +138,7 @@ export default class Api implements ApiInterface {
|
||||
return call;
|
||||
}
|
||||
|
||||
private formatInputs (method: Method, inputs: Array<any>): Array<Base> {
|
||||
private formatInputs (method: RpcMethod, inputs: Array<any>): Array<Base> {
|
||||
assert(method.params.length === inputs.length, `Expected ${method.params.length} parameters, ${inputs.length} found instead`);
|
||||
|
||||
return method.params.map(({ type }, index) =>
|
||||
@@ -146,7 +146,7 @@ export default class Api implements ApiInterface {
|
||||
);
|
||||
}
|
||||
|
||||
private formatOutput (method: Method, params: Array<Base>, result?: any): Base {
|
||||
private formatOutput (method: RpcMethod, params: Array<Base>, result?: any): Base {
|
||||
const base = createType(method.type as string).fromJSON(result);
|
||||
|
||||
if (method.type === 'StorageData') {
|
||||
|
||||
Reference in New Issue
Block a user