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:
@@ -20,7 +20,7 @@ describe('Api', (): void => {
|
||||
Object.keys(rpc).filter((key): boolean => !key.startsWith('_'))
|
||||
).toEqual([
|
||||
'provider',
|
||||
'author', 'chain', 'state', 'system'
|
||||
'account', 'author', 'chain', 'contracts', 'rpc', 'state', 'system'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,10 +56,16 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
public readonly provider: ProviderInterface;
|
||||
|
||||
public readonly account: RpcInterface['account'];
|
||||
|
||||
public readonly author: RpcInterface['author'];
|
||||
|
||||
public readonly chain: RpcInterface['chain'];
|
||||
|
||||
public readonly contracts: RpcInterface['contracts'];
|
||||
|
||||
public readonly rpc: RpcInterface['rpc'];
|
||||
|
||||
public readonly state: RpcInterface['state'];
|
||||
|
||||
public readonly system: RpcInterface['system'];
|
||||
@@ -75,8 +81,11 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
this.provider = provider;
|
||||
|
||||
this.account = this.createInterface('account');
|
||||
this.author = this.createInterface('author');
|
||||
this.contracts = this.createInterface('contracts');
|
||||
this.chain = this.createInterface('chain');
|
||||
this.rpc = this.createInterface('rpc');
|
||||
this.state = this.createInterface('state');
|
||||
this.system = this.createInterface('system');
|
||||
}
|
||||
@@ -161,7 +170,10 @@ export default class Rpc implements RpcInterface {
|
||||
catchError((error): any => {
|
||||
const message = this.createErrorMessage(method, error);
|
||||
|
||||
l.error(message);
|
||||
// don't scare with old nodes, this is handled transparently
|
||||
if (rpcName !== 'rpc_methods') {
|
||||
l.error(message);
|
||||
}
|
||||
|
||||
return throwError(new Error(message));
|
||||
}),
|
||||
|
||||
@@ -4,11 +4,15 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, Metadata, StorageData, StorageKey, Text, u64 } from '@polkadot/types';
|
||||
import { BlockNumber, Extrinsic, Hash, Header, SignedBlock } from '@polkadot/types/interfaces/runtime';
|
||||
import { ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, BlockNumber, Extrinsic, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces/runtime';
|
||||
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
|
||||
import { ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { Codec, IExtrinsic } from '@polkadot/types/types';
|
||||
|
||||
export interface RpcInterface {
|
||||
account: {
|
||||
nextIndex(accountId: AccountId | Uint8Array | string): Observable<Index>;
|
||||
};
|
||||
author: {
|
||||
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | Uint8Array | string): Observable<Bytes>;
|
||||
pendingExtrinsics(): Observable<Vec<Extrinsic>>;
|
||||
@@ -25,6 +29,12 @@ export interface RpcInterface {
|
||||
subscribeFinalizedHeads(): Observable<Header>;
|
||||
subscribeNewHeads(): Observable<Header>;
|
||||
};
|
||||
contracts: {
|
||||
call(callRequest: ContractCallRequest, at?: Hash | Uint8Array | string): Observable<ContractExecResult>;
|
||||
};
|
||||
rpc: {
|
||||
methods(): Observable<RpcMethods>;
|
||||
};
|
||||
state: {
|
||||
call(method: Text | string, data: Bytes | Uint8Array | string, block?: Hash | Uint8Array | string): Observable<Bytes>;
|
||||
getChildKeys(childStorageKey: any, key: any, block?: Hash | Uint8Array | string): Observable<Vec<StorageKey>>;
|
||||
|
||||
Reference in New Issue
Block a user