Add childstate_* RPCs (#2065)

* Add childstate_* RPCs

* childstate into rpc-core

* PrefixedStorageKey
This commit is contained in:
Jaco Greeff
2020-03-30 13:53:33 +02:00
committed by GitHub
parent d338fcb58c
commit 6aa0d90fc0
9 changed files with 131 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
**Breaking change** (TypeScript with derives only) The type names for `api.derive.*` returns has been adjusted to be consistent with `Derive*` (previously a mixture of `Derived*` and `Derive*`)
**Breaking change** (derives only) Additional cleanups of democracy proposeal & referenda derives, including support for new Polkadot/Substrate vote retrievals
- Tx signing via `signAndSend` & `signAsync` now tries to use the last finalized block (depending on finalized drift)
- Add support for `api.rpc.childstate.*` Substrate RPCs, older nodes with still populate `api.rpc.state.*` with the child methods
- Adjust `Error.message` on RPC failures to not include the (already known) method signature
- Internal adjustment of interface types to align with modules (no external impact via `@polkadot/types/interfaces`)
- Extended `api.derive.democracy` to cater for dispatchQueue and externals
+19
View File
@@ -8,6 +8,7 @@ import { Metadata } from '@polkadot/types';
import { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
import { EpochAuthorship } from '@polkadot/types/interfaces/babe';
import { BlockHash } from '@polkadot/types/interfaces/chain';
import { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
import { CreatedBlock } from '@polkadot/types/interfaces/engine';
@@ -98,6 +99,24 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
**/
subscribeNewHeads: AugmentedRpc<() => Observable<Header>>;
};
childstate: {
/**
* Returns the keys with prefix from a child storage, leave empty to get all the keys
**/
getKeys: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, prefix: StorageKey | string | Uint8Array | any, at?: Hash | string | Uint8Array) => Observable<Vec<StorageKey>>>;
/**
* Returns a child storage entry at a specific block state
**/
getStorage: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: Hash | string | Uint8Array) => Observable<Option<StorageData>>>;
/**
* Returns the hash of a child storage entry at a block state
**/
getStorageHash: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: Hash | string | Uint8Array) => Observable<Option<Hash>>>;
/**
* Returns the size of a child storage entry at a block state
**/
getStorageSize: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: Hash | string | Uint8Array) => Observable<Option<u64>>>;
};
contracts: {
/**
* Executes a call to a contract
+2
View File
@@ -83,6 +83,8 @@ export default class Rpc implements RpcInterface {
public readonly chain!: RpcInterface['chain'];
public readonly childstate!: RpcInterface['childstate'];
public readonly contracts!: RpcInterface['contracts'];
public readonly engine!: RpcInterface['engine'];
+4
View File
@@ -10,6 +10,7 @@ import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, EpochAuthorship, MaybeVrf, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondary, RawBabePreDigestSecondaryTo159, RawBabePreDigestTo159, SlotNumber, VrfData, VrfProof } from '@polkadot/types/interfaces/babe';
import { AccountData, BalanceLock, BalanceLockTo212, Reasons, ReleasesBalances, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances';
import { BlockHash } from '@polkadot/types/interfaces/chain';
import { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
import { EthereumAddress } from '@polkadot/types/interfaces/claims';
import { MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
import { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
@@ -1606,6 +1607,9 @@ declare module '@polkadot/types/types/registry' {
BlockHash: BlockHash;
'Option<BlockHash>': Option<BlockHash>;
'Vec<BlockHash>': Vec<BlockHash>;
PrefixedStorageKey: PrefixedStorageKey;
'Option<PrefixedStorageKey>': Option<PrefixedStorageKey>;
'Vec<PrefixedStorageKey>': Vec<PrefixedStorageKey>;
StorageKind: StorageKind;
'Option<StorageKind>': Option<StorageKind>;
'Vec<StorageKind>': Vec<StorageKind>;
@@ -0,0 +1,90 @@
// 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: {
getKeys: {
description: 'Returns the keys with prefix from a child storage, leave empty to get all the keys',
params: [
{
name: 'childKey',
type: 'PrefixedStorageKey'
},
{
name: 'prefix',
type: 'StorageKey'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Vec<StorageKey>'
},
getStorage: {
description: 'Returns a child storage entry at a specific block state',
params: [
{
name: 'childKey',
type: 'PrefixedStorageKey'
},
{
name: 'key',
type: 'StorageKey'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Option<StorageData>'
},
getStorageHash: {
description: 'Returns the hash of a child storage entry at a block state',
params: [
{
name: 'childKey',
type: 'PrefixedStorageKey'
},
{
name: 'key',
type: 'StorageKey'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Option<Hash>'
},
getStorageSize: {
description: 'Returns the size of a child storage entry at a block state',
params: [
{
name: 'childKey',
type: 'PrefixedStorageKey'
},
{
name: 'key',
type: 'StorageKey'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Option<u64>'
}
},
types: {
// StorageKey extends Bytes
PrefixedStorageKey: 'StorageKey'
}
} 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,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { StorageKey } from '@polkadot/types/primitive';
/** @name PrefixedStorageKey */
export interface PrefixedStorageKey extends StorageKey {}
export type PHANTOM_CHILDSTATE = 'childstate';
@@ -46,6 +46,7 @@ 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 childstate } from './childstate/definitions';
export { default as offchain } from './offchain/definitions';
export { default as payment } from './payment/definitions';
export { default as state } from './state/definitions';
+1
View File
@@ -36,6 +36,7 @@ export * from './rpc/types';
export * from './account/types';
export * from './author/types';
export * from './chain/types';
export * from './childstate/types';
export * from './offchain/types';
export * from './payment/types';
export * from './state/types';