Add all missing RPC endpoints (#2070)

* Add all missing RPC endpoints

* Rework RPC return types

* rpc-core interface

* Remove crap test, checked anyway
This commit is contained in:
Jaco Greeff
2020-03-20 13:42:18 +01:00
committed by GitHub
parent 53d18d874d
commit 3a1634d67f
12 changed files with 163 additions and 14 deletions
+30 -2
View File
@@ -3,13 +3,15 @@
import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types';
import { Option, Vec } from '@polkadot/types/codec';
import { Bytes, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primitive';
import { Bytes, Null, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primitive';
import { Metadata } from '@polkadot/types';
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
import { CreatedBlock } from '@polkadot/types/interfaces/engine';
import { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
import { StorageKind } from '@polkadot/types/interfaces/offchain';
import { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion } from '@polkadot/types/interfaces/rpc';
import { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
import { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, KeyValue, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
import { NodeRole } from '@polkadot/types/interfaces/system';
import { Observable } from 'rxjs';
declare module '@polkadot/rpc-core/types.jsonrpc' {
@@ -104,6 +106,16 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
**/
finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification | string | Uint8Array) => Observable<bool>>;
};
offchain: {
/**
* Get offchain local storage under given key and prefix
**/
localStorageGet: AugmentedRpc<(kind: StorageKind | ('__UNUSED' | 'PERSISTENT' | 'LOCAL') | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable<Option<Bytes>>>;
/**
* Set offchain local storage under given key and prefix
**/
localStorageSet: AugmentedRpc<(kind: StorageKind | ('__UNUSED' | 'PERSISTENT' | 'LOCAL') | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable<Null>>;
};
payment: {
/**
* Retrieves the fee information for an encoded extrinsic
@@ -149,6 +161,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
* Returns the runtime metadata
**/
getMetadata: AugmentedRpc<(at?: BlockHash | string | Uint8Array) => Observable<Metadata>>;
/**
* Returns the keys with prefix, leave empty to get all the keys
**/
getPairs: AugmentedRpc<(prefix: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Vec<KeyValue>>>;
/**
* Get the runtime version
**/
@@ -179,6 +195,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[]) => Observable<T>>;
};
system: {
/**
* Adds a reserved peer
**/
addReservedPeer: AugmentedRpc<(peer: Text | string) => Observable<Text>>;
/**
* Retrieves the chain
**/
@@ -195,6 +215,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
* Returns current state of the network
**/
networkState: AugmentedRpc<() => Observable<NetworkState>>;
/**
* Returns the roles the node is running as
**/
nodeRoles: AugmentedRpc<() => Observable<Vec<NodeRole>>>;
/**
* Returns the currently connected peers
**/
@@ -203,6 +227,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
* Get a custom set of properties as a JSON object, defined in the chain spec
**/
properties: AugmentedRpc<() => Observable<ChainProperties>>;
/**
* Remove a reserved peer
**/
removeReservedPeer: AugmentedRpc<(peerId: Text | string) => Observable<Text>>;
/**
* Retrieves the version of the node
**/
-11
View File
@@ -17,17 +17,6 @@ describe('Api', (): void => {
).toThrow(/Expected Provider/);
});
it('creates an instance with all sections', (): void => {
const rpc = new Rpc(registry, new MockProvider(registry));
expect(
Object.keys(rpc).filter((key): boolean => !key.startsWith('_'))
).toEqual([
'mapping', 'provider', 'registry', 'sections',
'account', 'author', 'chain', 'contracts', 'engine', 'payment', 'rpc', 'state', 'system'
]);
});
it('allows for the definition of user RPCs', (): void => {
const rpc = new Rpc(registry, new MockProvider(registry), {
testing: {
+2
View File
@@ -85,6 +85,8 @@ export default class Rpc implements RpcInterface {
public readonly engine!: RpcInterface['engine'];
public readonly offchain!: RpcInterface['offchain'];
public readonly payment!: RpcInterface['payment'];
public readonly rpc!: RpcInterface['rpc'];
+8 -1
View File
@@ -22,6 +22,7 @@ import { AuthorityIndex, AuthorityList, AuthorityWeight, NextAuthority, PendingP
import { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement } from '@polkadot/types/interfaces/identity';
import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV11, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV11, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV11, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV11, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV11, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import { StorageKind } from '@polkadot/types/interfaces/offchain';
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
import { AttestedCandidate, AuctionIndex, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
@@ -30,7 +31,7 @@ import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, Balanc
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, ReleasesStaking, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { AccountInfo, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, LastRuntimeUpgradeInfo, Phase, RefCount } from '@polkadot/types/interfaces/system';
import { AccountInfo, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, LastRuntimeUpgradeInfo, NodeRole, Phase, RefCount } from '@polkadot/types/interfaces/system';
import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
@@ -853,6 +854,9 @@ declare module '@polkadot/types/types/registry' {
LastRuntimeUpgradeInfo: LastRuntimeUpgradeInfo;
'Option<LastRuntimeUpgradeInfo>': Option<LastRuntimeUpgradeInfo>;
'Vec<LastRuntimeUpgradeInfo>': Vec<LastRuntimeUpgradeInfo>;
NodeRole: NodeRole;
'Option<NodeRole>': Option<NodeRole>;
'Vec<NodeRole>': Vec<NodeRole>;
Phase: Phase;
'Option<Phase>': Option<Phase>;
'Vec<Phase>': Vec<Phase>;
@@ -1565,5 +1569,8 @@ declare module '@polkadot/types/types/registry' {
StorageChangeSet: StorageChangeSet;
'Option<StorageChangeSet>': Option<StorageChangeSet>;
'Vec<StorageChangeSet>': Vec<StorageChangeSet>;
StorageKind: StorageKind;
'Option<StorageKind>': Option<StorageKind>;
'Vec<StorageKind>': Vec<StorageKind>;
}
}
@@ -46,5 +46,6 @@ export { default as rpc } from './rpc/definitions';
export { default as account } from './account/definitions';
export { default as author } from './author/definitions';
export { default as chain } from './chain/definitions';
export { default as offchain } from './offchain/definitions';
export { default as payment } from './payment/definitions';
export { default as state } from './state/definitions';
@@ -0,0 +1,47 @@
// Copyright 2017-2020 @polkadot/types 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 { Definitions } from '../../types';
export default {
rpc: {
localStorageSet: {
description: 'Set offchain local storage under given key and prefix',
params: [
{
name: 'kind',
type: 'StorageKind'
},
{
name: 'key',
type: 'Bytes'
},
{
name: 'value',
type: 'Bytes'
}
],
type: 'Null'
},
localStorageGet: {
description: 'Get offchain local storage under given key and prefix',
params: [
{
name: 'kind',
type: 'StorageKind'
},
{
name: 'key',
type: 'Bytes'
}
],
type: 'Option<Bytes>'
}
},
types: {
StorageKind: {
_enum: ['__UNUSED', 'PERSISTENT', 'LOCAL']
}
}
} as Definitions;
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
export * from './types';
@@ -0,0 +1,13 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { Enum } from '@polkadot/types/codec';
/** @name StorageKind */
export interface StorageKind extends Enum {
readonly isUnused: boolean;
readonly isPersistent: boolean;
readonly isLocal: boolean;
}
export type PHANTOM_OFFCHAIN = 'offchain';
@@ -41,6 +41,21 @@ export default {
],
type: 'Vec<StorageKey>'
},
getPairs: {
description: 'Returns the keys with prefix, leave empty to get all the keys',
params: [
{
name: 'prefix',
type: 'StorageKey'
},
{
name: 'at',
type: 'BlockHash',
isOptional: true
}
],
type: 'Vec<KeyValue>'
},
getKeysPaged: {
alias: ['state_getKeysPagedAt'],
description: 'Returns the keys with prefix with pagination support.',
@@ -40,6 +40,31 @@ export default {
description: 'Returns current state of the network',
params: [],
type: 'NetworkState'
},
addReservedPeer: {
description: 'Adds a reserved peer',
params: [
{
name: 'peer',
type: 'Text'
}
],
type: 'Text'
},
removeReservedPeer: {
description: 'Remove a reserved peer',
params: [
{
name: 'peerId',
type: 'Text'
}
],
type: 'Text'
},
nodeRoles: {
description: 'Returns the roles the node is running as',
params: [],
type: 'Vec<NodeRole>'
}
},
types: {
@@ -85,6 +110,14 @@ export default {
specVersion: 'Compact<u32>',
specName: 'Text'
},
NodeRole: {
_enum: {
Full: 'Null',
LightClient: 'Null',
Authority: 'Null',
UnknownRole: 'u8'
}
},
Phase: {
_enum: {
ApplyExtrinsic: 'u32',
@@ -89,6 +89,15 @@ export interface LastRuntimeUpgradeInfo extends Struct {
readonly specName: Text;
}
/** @name NodeRole */
export interface NodeRole extends Enum {
readonly isFull: boolean;
readonly isLightClient: boolean;
readonly isAuthority: boolean;
readonly isUnknownRole: boolean;
readonly asUnknownRole: u8;
}
/** @name Phase */
export interface Phase extends Enum {
readonly isApplyExtrinsic: boolean;
+1
View File
@@ -36,5 +36,6 @@ export * from './rpc/types';
export * from './account/types';
export * from './author/types';
export * from './chain/types';
export * from './offchain/types';
export * from './payment/types';
export * from './state/types';