From 6aa0d90fc0568938b3ba0df444830ad273823c5d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 30 Mar 2020 13:53:33 +0200 Subject: [PATCH] Add childstate_* RPCs (#2065) * Add childstate_* RPCs * childstate into rpc-core * PrefixedStorageKey --- CHANGELOG.md | 1 + packages/api/src/augment/rpc.ts | 19 ++++ packages/rpc-core/src/index.ts | 2 + packages/types/src/augment/registry.ts | 4 + .../src/interfaces/childstate/definitions.ts | 90 +++++++++++++++++++ .../types/src/interfaces/childstate/index.ts | 4 + .../types/src/interfaces/childstate/types.ts | 9 ++ packages/types/src/interfaces/definitions.ts | 1 + packages/types/src/interfaces/types.ts | 1 + 9 files changed, 131 insertions(+) create mode 100644 packages/types/src/interfaces/childstate/definitions.ts create mode 100644 packages/types/src/interfaces/childstate/index.ts create mode 100644 packages/types/src/interfaces/childstate/types.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ba815fd9..4c15864178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index 5126b3935d..e08a1e0fef 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -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
>; }; + 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>>; + /** + * 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>>; + /** + * 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>>; + /** + * 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>>; + }; contracts: { /** * Executes a call to a contract diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index c8fd62366b..645a8feb4a 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -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']; diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 937ca8acde..55245e005d 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -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': Option; 'Vec': Vec; + PrefixedStorageKey: PrefixedStorageKey; + 'Option': Option; + 'Vec': Vec; StorageKind: StorageKind; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/childstate/definitions.ts b/packages/types/src/interfaces/childstate/definitions.ts new file mode 100644 index 0000000000..23cf3fe4ee --- /dev/null +++ b/packages/types/src/interfaces/childstate/definitions.ts @@ -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' + }, + 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' + }, + 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' + }, + 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' + } + }, + types: { + // StorageKey extends Bytes + PrefixedStorageKey: 'StorageKey' + } +} as Definitions; diff --git a/packages/types/src/interfaces/childstate/index.ts b/packages/types/src/interfaces/childstate/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/childstate/index.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export * from './types'; diff --git a/packages/types/src/interfaces/childstate/types.ts b/packages/types/src/interfaces/childstate/types.ts new file mode 100644 index 0000000000..db7af42afc --- /dev/null +++ b/packages/types/src/interfaces/childstate/types.ts @@ -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'; diff --git a/packages/types/src/interfaces/definitions.ts b/packages/types/src/interfaces/definitions.ts index 5c228e451c..2e3773bad9 100644 --- a/packages/types/src/interfaces/definitions.ts +++ b/packages/types/src/interfaces/definitions.ts @@ -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'; diff --git a/packages/types/src/interfaces/types.ts b/packages/types/src/interfaces/types.ts index 9380dd576a..ce5ad0befc 100644 --- a/packages/types/src/interfaces/types.ts +++ b/packages/types/src/interfaces/types.ts @@ -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';