From 044efbc6de4980dbabb5461c9d802c9c91634280 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 19 Mar 2020 14:40:54 +0100 Subject: [PATCH] Convert jsonrpc & typings to definitions (#2064) * Convert jsonrpc & typings to definitions * Handle empty interface generation (no types) * Move jsonrpc/create to rpc-core/create * Create imports * Remove jsonrpc package, generate rpc-core from defs * Debug :) * Generate RPC definitions via interfaces * Generate md docs * Remove @polkadot/jsonrpc refs (at least packages) * No empty types * Add PAHNTOM "cleanup" gen * *sigh* regex loop * Update mock for no jsonrpc * Add definition export types * Cleanup linting * Mocking 1 fix * Mocking 2 fix * rpc-core tests updates * CHANGELOG & docs * Add jsonrpc (already mapped) to interfaces * Add aliasses for RPCs * Fix rpc-core tests --- CHANGELOG.md | 6 + copy-to-apps.sh | 1 - docs/.vuepress/config.js | 1 + docs/start/.TODOS.md | 5 - docs/start/rpc.custom.md | 51 +++ docs/start/types.extend.md | 4 +- jest.config.js | 12 - packages/api/src/augment/consts.ts | 2 +- packages/api/src/augment/query.ts | 2 +- packages/api/src/augment/rpc.ts | 15 +- packages/api/src/augment/tx.ts | 2 +- packages/api/src/base/Decorate.ts | 40 ++- packages/api/src/types/index.ts | 6 +- packages/jsonrpc/LICENSE | 201 ------------ packages/jsonrpc/README.md | 24 -- packages/jsonrpc/package.json | 33 -- packages/jsonrpc/src/account.ts | 34 -- packages/jsonrpc/src/author.ts | 100 ------ packages/jsonrpc/src/chain.ts | 95 ------ packages/jsonrpc/src/contracts.ts | 47 --- packages/jsonrpc/src/create/method.ts | 24 -- packages/jsonrpc/src/create/param.ts | 19 -- packages/jsonrpc/src/engine.ts | 43 --- packages/jsonrpc/src/index.spec.ts | 12 - packages/jsonrpc/src/index.ts | 27 -- packages/jsonrpc/src/payment.ts | 35 --- packages/jsonrpc/src/rpc.ts | 30 -- packages/jsonrpc/src/state.ts | 172 ---------- packages/jsonrpc/src/system.ts | 72 ----- packages/jsonrpc/src/types.ts | 48 --- .../storage/fromMetadata/getHasher.ts | 4 +- packages/rpc-core/package.json | 1 - packages/rpc-core/src/index.spec.ts | 19 +- packages/rpc-core/src/index.ts | 116 +++---- packages/rpc-core/src/methodSend.spec.ts | 16 +- packages/rpc-core/src/types.ts | 9 - packages/rpc-provider/package.json | 1 - packages/rpc-provider/src/mock/index.ts | 14 +- packages/typegen/package.json | 1 - .../scripts/polkadot-types-chain-info.js | 1 - .../polkadot-types-internal-interfaces.js | 1 - .../polkadot-types-internal-metadata.js | 1 - packages/typegen/src/generate/rpc.ts | 29 +- packages/typegen/src/generate/tsDef.ts | 7 +- packages/typegen/src/metadataMd.ts | 18 +- packages/typegen/src/util/derived.ts | 5 +- packages/typegen/src/util/file.ts | 14 +- packages/typegen/src/util/formatting.ts | 2 +- packages/types/src/augment/registry.ts | 2 +- packages/types/src/generic/Vote.ts | 6 +- .../src/interfaces/account/definitions.ts | 22 ++ .../types/src/interfaces/account/index.ts | 4 + .../types/src/interfaces/account/types.ts | 4 + .../interfaces/attestations/definitions.ts | 5 +- .../src/interfaces/attestations/index.ts | 2 +- .../src/interfaces/attestations/types.ts | 4 +- .../types/src/interfaces/aura/definitions.ts | 5 +- packages/types/src/interfaces/aura/index.ts | 2 +- packages/types/src/interfaces/aura/types.ts | 4 +- .../src/interfaces/author/definitions.ts | 100 ++++++ packages/types/src/interfaces/author/index.ts | 4 + packages/types/src/interfaces/author/types.ts | 4 + .../src/interfaces/authorship/definitions.ts | 5 +- .../types/src/interfaces/authorship/index.ts | 2 +- .../types/src/interfaces/authorship/types.ts | 4 +- .../types/src/interfaces/babe/definitions.ts | 5 +- packages/types/src/interfaces/babe/index.ts | 2 +- packages/types/src/interfaces/babe/types.ts | 4 +- .../src/interfaces/balances/definitions.ts | 5 +- .../types/src/interfaces/balances/index.ts | 2 +- .../types/src/interfaces/balances/types.ts | 4 +- .../types/src/interfaces/chain/definitions.ts | 84 +++++ packages/types/src/interfaces/chain/index.ts | 4 + packages/types/src/interfaces/chain/types.ts | 4 + .../src/interfaces/claims/definitions.ts | 5 +- packages/types/src/interfaces/claims/index.ts | 2 +- packages/types/src/interfaces/claims/types.ts | 4 +- .../src/interfaces/collective/definitions.ts | 5 +- .../types/src/interfaces/collective/index.ts | 2 +- .../types/src/interfaces/collective/types.ts | 4 +- .../src/interfaces/consensus/definitions.ts | 5 +- .../types/src/interfaces/consensus/index.ts | 2 +- .../types/src/interfaces/consensus/types.ts | 4 +- .../src/interfaces/contracts/definitions.ts | 40 ++- .../types/src/interfaces/contracts/index.ts | 2 +- .../types/src/interfaces/contracts/types.ts | 4 +- packages/types/src/interfaces/definitions.ts | 7 + .../src/interfaces/democracy/definitions.ts | 41 ++- .../types/src/interfaces/democracy/index.ts | 2 +- .../types/src/interfaces/democracy/types.ts | 4 +- .../src/interfaces/elections/definitions.ts | 5 +- .../types/src/interfaces/elections/index.ts | 2 +- .../types/src/interfaces/elections/types.ts | 4 +- .../src/interfaces/engine/definitions.ts | 40 ++- packages/types/src/interfaces/engine/index.ts | 2 +- packages/types/src/interfaces/engine/types.ts | 4 +- .../types/src/interfaces/evm/definitions.ts | 5 +- packages/types/src/interfaces/evm/index.ts | 2 +- packages/types/src/interfaces/evm/types.ts | 4 +- .../src/interfaces/extrinsics/definitions.ts | 5 +- .../types/src/interfaces/extrinsics/index.ts | 2 +- .../types/src/interfaces/extrinsics/types.ts | 4 +- .../interfaces/genericAsset/definitions.ts | 5 +- .../src/interfaces/genericAsset/index.ts | 2 +- .../src/interfaces/genericAsset/types.ts | 4 +- .../src/interfaces/grandpa/definitions.ts | 5 +- .../types/src/interfaces/grandpa/index.ts | 2 +- .../types/src/interfaces/grandpa/types.ts | 4 +- .../src/interfaces/identity/definitions.ts | 5 +- .../types/src/interfaces/identity/index.ts | 2 +- .../types/src/interfaces/identity/types.ts | 4 +- .../src/interfaces/imOnline/definitions.ts | 5 +- .../types/src/interfaces/imOnline/index.ts | 2 +- .../types/src/interfaces/imOnline/types.ts | 4 +- packages/types/src/interfaces/index.ts | 2 +- packages/types/src/interfaces/jsonrpc.ts | 26 ++ .../src/interfaces/metadata/definitions.ts | 29 +- .../types/src/interfaces/metadata/index.ts | 2 +- .../types/src/interfaces/metadata/types.ts | 4 +- .../src/interfaces/offences/definitions.ts | 5 +- .../types/src/interfaces/offences/index.ts | 2 +- .../types/src/interfaces/offences/types.ts | 4 +- .../src/interfaces/parachains/definitions.ts | 5 +- .../types/src/interfaces/parachains/index.ts | 2 +- .../types/src/interfaces/parachains/types.ts | 4 +- .../src/interfaces/payment/definitions.ts | 26 ++ .../types/src/interfaces/payment/index.ts | 4 + .../types/src/interfaces/payment/types.ts | 4 + .../src/interfaces/recovery/definitions.ts | 5 +- .../types/src/interfaces/recovery/index.ts | 2 +- .../types/src/interfaces/recovery/types.ts | 4 +- .../types/src/interfaces/rpc/definitions.ts | 11 +- packages/types/src/interfaces/rpc/index.ts | 2 +- packages/types/src/interfaces/rpc/types.ts | 4 +- .../src/interfaces/runtime/definitions.ts | 5 +- .../types/src/interfaces/runtime/index.ts | 2 +- .../types/src/interfaces/runtime/types.ts | 4 +- .../src/interfaces/session/definitions.ts | 5 +- .../types/src/interfaces/session/index.ts | 2 +- .../types/src/interfaces/session/types.ts | 4 +- .../src/interfaces/society/definitions.ts | 5 +- .../types/src/interfaces/society/index.ts | 2 +- .../types/src/interfaces/society/types.ts | 4 +- .../src/interfaces/staking/definitions.ts | 5 +- .../types/src/interfaces/staking/index.ts | 2 +- .../types/src/interfaces/staking/types.ts | 4 +- .../types/src/interfaces/state/definitions.ts | 295 ++++++++++++++++++ packages/types/src/interfaces/state/index.ts | 4 + packages/types/src/interfaces/state/types.ts | 4 + .../src/interfaces/system/definitions.ts | 41 ++- packages/types/src/interfaces/system/index.ts | 2 +- packages/types/src/interfaces/system/types.ts | 4 +- .../src/interfaces/treasury/definitions.ts | 5 +- .../types/src/interfaces/treasury/index.ts | 2 +- .../types/src/interfaces/treasury/types.ts | 4 +- .../src/interfaces/txpayment/definitions.ts | 5 +- .../types/src/interfaces/txpayment/index.ts | 2 +- .../types/src/interfaces/txpayment/types.ts | 4 +- packages/types/src/interfaces/types.ts | 7 +- .../src/interfaces/utility/definitions.ts | 5 +- .../types/src/interfaces/utility/index.ts | 2 +- .../types/src/interfaces/utility/types.ts | 4 +- .../src/interfaces/vesting/definitions.ts | 5 +- .../types/src/interfaces/vesting/index.ts | 2 +- .../types/src/interfaces/vesting/types.ts | 4 +- packages/types/src/primitive/StorageKey.ts | 4 +- packages/types/src/types/definitions.ts | 44 +++ packages/types/src/types/index.ts | 1 + tsconfig.json | 2 - yarn.lock | 13 - 170 files changed, 1281 insertions(+), 1346 deletions(-) delete mode 100644 docs/start/.TODOS.md create mode 100644 docs/start/rpc.custom.md delete mode 100644 packages/jsonrpc/LICENSE delete mode 100644 packages/jsonrpc/README.md delete mode 100644 packages/jsonrpc/package.json delete mode 100644 packages/jsonrpc/src/account.ts delete mode 100644 packages/jsonrpc/src/author.ts delete mode 100644 packages/jsonrpc/src/chain.ts delete mode 100644 packages/jsonrpc/src/contracts.ts delete mode 100644 packages/jsonrpc/src/create/method.ts delete mode 100644 packages/jsonrpc/src/create/param.ts delete mode 100644 packages/jsonrpc/src/engine.ts delete mode 100644 packages/jsonrpc/src/index.spec.ts delete mode 100644 packages/jsonrpc/src/index.ts delete mode 100644 packages/jsonrpc/src/payment.ts delete mode 100644 packages/jsonrpc/src/rpc.ts delete mode 100644 packages/jsonrpc/src/state.ts delete mode 100644 packages/jsonrpc/src/system.ts delete mode 100644 packages/jsonrpc/src/types.ts create mode 100644 packages/types/src/interfaces/account/definitions.ts create mode 100644 packages/types/src/interfaces/account/index.ts create mode 100644 packages/types/src/interfaces/account/types.ts create mode 100644 packages/types/src/interfaces/author/definitions.ts create mode 100644 packages/types/src/interfaces/author/index.ts create mode 100644 packages/types/src/interfaces/author/types.ts create mode 100644 packages/types/src/interfaces/chain/definitions.ts create mode 100644 packages/types/src/interfaces/chain/index.ts create mode 100644 packages/types/src/interfaces/chain/types.ts create mode 100644 packages/types/src/interfaces/jsonrpc.ts create mode 100644 packages/types/src/interfaces/payment/definitions.ts create mode 100644 packages/types/src/interfaces/payment/index.ts create mode 100644 packages/types/src/interfaces/payment/types.ts create mode 100644 packages/types/src/interfaces/state/definitions.ts create mode 100644 packages/types/src/interfaces/state/index.ts create mode 100644 packages/types/src/interfaces/state/types.ts create mode 100644 packages/types/src/types/definitions.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9b56fb8c..10c3af6031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.8.0-beta.x + +- **Breaking change** The format for any custom RPCs have been changed, alongside API-internal changes to allow for better RPC management. If you are currently using custom RPCs (or planning to do so), look at the [updated documentation](https://polkadot.js.org/api/start/rpc.custom.html) +- **Breaking change** Alongside API RPC changes, the `@polkadot/jsonrpc` package has been removed. Since it was never documented and only used internally, this should not have adverse impacts. All RPC definitions itself has now been moved to the relevant modules inside `@polkadot/types/interfaces` +- The Substrate extrinsic phase definitions has been expanded with `Initialization` to align with the latest versions + # 1.7.1 Mar 17, 2020 - **Important** Current versions of Polkadot/Substrate have dropped support for linked maps on storage entries. If you are using these queries to retrieve all entries, for instance `staking.{nominators,validators}()` and using an upgraded chain, you need to swap to retrieving entries via `.entries()` or `.keys()` for the keys. diff --git a/copy-to-apps.sh b/copy-to-apps.sh index b52ecc8683..958d9016be 100755 --- a/copy-to-apps.sh +++ b/copy-to-apps.sh @@ -18,6 +18,5 @@ copy_folder "api-derive" copy_folder "metadata" copy_folder "rpc-core" copy_folder "rpc-provider" -copy_folder "jsonrpc" copy_folder "types" copy_folder "typegen" diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 0a56612eea..c80fef3fee 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -43,6 +43,7 @@ module.exports = { ['start/api.tx.wrap.md', 'Complex transactions'], ['start/types.basics.md', 'Type basics'], ['start/types.extend.md', 'Extending types'], + ['start/rpc.custom.md', 'Custom RPC'], ['start/types.create.md', 'Creating types'], ['start/typescript.md', 'TypeScript interfaces'], ['start/typescript.user.md', 'TypeScript user generated'], diff --git a/docs/start/.TODOS.md b/docs/start/.TODOS.md deleted file mode 100644 index 506780031b..0000000000 --- a/docs/start/.TODOS.md +++ /dev/null @@ -1,5 +0,0 @@ -... somewhere also need a signer injection section, something along the lines of the singlesigner or this https://github.com/polkadot-js/tools/blob/master/packages/signer-cli/src/cmdSubmit.ts#L12 - -... DoubleMap & LinkedMap examples - -... api.derive diff --git a/docs/start/rpc.custom.md b/docs/start/rpc.custom.md new file mode 100644 index 0000000000..69d1d53b13 --- /dev/null +++ b/docs/start/rpc.custom.md @@ -0,0 +1,51 @@ +# Custom RPC + +In previous sections we looked at the injection of types, as in use and defined in modules from the node. Another area that can be customized is RC definitions, and like with the types, the API provides the capability to add user-defined RPCs (in addition to the Polkadot/Substrate base) to allow use of these RPCs via the API. + +## Custom definitions + +RPCs are exposed as a method on a specific module, this means that once available you can call any rpc via the `api.rpc..(...params[])` endpoints. To extend with user-defined RPCs, the injection can happen at the time of API creation with the addition of the `rpc` key (in addition to any other params, such as `types` or `provider`) - + +```js +... +const api = await ApiPromise.create({ + rpc: { + firstModule: { + testMethod: { + description: 'Just a test method', + params: [ + { + name: 'index', + type: 'u64' + } + ], + type: 'Balance' + } + } + } +}); +``` + +In the above example we have defined a new method, which is now available on the RPCs as `api.rpc.firstModule.testMethod(u64) => Promise`. Do be aware that while defined, the method will only appear if it is in the list as returned by `api.rpc.rpc.methods()`, which is the list of known RPCs the node exposes. When making changes to the node, always ensure that it does expose the RPC method correctly, otherwise it will not be decorated. + +## Definition breakdown + +While the above example should be self-explanatory, it is important to understand teh structure. The `rpc: { ... }` definitions are keyed first and foremost by the name of the module exposing the RPC. This means that when we have 2 modules `firstModule` & `testModule`, the first-level structure would follow the following pattern, + +```js +... +const api = await ApiPromise.create({ + rpc: { + firstModule: { ... }, + testModule: { ... } + } +}); +``` + +Inside the specific module definitions, the key is the actual expose RPC method. As we have seen in the first example, we expose a `testMethod` on `firstModule`. For the method definitions, apart from the description, we have definitions for the params and return a single result `type`. + +Params itself, as an array, contains fields for `name`, `type` and an optional flag `isOptional` that indicates that the field is not required when making the call. (And example of this use would be in cases such as `state.getStorage(key, blockHash?)` where the last param is optional) + +## Type creation + +While the API always converts all the inputs into the underlying type required by the operation, be it for RPC, query or transaction, in some cases you may want to [create an instance of a type](types.create.md) yourself. diff --git a/docs/start/types.extend.md b/docs/start/types.extend.md index 5e23f64be7..a1bed3afe1 100644 --- a/docs/start/types.extend.md +++ b/docs/start/types.extend.md @@ -201,6 +201,6 @@ const api = await ApiPromise.create({ Always look at customization and understand the impacts, replicating these changes between the node and the API. For the above the `Address` type is used in the construction of the `UncheckedExtrinsic` type, while the lookup type is applicable on transactions such as `balances.transfer(to: LookupSource, value: Balance)` -## Type creation +## Custom RPC -While the API always converts all the inputs into the underlying type required by the operation, in some cases you may want to [create an instance of a type](types.create.md) yourself. +In addition to customizing modules and types on your node, you can also add custom RPC definitions. Like the type definitions in ths section, [these can be defined and passed to the API](rpc.custom.md) for decoration. diff --git a/jest.config.js b/jest.config.js index b34c487178..77e927ff72 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,6 @@ module.exports = Object.assign({}, config, { '@polkadot/api-contract(.*)$': '/packages/api-contract/src/$1', '@polkadot/api-derive(.*)$': '/packages/api-derive/src/$1', '@polkadot/api(.*)$': '/packages/api/src/$1', - '@polkadot/jsonrpc(.*)$': '/packages/jsonrpc/src/$1', '@polkadot/metadata(.*)$': '/packages/metadata/src/$1', '@polkadot/rpc-(core|provider)(.*)$': '/packages/rpc-$1/src/$2', '@polkadot/types(.*)$': '/packages/types/src/$1' @@ -16,21 +15,10 @@ module.exports = Object.assign({}, config, { '/packages/api/build', '/packages/api-derive/build', '/packages/api-contract/build', - '/packages/jsonrpc/build', '/packages/metadata/build', '/packages/rpc-core/build', '/packages/rpc-provider/build', '/packages/types/build' ], - globals: { - ws_local: 'ws://127.0.0.1:9944/', - ws_local_substrate_master: 'ws://127.0.0.1:9945/', - ws_local_substrate_1: 'ws://127.0.0.1:9946/', - ws_local_substrate_2: 'ws://127.0.0.1:9947/', - ws_local_polkadot_master: 'ws://127.0.0.1:9948/', - ws_local_polkadot_alex: 'ws://127.0.0.1:9949/', - ws_substrate_1: 'wss://substrate-rpc.parity.io/', - ws_polkadot_alex: 'wss://poc3-rpc.polkadot.io/' - }, resolver: './jest.resolver.js' }); diff --git a/packages/api/src/augment/consts.ts b/packages/api/src/augment/consts.ts index 19c055f10a..a0e1f3f4dd 100644 --- a/packages/api/src/augment/consts.ts +++ b/packages/api/src/augment/consts.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-chain`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Codec } from '@polkadot/types/types'; import { u32, u64 } from '@polkadot/types/primitive'; diff --git a/packages/api/src/augment/query.ts b/packages/api/src/augment/query.ts index 9fce8e731d..532ecf06a3 100644 --- a/packages/api/src/augment/query.ts +++ b/packages/api/src/augment/query.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-chain`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { AnyNumber, ITuple } from '@polkadot/types/types'; import { Option, U8aFixed, Vec } from '@polkadot/types/codec'; diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index 663d560eca..1c6e8f5109 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -1,14 +1,15 @@ // Auto-generated via `yarn polkadot-types-from-chain`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ 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 { 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 { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion } from '@polkadot/types/interfaces/rpc'; -import { AccountId, BlockNumber, H256, Hash, Header, Index, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime'; +import { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime'; import { Observable } from 'rxjs'; declare module '@polkadot/rpc-core/types.jsonrpc' { @@ -93,6 +94,16 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { **/ getStorage: AugmentedRpc<(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>>; }; + engine: { + /** + * Instructs the manual-seal authorship task to create a new block + **/ + createBlock: AugmentedRpc<(createEmpty: bool | boolean | Uint8Array, finalize: bool | boolean | Uint8Array, parentHash?: BlockHash | string | Uint8Array) => Observable>; + /** + * Instructs the manual-seal authorship task to finalize a block + **/ + finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification | string | Uint8Array) => Observable>; + }; payment: { /** * Retrieves the fee information for an encoded extrinsic diff --git a/packages/api/src/augment/tx.ts b/packages/api/src/augment/tx.ts index 5acb425c63..2fa5c47c4d 100644 --- a/packages/api/src/augment/tx.ts +++ b/packages/api/src/augment/tx.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-chain`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { AnyNumber, ITuple } from '@polkadot/types/types'; import { Compact, Option, U8aFixed, Vec } from '@polkadot/types/codec'; diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 8e7364d1fc..08567cd92a 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -22,7 +22,7 @@ import { Metadata, Null, Option, Raw, Text, TypeRegistry, u64 } from '@polkadot/ import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage'; import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants'; import StorageKey, { StorageEntry, unwrapStorageType } from '@polkadot/types/primitive/StorageKey'; -import { assert, compactStripLength, isNull, isUndefined, u8aConcat, u8aToHex } from '@polkadot/util'; +import { assert, compactStripLength, isNull, isUndefined, logger, u8aConcat, u8aToHex } from '@polkadot/util'; import { createSubmittable } from '../submittable'; import augmentObject from '../util/augmentObject'; @@ -43,6 +43,8 @@ type LinkageData = ITuple<[Codec, Linkage]>; const PAGE_SIZE_KEYS = 256; const PAGE_SIZE_VALS = PAGE_SIZE_KEYS / 2; +const l = logger('api/init'); + export default abstract class Decorate extends Events { public readonly registry: Registry; @@ -213,17 +215,35 @@ export default abstract class Decorate extends Events this.filterRpcMethods(methods); } - protected filterRpcMethods (methods: string[]): void { - // this is true when the RPC has entries - const hasResults = methods.length !== 0; + protected filterRpcMethods (exposed: string[]): void { + const hasResults = exposed.length !== 0; + const allKnown = [...this._rpcCore.mapping.entries()]; + const allKeys = allKnown.reduce((allKeys: string[], [, { alias, method, section, pubsub }]): string[] => { + allKeys.push(`${section}_${method}`); + + if (pubsub) { + allKeys.push(`${section}_${pubsub[1]}`); + allKeys.push(`${section}_${pubsub[2]}`); + } + + if (alias) { + allKeys.push(...alias); + } + + return allKeys; + }, []); + const unknown = exposed.filter((key) => !allKeys.includes(key)); + + if (unknown.length) { + l.warn(`RPC methods not decorated: ${unknown.join(', ')}}`); + } // loop through all entries we have (populated in decorate) and filter as required - [...this._rpcCore.mapping.entries()] - .filter(([key, { isOptional }]): boolean => - // only remove when we have results and method missing, or with no results if optional - hasResults - ? !methods.includes(key) && key !== 'rpc_methods' // rpc_methods doesn't appear, v1 - : isOptional || key === 'rpc_methods' // we didn't find this one, remove + // only remove when we have results and method missing, or with no results if optional + allKnown + .filter(([key]): boolean => hasResults + ? !exposed.includes(key) && key !== 'rpc_methods' // rpc_methods doesn't appear, v1 + : key === 'rpc_methods' // we didn't find this one, remove ) // eslint-disable-next-line @typescript-eslint/no-unused-vars .forEach(([_, { method, section }]): void => { diff --git a/packages/api/src/types/index.ts b/packages/api/src/types/index.ts index cd0d1533b1..0f8e27a0d4 100644 --- a/packages/api/src/types/index.ts +++ b/packages/api/src/types/index.ts @@ -8,10 +8,10 @@ import '@polkadot/api/augment'; import BN from 'bn.js'; import { DeriveCustom, ExactDerive } from '@polkadot/api-derive'; import { Constants } from '@polkadot/metadata/Decorated/types'; -import { RpcInterface, UserRpc } from '@polkadot/rpc-core/types'; +import { RpcInterface } from '@polkadot/rpc-core/types'; import { Metadata } from '@polkadot/types'; import { Hash, RuntimeVersion } from '@polkadot/types/interfaces'; -import { Signer, SignerResult, SignatureOptions, Registry, RegisteredTypes } from '@polkadot/types/types'; +import { DefinitionRpc, DefinitionRpcSub, Signer, SignerResult, SignatureOptions, Registry, RegisteredTypes } from '@polkadot/types/types'; import ApiBase from '../base'; import { DeriveAllSections } from '../util/decorate'; @@ -48,7 +48,7 @@ export interface ApiOptions extends RegisteredTypes { /** * @description User-defined RPC methods */ - rpc?: UserRpc; + rpc?: Record>; /** * @description An external signer which will be used to sign extrinsic when account passed in is not KeyringPair */ diff --git a/packages/jsonrpc/LICENSE b/packages/jsonrpc/LICENSE deleted file mode 100644 index 0d381b2e97..0000000000 --- a/packages/jsonrpc/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/packages/jsonrpc/README.md b/packages/jsonrpc/README.md deleted file mode 100644 index 1bb2b13241..0000000000 --- a/packages/jsonrpc/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# @polkadot/jsonrpc - -A definition of all the methods exposed in a general Polkadot client application. These are used not only to provide a comprehensive code-generated document of the available methods, but are also used in the API to auto-generate endpoints with the required type-checking. - -For a list of currently exposed methods, see the [method documentation](docs/substrate/rpc.md). - -## Usage - -Installation - - -``` -yarn add @polkadot/jsonrpc -``` - -## Adding methods - -As methods are added, simply adding the name, inputs & output will prepare it for use. - -- Add the method to the correct file in [src/rpc/](src/rpc/) (Input/Output types as cross-referenced from the canonical implementation and match one-to-one) -- Should a new type be required, add it to the type list, [src/types.js](src/types.js) (Required for TSLint type checking) - -## Classes - -[Classes](SUMMARY.md) diff --git a/packages/jsonrpc/package.json b/packages/jsonrpc/package.json deleted file mode 100644 index 08050980e1..0000000000 --- a/packages/jsonrpc/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@polkadot/jsonrpc", - "version": "1.8.0-beta.2", - "description": "Method definitions for the Polkadot RPC layer", - "main": "index.js", - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/polkadot-js/api.git" - }, - "keywords": [ - "Polkadot", - "JsonRPC" - ], - "author": "Jaco Greeff ", - "maintainers": [ - "Jaco Greeff " - ], - "contributors": [], - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/polkadot-js/api/issues" - }, - "homepage": "https://github.com/polkadot-js/api/tree/master/packages/jsonrpc#readme", - "dependencies": { - "@babel/runtime": "^7.8.7", - "@polkadot/types": "1.8.0-beta.2", - "@polkadot/util": "^2.6.2" - } -} diff --git a/packages/jsonrpc/src/account.ts b/packages/jsonrpc/src/account.ts deleted file mode 100644 index f8bb2f3c36..0000000000 --- a/packages/jsonrpc/src/account.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -// NOTE order here is the same as in Rust, alphabetical below - -const nextIndex: RpcMethodOpt = { - description: 'Retrieves the next accountIndex as available on the node', - isOptional: true, - params: [ - createParam('accountId', 'AccountId') - ], - type: 'Index' -}; - -const section = 'account'; - -/** - * @summary Calls to account-specific information. - */ -export default { - isDeprecated: false, - isHidden: false, - description: '(Optional) Methods that retrieves account-specific information', - section, - methods: { - nextIndex: createMethod(section, 'nextIndex', nextIndex) - } -}; diff --git a/packages/jsonrpc/src/author.ts b/packages/jsonrpc/src/author.ts deleted file mode 100644 index f0d010b55e..0000000000 --- a/packages/jsonrpc/src/author.ts +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -const hasKey: RpcMethodOpt = { - description: 'Returns true if the keystore has private keys for the given public key and key type.', - params: [ - createParam('publicKey', 'Bytes'), - createParam('keyType', 'Text') - ], - type: 'bool' -}; - -const hasSessionKeys: RpcMethodOpt = { - description: 'Returns true if the keystore has private keys for the given session public keys.', - params: [ - createParam('sessionKeys', 'Bytes') - ], - type: 'bool' -}; - -const removeExtrinsic: RpcMethodOpt = { - description: 'Remove given extrinsic from the pool and temporarily ban it to prevent reimporting', - params: [ - createParam('bytesOrHash', 'Vec') - ], - type: 'Vec' -}; - -const insertKey: RpcMethodOpt = { - description: 'Insert a key into the keystore.', - params: [ - createParam('keyType', 'Text'), - createParam('suri', 'Text'), - createParam('publicKey', 'Bytes') - ], - type: 'Bytes' -}; - -const rotateKeys: RpcMethodOpt = { - description: 'Generate new session keys and returns the corresponding public keys', - params: [], - type: 'Bytes' -}; - -const pendingExtrinsics: RpcMethodOpt = { - description: 'Returns all pending extrinsics, potentially grouped by sender', - params: [], - type: 'Vec' -}; - -const submitExtrinsic: RpcMethodOpt = { - isSigned: true, - description: 'Submit a fully formatted extrinsic for block inclusion', - params: [ - createParam('extrinsic', 'Extrinsic') - ], - type: 'Hash' -}; - -const submitAndWatchExtrinsic: RpcMethodOpt = { - description: 'Submit and subscribe to watch an extrinsic until unsubscribed', - isSigned: true, - params: [ - createParam('extrinsic', 'Extrinsic') - ], - pubsub: [ - 'extrinsicUpdate', - 'submitAndWatchExtrinsic', - 'unwatchExtrinsic' - ], - type: 'ExtrinsicStatus' -}; - -const section = 'author'; - -/** - * @summary Calls to work with authors & contributors. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Authoring of network items', - section, - methods: { - hasKey: createMethod(section, 'hasKey', hasKey), - hasSessionKeys: createMethod(section, 'hasSessionKeys', hasSessionKeys), - insertKey: createMethod(section, 'insertKey', insertKey), - removeExtrinsic: createMethod(section, 'removeExtrinsic', removeExtrinsic), - rotateKeys: createMethod(section, 'rotateKeys', rotateKeys), - pendingExtrinsics: createMethod(section, 'pendingExtrinsics', pendingExtrinsics), - submitExtrinsic: createMethod(section, 'submitExtrinsic', submitExtrinsic), - submitAndWatchExtrinsic: createMethod(section, 'submitAndWatchExtrinsic', submitAndWatchExtrinsic) - } -}; diff --git a/packages/jsonrpc/src/chain.ts b/packages/jsonrpc/src/chain.ts deleted file mode 100644 index f417d5008c..0000000000 --- a/packages/jsonrpc/src/chain.ts +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -// NOTE Order is the same as in Rust - -const getHeader: RpcMethodOpt = { - description: 'Retrieves the header for a specific block', - params: [ - createParam('hash', 'BlockHash', { isOptional: true }) - ], - type: 'Header' -}; - -const getBlock: RpcMethodOpt = { - description: 'Get header and body of a relay chain block', - params: [ - createParam('hash', 'BlockHash', { isOptional: true }) - ], - type: 'SignedBlock' -}; - -const getBlockHash: RpcMethodOpt = { - description: 'Get the block hash for a specific block', - params: [ - createParam('blockNumber', 'BlockNumber', { isOptional: true }) - ], - type: 'BlockHash' -}; - -const getFinalizedHead: RpcMethodOpt = { - description: 'Get hash of the last finalized block in the canon chain', - params: [], - type: 'BlockHash' -}; - -const subscribeNewHeads: RpcMethodOpt = { - description: 'Retrieves the best header via subscription', - params: [], - // NOTE These still has the aliassed version, compatible with 1.x - pubsub: [ - 'newHead', - 'subscribeNewHead', - 'unsubscribeNewHead' - ], - type: 'Header' -}; - -const subscribeFinalizedHeads: RpcMethodOpt = { - description: 'Retrieves the best finalized header via subscription', - params: [], - pubsub: [ - 'finalizedHead', - 'subscribeFinalizedHeads', - 'unsubscribeFinalizedHeads' - ], - type: 'Header' -}; - -const subscribeAllHeads: RpcMethodOpt = { - description: 'Retrieves the newest header via subscription', - params: [], - pubsub: [ - 'allHead', - 'subscribeAllHeads', - 'unsubscribeAllHeads' - ], - type: 'Header' -}; - -const section = 'chain'; - -/** - * @summary Calls to retrieve chain data. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Retrieval of chain data', - section, - methods: { - getBlock: createMethod(section, 'getBlock', getBlock), - getBlockHash: createMethod(section, 'getBlockHash', getBlockHash), - getFinalizedHead: createMethod(section, 'getFinalizedHead', getFinalizedHead), - getHeader: createMethod(section, 'getHeader', getHeader), - subscribeFinalizedHeads: createMethod(section, 'subscribeFinalizedHeads', subscribeFinalizedHeads), - subscribeNewHeads: createMethod(section, 'subscribeNewHeads', subscribeNewHeads), - subscribeAllHeads: createMethod(section, 'subscribeAllHeads', subscribeAllHeads) - } -}; diff --git a/packages/jsonrpc/src/contracts.ts b/packages/jsonrpc/src/contracts.ts deleted file mode 100644 index 3851121281..0000000000 --- a/packages/jsonrpc/src/contracts.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -// NOTE order here is the same as in Rust, alphabetical below - -const call: RpcMethodOpt = { - description: 'Executes a call to a contract', - isOptional: true, - params: [ - createParam('callRequest', 'ContractCallRequest'), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'ContractExecResult' -}; - -const getStorage: RpcMethodOpt = { - description: 'Returns the value under a specified storage key in a contract', - isOptional: true, - params: [ - createParam('address', 'AccountId'), - createParam('key', 'H256'), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'Option' -}; - -const section = 'contracts'; - -/** - * @summary Calls to retrieve system info. - */ -export default { - isDeprecated: false, - isHidden: false, - description: '(Optional) Methods that performs actions on contracts', - section, - methods: { - call: createMethod(section, 'call', call), - getStorage: createMethod(section, 'getStorage', getStorage) - } -}; diff --git a/packages/jsonrpc/src/create/method.ts b/packages/jsonrpc/src/create/method.ts deleted file mode 100644 index 9775c44de3..0000000000 --- a/packages/jsonrpc/src/create/method.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt, RpcMethod } from '../types'; - -import { isUndefined } from '@polkadot/util'; - -/** @internal */ -export default function createMethod (section: string, method: string, { description, isDeprecated = false, isHidden = false, isOptional = false, isSigned = false, params, pubsub, type }: RpcMethodOpt): RpcMethod { - return { - description, - isDeprecated, - isHidden, - isOptional, - isSigned, - isSubscription: !isUndefined(pubsub), - method, - params, - pubsub: pubsub || ['', '', ''], - section, - type - }; -} diff --git a/packages/jsonrpc/src/create/param.ts b/packages/jsonrpc/src/create/param.ts deleted file mode 100644 index ec3645c8ea..0000000000 --- a/packages/jsonrpc/src/create/param.ts +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { InterfaceTypes } from '@polkadot/types/types'; -import { RpcParam } from '../types'; - -interface RpcParamOptions { - isOptional?: boolean; -} - -/** @internal */ -export default function createParam (name: string, type: keyof InterfaceTypes, { isOptional = false }: RpcParamOptions = { isOptional: false }): RpcParam { - return { - isOptional, - name, - type - }; -} diff --git a/packages/jsonrpc/src/engine.ts b/packages/jsonrpc/src/engine.ts deleted file mode 100644 index 1d9dcaab75..0000000000 --- a/packages/jsonrpc/src/engine.ts +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -const createBlock: RpcMethodOpt = { - description: 'Instructs the manual-seal authorship task to create a new block', - params: [ - createParam('createEmpty', 'bool'), - createParam('finalize', 'bool'), - createParam('parentHash', 'Option') - ], - type: 'CreatedBlock' -}; - -const finalizeBlock: RpcMethodOpt = { - description: 'Instructs the manual-seal authorship task to finalize a block', - params: [ - createParam('hash', 'BlockHash'), - createParam('justification', 'Option') - ], - type: 'bool' -}; - -const section = 'engine'; - -/** - * @summary Calls to interact with the block production engine - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Block production engine', - section, - methods: { - createBlock: createMethod(section, 'createBlock', createBlock), - finalizeBlock: createMethod(section, 'finalizeBlock', finalizeBlock) - } -}; diff --git a/packages/jsonrpc/src/index.spec.ts b/packages/jsonrpc/src/index.spec.ts deleted file mode 100644 index b248103924..0000000000 --- a/packages/jsonrpc/src/index.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 interfaces from './'; - -describe('jsonrpc', (): void => { - it('exports the available interfaces', (): void => { - expect(interfaces).toBeDefined(); - expect(Object.keys(interfaces).length).toBeGreaterThan(0); - }); -}); diff --git a/packages/jsonrpc/src/index.ts b/packages/jsonrpc/src/index.ts deleted file mode 100644 index 31510d43c4..0000000000 --- a/packages/jsonrpc/src/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcSection } from './types'; - -import account from './account'; -import author from './author'; -import chain from './chain'; -import contracts from './contracts'; -import payment from './payment'; -import rpc from './rpc'; -import state from './state'; -import system from './system'; - -const interfaces: Record = { - account, - author, - chain, - contracts, - payment, - rpc, - state, - system -}; - -export default interfaces; diff --git a/packages/jsonrpc/src/payment.ts b/packages/jsonrpc/src/payment.ts deleted file mode 100644 index ec2b10b15a..0000000000 --- a/packages/jsonrpc/src/payment.ts +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -// NOTE order here is the same as in Rust, alphabetical below - -const queryInfo: RpcMethodOpt = { - description: 'Retrieves the fee information for an encoded extrinsic', - isOptional: true, - params: [ - createParam('extrinsic', 'Bytes'), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'RuntimeDispatchInfo' -}; - -const section = 'payment'; - -/** - * @summary Calls to retrieve payment information. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Methods that retrieves payment information, e.g. fee calculations', - section, - methods: { - queryInfo: createMethod(section, 'queryInfo', queryInfo) - } -}; diff --git a/packages/jsonrpc/src/rpc.ts b/packages/jsonrpc/src/rpc.ts deleted file mode 100644 index 9362fc75e8..0000000000 --- a/packages/jsonrpc/src/rpc.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; - -// NOTE order here is the same as in Rust, alphabetical below - -const methods: RpcMethodOpt = { - description: 'Retrieves the list of RPC methods that are exposed by the node', - params: [], - type: 'RpcMethods' -}; - -const section = 'rpc'; - -/** - * @summary Calls to retrieve system info. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Retrieves information about the RPC endpoints', - section, - methods: { - methods: createMethod(section, 'methods', methods) - } -}; diff --git a/packages/jsonrpc/src/state.ts b/packages/jsonrpc/src/state.ts deleted file mode 100644 index ff8123947a..0000000000 --- a/packages/jsonrpc/src/state.ts +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; -import createParam from './create/param'; - -// NOTE Order here is the same as in the Rust code - -const call: RpcMethodOpt = { - description: 'Perform a call to a builtin on the chain', - params: [ - createParam('method', 'Text'), - createParam('data', 'Bytes'), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'Bytes' -}; - -const KEY_QUERY_PARAMS = [ - createParam('key', 'StorageKey'), - createParam('at', 'BlockHash', { isOptional: true }) -]; - -const getKeys: RpcMethodOpt = { - description: 'Retrieves the keys with a certain prefix', - params: KEY_QUERY_PARAMS, - type: 'Vec' -}; - -const getKeysPaged: RpcMethodOpt = { - description: 'Returns the keys with prefix with pagination support.', - params: [ - createParam('key', 'StorageKey'), - createParam('count', 'u32'), - createParam('startKey', 'StorageKey', { isOptional: true }), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'Vec' -}; - -const getStorage: RpcMethodOpt = { - description: 'Retrieves the storage for a key', - params: KEY_QUERY_PARAMS, - type: 'StorageData' -}; - -const getStorageHash: RpcMethodOpt = { - description: 'Retrieves the storage hash', - params: KEY_QUERY_PARAMS, - type: 'Hash' -}; - -const getStorageSize: RpcMethodOpt = { - description: 'Retrieves the storage size', - params: KEY_QUERY_PARAMS, - type: 'u64' -}; - -const CHILD_QUERY_PARAMS = [ - createParam('childStorageKey', 'StorageKey'), - createParam('childDefinition', 'StorageKey'), - createParam('childType', 'u32'), - createParam('key', 'StorageKey'), - createParam('at', 'BlockHash', { isOptional: true }) -]; - -const getChildKeys: RpcMethodOpt = { - description: 'Retrieves the keys with prefix of a specific child storage', - params: CHILD_QUERY_PARAMS, - type: 'Vec' -}; - -const getChildStorage: RpcMethodOpt = { - description: 'Retrieves the child storage for a key', - params: CHILD_QUERY_PARAMS, - type: 'StorageData' -}; - -const getChildStorageHash: RpcMethodOpt = { - description: 'Retrieves the child storage hash', - params: CHILD_QUERY_PARAMS, - type: 'Hash' -}; - -const getChildStorageSize: RpcMethodOpt = { - description: 'Retrieves the child storage size', - params: CHILD_QUERY_PARAMS, - type: 'u64' -}; - -const getMetadata: RpcMethodOpt = { - description: 'Returns the runtime metadata', - params: [ - createParam('at', 'BlockHash', { isOptional: true }) - ], - // This is not part of keyof InterfaceTypes - type: 'Metadata' as any -}; - -const getRuntimeVersion: RpcMethodOpt = { - description: 'Get the runtime version', - params: [ - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'RuntimeVersion' -}; - -const queryStorage: RpcMethodOpt = { - description: 'Query historical storage entries (by key) starting from a start block', - params: [ - createParam('keys', 'Vec'), - createParam('startBlock', 'Hash'), - createParam('at', 'BlockHash', { isOptional: true }) - ], - type: 'Vec' -}; - -const subscribeRuntimeVersion: RpcMethodOpt = { - description: 'Retrieves the runtime version via subscription', - params: [], - pubsub: [ - 'runtimeVersion', - 'subscribeRuntimeVersion', - 'unsubscribeRuntimeVersion' - ], - type: 'RuntimeVersion' -}; - -const subscribeStorage: RpcMethodOpt = { - description: 'Subscribes to storage changes for the provided keys', - params: [ - createParam('keys', 'Vec') - ], - pubsub: [ - 'storage', - 'subscribeStorage', - 'unsubscribeStorage' - ], - type: 'StorageChangeSet' -}; - -const section = 'state'; - -/** - * @summary Query the state and state storage. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Query of state', - section, - methods: { - call: createMethod(section, 'call', call), - getChildKeys: createMethod(section, 'getChildKeys', getChildKeys), - getChildStorage: createMethod(section, 'getChildStorage', getChildStorage), - getChildStorageHash: createMethod(section, 'getChildStorageHash', getChildStorageHash), - getChildStorageSize: createMethod(section, 'getChildStorageSize', getChildStorageSize), - getKeys: createMethod(section, 'getKeys', getKeys), - getKeysPaged: createMethod(section, 'getKeysPaged', getKeysPaged), - getMetadata: createMethod(section, 'getMetadata', getMetadata), - getRuntimeVersion: createMethod(section, 'getRuntimeVersion', getRuntimeVersion), - getStorage: createMethod(section, 'getStorage', getStorage), - getStorageHash: createMethod(section, 'getStorageHash', getStorageHash), - getStorageSize: createMethod(section, 'getStorageSize', getStorageSize), - queryStorage: createMethod(section, 'queryStorage', queryStorage), - subscribeRuntimeVersion: createMethod(section, 'subscribeRuntimeVersion', subscribeRuntimeVersion), - subscribeStorage: createMethod(section, 'subscribeStorage', subscribeStorage) - } -}; diff --git a/packages/jsonrpc/src/system.ts b/packages/jsonrpc/src/system.ts deleted file mode 100644 index 2a9002b605..0000000000 --- a/packages/jsonrpc/src/system.ts +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { RpcMethodOpt } from './types'; - -import createMethod from './create/method'; - -// NOTE order here is the same as in Rust, alphabetical below - -const name: RpcMethodOpt = { - description: 'Retrieves the node name', - params: [], - type: 'Text' -}; - -const version: RpcMethodOpt = { - description: 'Retrieves the version of the node', - params: [], - type: 'Text' -}; - -const chain: RpcMethodOpt = { - description: 'Retrieves the chain', - params: [], - type: 'Text' -}; - -const properties: RpcMethodOpt = { - description: 'Get a custom set of properties as a JSON object, defined in the chain spec', - params: [], - type: 'ChainProperties' -}; - -const health: RpcMethodOpt = { - description: 'Return health status of the node', - params: [], - type: 'Health' -}; - -const peers: RpcMethodOpt = { - description: 'Returns the currently connected peers', - params: [], - type: 'Vec' -}; - -const networkState: RpcMethodOpt = { - description: 'Returns current state of the network', - params: [], - type: 'NetworkState' -}; - -const section = 'system'; - -/** - * @summary Calls to retrieve system info. - */ -export default { - isDeprecated: false, - isHidden: false, - description: 'Calls to retrieve system info', - section, - methods: { - chain: createMethod(section, 'chain', chain), - health: createMethod(section, 'health', health), - name: createMethod(section, 'name', name), - networkState: createMethod(section, 'networkState', networkState), - peers: createMethod(section, 'peers', peers), - properties: createMethod(section, 'properties', properties), - version: createMethod(section, 'version', version) - } -}; diff --git a/packages/jsonrpc/src/types.ts b/packages/jsonrpc/src/types.ts deleted file mode 100644 index f66d06c3e3..0000000000 --- a/packages/jsonrpc/src/types.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017-2020 @polkadot/jsonrpc 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 { InterfaceTypes } from '@polkadot/types/types'; - -type PubSub = [string, string, string]; - -export interface RpcParam { - isOptional: boolean; - name: string; - type: keyof InterfaceTypes; -} - -export interface RpcMethodOpt { - description: string; - isDeprecated?: boolean; - isHidden?: boolean; - isOptional?: boolean; - isSigned?: boolean; - isSubscription?: boolean; - params: RpcParam[]; - pubsub?: PubSub; - type: keyof InterfaceTypes; -} - -export interface RpcMethod { - alias?: string; - description: string; - isDeprecated: boolean; - isHidden: boolean; - isOptional: boolean; - isSigned: boolean; - isSubscription: boolean; - method: string; - params: RpcParam[]; - pubsub: PubSub; - section: string; - type: keyof InterfaceTypes; -} - -export interface RpcSection { - isDeprecated: boolean; - isHidden: boolean; - description: string; - section: string; - methods: Record; -} diff --git a/packages/metadata/src/Decorated/storage/fromMetadata/getHasher.ts b/packages/metadata/src/Decorated/storage/fromMetadata/getHasher.ts index 1dc3e66b94..93aac5bc3c 100644 --- a/packages/metadata/src/Decorated/storage/fromMetadata/getHasher.ts +++ b/packages/metadata/src/Decorated/storage/fromMetadata/getHasher.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import metadataDefs from '@polkadot/types/interfaces/metadata/definitions'; +import { AllHashers } from '@polkadot/types/interfaces/metadata/definitions'; import { StorageHasher } from '@polkadot/types/interfaces'; import { u8aConcat, u8aToU8a } from '@polkadot/util'; import { blake2AsU8a, xxhashAsU8a } from '@polkadot/util-crypto'; @@ -13,7 +13,7 @@ export type HasherFunction = (data: HasherInput) => Uint8Array; const DEFAULT_FN = (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128); -const HASHERS: Record = { +const HASHERS: Record = { Blake2_128: (data: HasherInput): Uint8Array => // eslint-disable-line @typescript-eslint/camelcase blake2AsU8a(data, 128), Blake2_128Concat: (data: HasherInput): Uint8Array => // eslint-disable-line @typescript-eslint/camelcase diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 3754f2e2d1..adaf21c774 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -27,7 +27,6 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme", "dependencies": { "@babel/runtime": "^7.8.7", - "@polkadot/jsonrpc": "1.8.0-beta.2", "@polkadot/metadata": "1.8.0-beta.2", "@polkadot/rpc-provider": "1.8.0-beta.2", "@polkadot/types": "1.8.0-beta.2", diff --git a/packages/rpc-core/src/index.spec.ts b/packages/rpc-core/src/index.spec.ts index 1602539423..c5ba1edea2 100644 --- a/packages/rpc-core/src/index.spec.ts +++ b/packages/rpc-core/src/index.spec.ts @@ -24,37 +24,32 @@ describe('Api', (): void => { Object.keys(rpc).filter((key): boolean => !key.startsWith('_')) ).toEqual([ 'mapping', 'provider', 'registry', 'sections', - 'account', 'author', 'chain', 'contracts', 'payment', 'rpc', 'state', 'system' + '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: [ - { - name: 'foo', + testing: { + foo: { + description: 'foo', params: [{ name: 'bar', type: 'u32' }], type: 'Balance' } - ] + } }); expect(isFunction((rpc as any).testing.foo)).toBe(true); expect(rpc.sections.includes('testing')).toBe(true); expect(rpc.mapping.get('testing_foo')).toEqual({ - description: 'User defined', - isDeprecated: false, - isHidden: false, - isOptional: false, - isSigned: false, + description: 'foo', isSubscription: false, + jsonrpc: 'testing_foo', method: 'foo', params: [{ - isOptional: false, name: 'bar', type: 'u32' }], - pubsub: ['', '', ''], section: 'testing', type: 'Balance' }); diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 38fb7b5c1f..123b6e08d7 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -3,24 +3,19 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types'; -import { RpcMethod, RpcSection, RpcParam } from '@polkadot/jsonrpc/types'; import { Hash } from '@polkadot/types/interfaces'; -import { AnyJson, Codec, Registry } from '@polkadot/types/types'; -import { RpcInterface, RpcInterfaceMethod, UserRpc } from './types'; +import { AnyJson, Codec, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types'; +import { RpcInterface, RpcInterfaceMethod } from './types'; import memoizee from 'memoizee'; import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs'; import { catchError, map, publishReplay, refCount, switchMap } from 'rxjs/operators'; -import jsonrpc from '@polkadot/jsonrpc'; -import jsonrpcMethod from '@polkadot/jsonrpc/create/method'; -import jsonrpcParam from '@polkadot/jsonrpc/create/param'; +import jsonrpc from '@polkadot/types/interfaces/jsonrpc'; import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types'; import { assert, isFunction, isNull, isNumber, isUndefined, logger, u8aToU8a } from '@polkadot/util'; import { drr } from './rxjs'; -type UserRpcConverted = Record>; - const l = logger('rpc-core'); const EMPTY_META = { @@ -34,7 +29,7 @@ const EMPTY_META = { // utility method to create a nicely-formatted error /** @internal */ -function createErrorMessage ({ method, params, type }: RpcMethod, error: Error): string { +function createErrorMessage (method: string, { params, type }: DefinitionRpc, error: Error): string { const inputs = params.map(({ isOptional, name, type }): string => `${name}${isOptional ? '?' : ''}: ${type}` ).join(', '); @@ -68,7 +63,7 @@ function createErrorMessage ({ method, params, type }: RpcMethod, error: Error): export default class Rpc implements RpcInterface { readonly #storageCache = new Map(); - public readonly mapping: Map = new Map(); + public readonly mapping: Map = new Map(); public readonly provider: ProviderInterface; @@ -88,6 +83,8 @@ export default class Rpc implements RpcInterface { public readonly contracts!: RpcInterface['contracts']; + public readonly engine!: RpcInterface['engine']; + public readonly payment!: RpcInterface['payment']; public readonly rpc!: RpcInterface['rpc']; @@ -101,14 +98,14 @@ export default class Rpc implements RpcInterface { * Default constructor for the Api Object * @param {ProviderInterface} provider An API provider using HTTP or WebSocket */ - constructor (registry: Registry, provider: ProviderInterface, userRpc: UserRpc = {}) { + constructor (registry: Registry, provider: ProviderInterface, userRpc: Record> = {}) { // eslint-disable-next-line @typescript-eslint/unbound-method assert(provider && isFunction(provider.send), 'Expected Provider to API create'); this.registry = registry; this.provider = provider; - this.createInterfaces(jsonrpc, userRpc); + this.createInterfaces(userRpc); } /** @@ -118,47 +115,32 @@ export default class Rpc implements RpcInterface { this.provider.disconnect(); } - private createInterfaces
(interfaces: Record, userBare: UserRpc): void { + private createInterfaces
(userRpc: Record>): void { + const sectionNames = Object.keys(jsonrpc); + // these are the base keys (i.e. part of jsonrpc) - this.sections.push(...Object.keys(interfaces)); + this.sections.push(...sectionNames); // add any extra user-defined sections - this.sections.push(...Object.keys(userBare).filter((key): boolean => !this.sections.includes(key))); - - // convert the user inputs into the same format as used in jsonrpc - const user = Object.entries(userBare).reduce((user: UserRpcConverted, [sectionName, methods]): UserRpcConverted => { - user[sectionName] = methods.reduce((section: Record, def): Record => { - const { description = 'User defined', name, params, type } = def; - - section[name] = jsonrpcMethod(sectionName, name, { - description, - params: params.map(({ isOptional, name, type }): RpcParam => - jsonrpcParam(name, type as any, { isOptional })), - type: type as any - }); - - return section; - }, {}); - - return user; - }, {}); + this.sections.push(...Object.keys(userRpc).filter((key): boolean => !this.sections.includes(key))); // decorate the sections with base and user methods this.sections.forEach((sectionName): void => { (this as any)[sectionName as Section] = { - ...this.createInterface(sectionName, interfaces[sectionName] ? interfaces[sectionName].methods : {}), - ...this.createInterface(sectionName, user[sectionName] || {}) + ...this.createInterface(sectionName, jsonrpc[sectionName as 'babe'] || {}), + ...this.createInterface(sectionName, userRpc[sectionName] || {}) }; }); } - private createInterface
(section: string, methods: Record): RpcInterface[Section] { + private createInterface
(section: string, methods: Record): RpcInterface[Section] { return Object .keys(methods) .reduce((exposed, method): RpcInterface[Section] => { const def = methods[method]; + const isSubscription = !!(def as DefinitionRpcSub).pubsub; - this.mapping.set(`${section}_${method}`, def); + this.mapping.set(`${section}_${method}`, { ...def, isSubscription, jsonrpc: `${section}_${method}`, method, section }); // FIXME Remove any here // To do so, remove `RpcInterfaceMethod` from './types.ts', and refactor @@ -166,9 +148,9 @@ export default class Rpc implements RpcInterface { // `` // Not doing so, because it makes this class a little bit less readable, // and leaving it as-is doesn't harm much - (exposed as any)[method] = def.isSubscription - ? this.createMethodSubscribe(def) - : this.createMethodSend(def); + (exposed as any)[method] = isSubscription + ? this.createMethodSubscribe(section, method, def as DefinitionRpcSub) + : this.createMethodSend(section, method, def); return exposed; }, {} as RpcInterface[Section]); @@ -182,11 +164,9 @@ export default class Rpc implements RpcInterface { return call as RpcInterfaceMethod; } - private createMethodSend (method: RpcMethod): RpcInterfaceMethod { - const rpcName = `${method.section}_${method.method}`; + private createMethodSend (section: string, method: string, def: DefinitionRpc): RpcInterfaceMethod { + const rpcName = `${section}_${method}`; const creator = (isRaw: boolean) => (...values: any[]): Observable => { - // TODO Warn on deprecated methods - // Here, logically, it should be `of(this.formatInputs(method, values))`. // However, formatInputs can throw, and when it does, the above way // doesn't throw in the "Observable loop" (which is internally wrapped in @@ -194,7 +174,7 @@ export default class Rpc implements RpcInterface { // - first do `of(1)` - won't throw // - then do `map(()=>this.formatInputs)` - might throw, but inside Observable. return of(1).pipe( - map((): Codec[] => this.formatInputs(method, values)), + map((): Codec[] => this.formatInputs(def, values)), switchMap((params): Observable<[Codec[], any]> => combineLatest([ of(params), @@ -204,10 +184,10 @@ export default class Rpc implements RpcInterface { map(([params, result]): any => isRaw ? this.registry.createType('Raw', result) - : this.formatOutput(method, params, result) + : this.formatOutput(def, params, result) ), catchError((error): any => { - const message = createErrorMessage(method, error); + const message = createErrorMessage(method, def, error); // don't scare with old nodes, this is handled transparently rpcName !== 'rpc_methods' && l.error(message); @@ -238,17 +218,17 @@ export default class Rpc implements RpcInterface { }); } - private createMethodSubscribe (method: RpcMethod): RpcInterfaceMethod { - const [updateType, subMethod, unsubMethod] = method.pubsub; - const subName = `${method.section}_${subMethod}`; - const unsubName = `${method.section}_${unsubMethod}`; - const subType = `${method.section}_${updateType}`; + private createMethodSubscribe (section: string, method: string, def: DefinitionRpcSub): RpcInterfaceMethod { + const [updateType, subMethod, unsubMethod] = def.pubsub; + const subName = `${section}_${subMethod}`; + const unsubName = `${section}_${unsubMethod}`; + const subType = `${section}_${updateType}`; const creator = (isRaw: boolean) => (...values: any[]): Observable => { return new Observable((observer: Observer): VoidCallback => { // Have at least an empty promise, as used in the unsubscribe let subscriptionPromise: Promise = Promise.resolve(); const errorHandler = (error: Error): void => { - const message = createErrorMessage(method, error); + const message = createErrorMessage(method, def, error); l.error(message); @@ -256,11 +236,11 @@ export default class Rpc implements RpcInterface { }; try { - const params = this.formatInputs(method, values); + const params = this.formatInputs(def, values); const paramsJson = params.map((param): AnyJson => param.toJSON()); const update = (error?: Error | null, result?: any): void => { if (error) { - l.error(createErrorMessage(method, error)); + l.error(createErrorMessage(method, def, error)); return; } @@ -268,7 +248,7 @@ export default class Rpc implements RpcInterface { observer.next( isRaw ? this.registry.createType('Raw', result) - : this.formatOutput(method, params, result) + : this.formatOutput(def, params, result) ); } catch (error) { observer.error(error); @@ -301,7 +281,7 @@ export default class Rpc implements RpcInterface { ? this.provider.unsubscribe(subType, unsubName, subscriptionId) : Promise.resolve(false) ) - .catch((error: Error): void => l.error(createErrorMessage(method, error))); + .catch((error: Error): void => l.error(createErrorMessage(method, def, error))); }; }).pipe(drr()); }; @@ -319,16 +299,16 @@ export default class Rpc implements RpcInterface { return memoized; } - private formatInputs (method: RpcMethod, inputs: any[]): Codec[] { - const reqArgCount = method.params.filter(({ isOptional }): boolean => !isOptional).length; - const optText = reqArgCount === method.params.length + private formatInputs (def: DefinitionRpc, inputs: any[]): Codec[] { + const reqArgCount = def.params.filter(({ isOptional }): boolean => !isOptional).length; + const optText = reqArgCount === def.params.length ? '' - : ` (${method.params.length - reqArgCount} optional)`; + : ` (${def.params.length - reqArgCount} optional)`; - assert(inputs.length >= reqArgCount && inputs.length <= method.params.length, `Expected ${method.params.length} parameters${optText}, ${inputs.length} found instead`); + assert(inputs.length >= reqArgCount && inputs.length <= def.params.length, `Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`); return inputs.map((input, index): Codec => - createTypeUnsafe(this.registry, method.params[index].type, [input]) + createTypeUnsafe(this.registry, def.params[index].type, [input]) ); } @@ -338,8 +318,8 @@ export default class Rpc implements RpcInterface { return ['0x3a636f6465'].includes(key.toHex()); } - private formatOutput (method: RpcMethod, params: Codec[], result?: any): Codec | Codec[] { - if (method.type === 'StorageData') { + private formatOutput (rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] { + if (rpc.type === 'StorageData') { const key = params[0] as StorageKey; try { @@ -349,16 +329,16 @@ export default class Rpc implements RpcInterface { throw error; } - } else if (method.type === 'StorageChangeSet') { + } else if (rpc.type === 'StorageChangeSet') { return this.formatStorageSet(params[0] as Vec, result.changes); - } else if (method.type === 'Vec') { + } else if (rpc.type === 'Vec') { return result.map(({ block, changes }: { block: string; changes: [string, string | null][] }): [Hash, Codec[]] => [ this.registry.createType('Hash', block), this.formatStorageSet(params[0] as Vec, changes) ]); } - return createTypeUnsafe(this.registry, method.type, [result]); + return createTypeUnsafe(this.registry, rpc.type, [result]); } private formatStorageData (key: StorageKey, value: string | null): Codec { diff --git a/packages/rpc-core/src/methodSend.spec.ts b/packages/rpc-core/src/methodSend.spec.ts index 66b72f12e6..9c3e9ef5cb 100644 --- a/packages/rpc-core/src/methodSend.spec.ts +++ b/packages/rpc-core/src/methodSend.spec.ts @@ -2,6 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { DefinitionRpc } from '@polkadot/types/types'; + import { TypeRegistry } from '@polkadot/types'; import Rpc from '.'; @@ -9,23 +11,21 @@ import Rpc from '.'; describe('methodSend', (): void => { const registry = new TypeRegistry(); let rpc: Rpc; - let methods: any; + let methods: Record; let provider: any; beforeEach((): void => { methods = { blah: { - method: 'blah', + description: 'test', params: [ { name: 'foo', type: 'Bytes' } ], - section: 'test', type: 'Bytes' }, bleh: { - method: 'bleh', + description: 'test', params: [], - section: 'test', type: 'Bytes' } }; @@ -41,7 +41,7 @@ describe('methodSend', (): void => { it('wraps errors with the call signature', (done): void => { // private access - const method = (rpc as any).createMethodSend(methods.blah); + const method = (rpc as any).createMethodSend('test', 'blah', methods.blah); method().subscribe( (): void => undefined, @@ -54,7 +54,7 @@ describe('methodSend', (): void => { it('checks for mismatched parameters', (done): void => { // private method - const method = (rpc as any).createMethodSend(methods.bleh); + const method = (rpc as any).createMethodSend('test', 'bleh', methods.bleh); method(1).subscribe( (): void => undefined, @@ -66,7 +66,7 @@ describe('methodSend', (): void => { it('calls the provider with the correct parameters', (done): void => { // private method - const method = (rpc as any).createMethodSend(methods.blah); + const method = (rpc as any).createMethodSend('test', 'blah', methods.blah); // Args are length-prefixed, because it's a Bytes method(new Uint8Array([2 << 2, 0x12, 0x34])).subscribe((): void => { diff --git a/packages/rpc-core/src/types.ts b/packages/rpc-core/src/types.ts index 7f9e598262..14c99211ba 100644 --- a/packages/rpc-core/src/types.ts +++ b/packages/rpc-core/src/types.ts @@ -10,12 +10,3 @@ export interface RpcInterfaceMethod { (...params: any[]): Observable; raw (...params: any[]): Observable; } - -export interface UserRpcMethod { - description?: string; - name: string; - params: { isOptional?: boolean; name: string; type: string }[]; - type: string; -} - -export type UserRpc = Record; diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 11df02ffc7..096a3fc113 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -27,7 +27,6 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme", "dependencies": { "@babel/runtime": "^7.8.7", - "@polkadot/jsonrpc": "1.8.0-beta.2", "@polkadot/metadata": "1.8.0-beta.2", "@polkadot/types": "1.8.0-beta.2", "@polkadot/util": "^2.6.2", diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 488fba7eee..a85f9c6287 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -12,7 +12,7 @@ import BN from 'bn.js'; import EventEmitter from 'eventemitter3'; import Metadata from '@polkadot/metadata/Decorated'; import rpcMetadata from '@polkadot/metadata/Metadata/static'; -import interfaces from '@polkadot/jsonrpc'; +import jsonrpc from '@polkadot/types/interfaces/jsonrpc'; import testKeyring from '@polkadot/keyring/testing'; import rpcHeader from '@polkadot/types/json/Header.004.json'; import rpcSignedBlock from '@polkadot/types/json/SignedBlock.004.immortal.json'; @@ -21,15 +21,11 @@ import { randomAsU8a } from '@polkadot/util-crypto'; const INTERVAL = 1000; const SUBSCRIPTIONS: string[] = Array.prototype.concat.apply( - [], Object.values(interfaces).map((area): string[] => + [], Object.values(jsonrpc).map((section): string[] => Object - .values(area.methods) - .filter((method): boolean => - method.isSubscription - ) - .map(({ method, section }): string => - `${section}_${method}` - ) + .values(section) + .filter(({ isSubscription }) => isSubscription) + .map(({ jsonrpc }) => jsonrpc) .concat('chain_subscribeNewHead') ) ); diff --git a/packages/typegen/package.json b/packages/typegen/package.json index 5842291ab1..4f119613f5 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -37,7 +37,6 @@ "@babel/register": "^7.8.6", "@babel/runtime": "^7.8.7", "@polkadot/api": "1.8.0-beta.2", - "@polkadot/jsonrpc": "1.8.0-beta.2", "@polkadot/metadata": "1.8.0-beta.2", "@polkadot/rpc-provider": "1.8.0-beta.2", "@polkadot/types": "1.8.0-beta.2", diff --git a/packages/typegen/scripts/polkadot-types-chain-info.js b/packages/typegen/scripts/polkadot-types-chain-info.js index 50100ecc00..f4cf10677b 100755 --- a/packages/typegen/scripts/polkadot-types-chain-info.js +++ b/packages/typegen/scripts/polkadot-types-chain-info.js @@ -17,7 +17,6 @@ try { '^@polkadot/api-derive(.*)': './packages/api-derive/src\\1', '^@polkadot/metadata(.*)': './packages/metadata/src\\1', '^@polkadot/api(.*)': './packages/api/src/\\1', - '^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1', '^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1', '^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/scripts/polkadot-types-internal-interfaces.js b/packages/typegen/scripts/polkadot-types-internal-interfaces.js index 801975f1c7..88ec0c9b50 100755 --- a/packages/typegen/scripts/polkadot-types-internal-interfaces.js +++ b/packages/typegen/scripts/polkadot-types-internal-interfaces.js @@ -14,7 +14,6 @@ try { plugins: [ ['module-resolver', { alias: { - '^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1', '^@polkadot/metadata(.*)': './packages/metadata/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' } diff --git a/packages/typegen/scripts/polkadot-types-internal-metadata.js b/packages/typegen/scripts/polkadot-types-internal-metadata.js index 04d12e41ca..8aeb53de35 100755 --- a/packages/typegen/scripts/polkadot-types-internal-metadata.js +++ b/packages/typegen/scripts/polkadot-types-internal-metadata.js @@ -14,7 +14,6 @@ try { plugins: [ ['module-resolver', { alias: { - '^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1', '^@polkadot/metadata(.*)': './packages/metadata/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' } diff --git a/packages/typegen/src/generate/rpc.ts b/packages/typegen/src/generate/rpc.ts index a8ee637a06..cdf4d00207 100644 --- a/packages/typegen/src/generate/rpc.ts +++ b/packages/typegen/src/generate/rpc.ts @@ -2,7 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import interfaces from '@polkadot/jsonrpc'; import * as definitions from '@polkadot/types/interfaces/definitions'; import { TypeRegistry } from '@polkadot/types/create'; @@ -19,26 +18,30 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => { return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs); }, {}); - const body = Object.keys(interfaces).sort().reduce((allSections, section): string[] => { - const allMethods = Object.keys(interfaces[section].methods).sort().map((key): string => { - const method = interfaces[section].methods[key]; + const rpcKeys = Object + .keys(definitions) + .filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0) + .sort(); + const body = rpcKeys.reduce((allSections, section): string[] => { + const allMethods = Object.keys(definitions[section as 'babe'].rpc).sort().map((methodName): string => { + const def = definitions[section as 'babe'].rpc[methodName]; // These are too hard to type with generics, do manual overrides if (section === 'state') { setImports(allDefs, imports, ['Codec', 'Hash', 'StorageKey', 'Vec']); - if (method.method === 'getStorage') { - return createDocComments(6, [method.description]) + indent(6)(`getStorage: AugmentedRpc<(key: ${StorageKeyTye}, block?: Hash | Uint8Array | string) => Observable>;`); - } else if (method.method === 'queryStorage') { - return createDocComments(6, [method.description]) + indent(6)(`queryStorage: AugmentedRpc<(keys: Vec | (${StorageKeyTye})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;`); - } else if (method.method === 'subscribeStorage') { - return createDocComments(6, [method.description]) + indent(6)(`subscribeStorage: AugmentedRpc<(keys: Vec | (${StorageKeyTye})[]) => Observable>;`); + if (methodName === 'getStorage') { + return createDocComments(6, [def.description]) + indent(6)(`getStorage: AugmentedRpc<(key: ${StorageKeyTye}, block?: Hash | Uint8Array | string) => Observable>;`); + } else if (methodName === 'queryStorage') { + return createDocComments(6, [def.description]) + indent(6)(`queryStorage: AugmentedRpc<(keys: Vec | (${StorageKeyTye})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;`); + } else if (methodName === 'subscribeStorage') { + return createDocComments(6, [def.description]) + indent(6)(`subscribeStorage: AugmentedRpc<(keys: Vec | (${StorageKeyTye})[]) => Observable>;`); } } - setImports(allDefs, imports, [method.type]); + setImports(allDefs, imports, [def.type]); - const args = method.params.map((param): string => { + const args = def.params.map((param: any): string => { const similarTypes = getSimilarTypes(definitions, registry, param.type, imports); setImports(allDefs, imports, [param.type, ...similarTypes]); @@ -46,7 +49,7 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`; }); - return createDocComments(6, [method.description]) + indent(6)(`${method.method}: AugmentedRpc<(${args.join(', ')}) => Observable<${method.type}>>;`); + return createDocComments(6, [def.description]) + indent(6)(`${methodName}: AugmentedRpc<(${args.join(', ')}) => Observable<${def.type}>>;`); }); return allSections.concat( diff --git a/packages/typegen/src/generate/tsDef.ts b/packages/typegen/src/generate/tsDef.ts index 5c8b2fd981..3a564b8123 100644 --- a/packages/typegen/src/generate/tsDef.ts +++ b/packages/typegen/src/generate/tsDef.ts @@ -4,7 +4,6 @@ import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types'; -import fs from 'fs'; import path from 'path'; import { getTypeDef } from '@polkadot/types/create'; import * as defaultDefinitions from '@polkadot/types/interfaces/definitions'; @@ -194,8 +193,8 @@ function generateTsDefFor (importDefinitions: { [importPath: string]: object }, })) ]); - fs.writeFileSync(path.join(outputDir, defName, 'types.ts'), header.concat(sortedDefs).concat(FOOTER), { flag: 'w' }); - fs.writeFileSync(path.join(outputDir, defName, 'index.ts'), HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' }); + writeFile(path.join(outputDir, defName, 'types.ts'), () => header.concat(sortedDefs).concat(`\n\nexport type PHANTOM_${defName.toUpperCase()} = '${defName}';`).concat(FOOTER), true); + writeFile(path.join(outputDir, defName, 'index.ts'), () => HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), true); } /** @internal */ @@ -219,7 +218,7 @@ export function generateTsDef (importDefinitions: { [importPath: string]: object .concat(FOOTER); }); - fs.writeFileSync(path.join(outputDir, 'index.ts'), HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' }); + writeFile(path.join(outputDir, 'index.ts'), () => HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), true); } /** @internal */ diff --git a/packages/typegen/src/metadataMd.ts b/packages/typegen/src/metadataMd.ts index 73a0d4e7e3..0bd5ebed01 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -5,13 +5,13 @@ import { MetadataLatest } from '@polkadot/types/interfaces/metadata'; import fs from 'fs'; -import interfaces from '@polkadot/jsonrpc'; import Decorated from '@polkadot/metadata/Decorated'; import rpcdata from '@polkadot/metadata/Metadata/static'; import Call from '@polkadot/types/generic/Call'; import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey'; import { TypeRegistry } from '@polkadot/types/create'; import { Vec } from '@polkadot/types/codec'; +import * as definitions from '@polkadot/types/interfaces/definitions'; import { Text } from '@polkadot/types/primitive'; import { stringCamelCase, stringLowerFirst } from '@polkadot/util'; @@ -100,22 +100,26 @@ function sortByName (a: T, b: T): number { /** @internal */ function addRpc (): string { + const sections = Object + .keys(definitions) + .filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0); + return renderPage({ title: 'JSON-RPC', description: DESC_RPC, - sections: Object.keys(interfaces) + sections: sections .sort() .map((sectionName) => { - const section = interfaces[sectionName]; + const section = definitions[sectionName as 'babe']; return { name: sectionName, - description: section.description, - items: Object.keys(section.methods) + // description: section.description, + items: Object.keys(section.rpc) .sort() .map((methodName) => { - const method = section.methods[methodName]; - const args = method.params.map(({ name, isOptional, type }): string => { + const method = section.rpc[methodName]; + const args = method.params.map(({ name, isOptional, type }: any): string => { return name + (isOptional ? '?' : '') + ': `' + type + '`'; }).join(', '); const type = '`' + method.type + '`'; diff --git a/packages/typegen/src/util/derived.ts b/packages/typegen/src/util/derived.ts index 20cc1f2c05..9c7d2dca53 100644 --- a/packages/typegen/src/util/derived.ts +++ b/packages/typegen/src/util/derived.ts @@ -14,9 +14,10 @@ import Struct from '@polkadot/types/codec/Struct'; import UInt from '@polkadot/types/codec/UInt'; import Vec from '@polkadot/types/codec/Vec'; import Tuple from '@polkadot/types/codec/Tuple'; +import { AllConvictions } from '@polkadot/types/interfaces/democracy/definitions'; import GenericAccountId from '@polkadot/types/generic/AccountId'; import GenericAddress from '@polkadot/types/generic/Address'; -import Vote, { convictionNames as _voteConvictions } from '@polkadot/types/generic/Vote'; +import Vote from '@polkadot/types/generic/Vote'; import Null from '@polkadot/types/primitive/Null'; import * as primitiveClasses from '@polkadot/types/primitive'; import { isChildClass, stringLowerFirst } from '@polkadot/util'; @@ -29,7 +30,7 @@ function arrayToStrType (arr: string[]): string { return `(${arr.map((c): string => `'${c}'`).join(' | ')})`; } -const voteConvictions = arrayToStrType(_voteConvictions); +const voteConvictions = arrayToStrType(AllConvictions); // From `T`, generate `Compact, Option, Vec` /** @internal */ diff --git a/packages/typegen/src/util/file.ts b/packages/typegen/src/util/file.ts index 93c4e8a1c1..07add191f2 100644 --- a/packages/typegen/src/util/file.ts +++ b/packages/typegen/src/util/file.ts @@ -4,14 +4,18 @@ import fs from 'fs'; -export function writeFile (dest: string, generator: () => string): void { - console.log(`${dest}\n\tGenerating`); +export function writeFile (dest: string, generator: () => string, noLog?: boolean): void { + !noLog && console.log(`${dest}\n\tGenerating`); - const generated = generator(); + let generated = generator(); - console.log('\tWriting'); + while (generated.includes('\n\n\n')) { + generated = generated.replace(/\n\n\n/g, '\n\n'); + } + + !noLog && console.log('\tWriting'); fs.writeFileSync(dest, generated, { flag: 'w' }); - console.log(''); + !noLog && console.log(''); } diff --git a/packages/typegen/src/util/formatting.ts b/packages/typegen/src/util/formatting.ts index 57fa1f95b1..d3e79fb635 100644 --- a/packages/typegen/src/util/formatting.ts +++ b/packages/typegen/src/util/formatting.ts @@ -9,7 +9,7 @@ import { paramsNotation } from '@polkadot/types/codec/utils'; import { setImports, TypeImports } from './imports'; -export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable @typescript-eslint/no-empty-interface */\n\n`; +export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`; export const FOOTER = '\n'; const TYPES_NON_PRIMITIVE = ['Metadata']; diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 1ab50d2925..d392e41ec7 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Compact, Option, Raw, Vec } from '@polkadot/types/codec'; import { BitVec, Bytes, Data, Null, StorageKey, Text, Type, U256, Unconstructable, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types/primitive'; diff --git a/packages/types/src/generic/Vote.ts b/packages/types/src/generic/Vote.ts index 3d78bb94b6..c81901ec2e 100644 --- a/packages/types/src/generic/Vote.ts +++ b/packages/types/src/generic/Vote.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AnyJson, ArrayElementType, Registry } from '../types'; -import democracyDef from '../interfaces/democracy/definitions'; +import { AllConvictions } from '../interfaces/democracy/definitions'; import { Conviction } from '../interfaces/democracy'; import { isBoolean, isNumber, isU8a, isUndefined } from '@polkadot/util'; @@ -11,12 +11,10 @@ import { isBoolean, isNumber, isU8a, isUndefined } from '@polkadot/util'; import U8aFixed from '../codec/U8aFixed'; import Bool from '../primitive/Bool'; -export const convictionNames = democracyDef.types.Conviction._enum; - // eslint-disable-next-line @typescript-eslint/ban-types type InputTypes = boolean | number | Boolean | Uint8Array | { aye: boolean; - conviction?: number | ArrayElementType; + conviction?: number | ArrayElementType; }; // For votes, the topmost bit indicated aye/nay, the lower bits indicate the conviction diff --git a/packages/types/src/interfaces/account/definitions.ts b/packages/types/src/interfaces/account/definitions.ts new file mode 100644 index 0000000000..da5e95b692 --- /dev/null +++ b/packages/types/src/interfaces/account/definitions.ts @@ -0,0 +1,22 @@ +// 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: { + nextIndex: { + alias: ['system_accountNextIndex'], + description: 'Retrieves the next accountIndex as available on the node', + params: [ + { + name: 'accountId', + type: 'AccountId' + } + ], + type: 'Index' + } + }, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/account/index.ts b/packages/types/src/interfaces/account/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/account/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/account/types.ts b/packages/types/src/interfaces/account/types.ts new file mode 100644 index 0000000000..d4469e0ce5 --- /dev/null +++ b/packages/types/src/interfaces/account/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_ACCOUNT = 'account'; diff --git a/packages/types/src/interfaces/attestations/definitions.ts b/packages/types/src/interfaces/attestations/definitions.ts index c7086bdc8e..a9c89b501e 100644 --- a/packages/types/src/interfaces/attestations/definitions.ts +++ b/packages/types/src/interfaces/attestations/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { BlockAttestations: { receipt: 'CandidateReceipt', @@ -18,4 +21,4 @@ export default { }, MoreAttestations: {} } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/attestations/index.ts b/packages/types/src/interfaces/attestations/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/attestations/index.ts +++ b/packages/types/src/interfaces/attestations/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/attestations/types.ts b/packages/types/src/interfaces/attestations/types.ts index 3bf62c0ee0..b576b8a08f 100644 --- a/packages/types/src/interfaces/attestations/types.ts +++ b/packages/types/src/interfaces/attestations/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { CandidateReceipt, ParaId } from '@polkadot/types/interfaces/parachains'; @@ -24,3 +24,5 @@ export interface IncludedBlocks extends Struct { /** @name MoreAttestations */ export interface MoreAttestations extends Struct {} + +export type PHANTOM_ATTESTATIONS = 'attestations'; diff --git a/packages/types/src/interfaces/aura/definitions.ts b/packages/types/src/interfaces/aura/definitions.ts index 82cd6ddc45..2ee4580568 100644 --- a/packages/types/src/interfaces/aura/definitions.ts +++ b/packages/types/src/interfaces/aura/definitions.ts @@ -2,10 +2,13 @@ // 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: {}, types: { RawAuraPreDigest: { slotNumber: 'u64' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/aura/index.ts b/packages/types/src/interfaces/aura/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/aura/index.ts +++ b/packages/types/src/interfaces/aura/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/aura/types.ts b/packages/types/src/interfaces/aura/types.ts index 2d8776ce64..ab6aca7c74 100644 --- a/packages/types/src/interfaces/aura/types.ts +++ b/packages/types/src/interfaces/aura/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct } from '@polkadot/types/codec'; import { u64 } from '@polkadot/types/primitive'; @@ -8,3 +8,5 @@ import { u64 } from '@polkadot/types/primitive'; export interface RawAuraPreDigest extends Struct { readonly slotNumber: u64; } + +export type PHANTOM_AURA = 'aura'; diff --git a/packages/types/src/interfaces/author/definitions.ts b/packages/types/src/interfaces/author/definitions.ts new file mode 100644 index 0000000000..f20efefd0f --- /dev/null +++ b/packages/types/src/interfaces/author/definitions.ts @@ -0,0 +1,100 @@ +// 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: { + hasKey: { + description: 'Returns true if the keystore has private keys for the given public key and key type.', + params: [ + { + name: 'publicKey', + type: 'Bytes' + }, + { + name: 'keyType', + type: 'Text' + } + ], + type: 'bool' + }, + hasSessionKeys: { + description: 'Returns true if the keystore has private keys for the given session public keys.', + params: [ + { + name: 'sessionKeys', + type: 'Bytes' + } + ], + type: 'bool' + }, + removeExtrinsic: { + description: 'Remove given extrinsic from the pool and temporarily ban it to prevent reimporting', + params: [ + { + name: 'bytesOrHash', + type: 'Vec' + } + ], + type: 'Vec' + }, + insertKey: { + description: 'Insert a key into the keystore.', + params: [ + { + name: 'keyType', + type: 'Text' + }, + { + name: 'suri', + type: 'Text' + }, + { + name: 'publicKey', + type: 'Bytes' + } + ], + type: 'Bytes' + }, + rotateKeys: { + description: 'Generate new session keys and returns the corresponding public keys', + params: [], + type: 'Bytes' + }, + pendingExtrinsics: { + description: 'Returns all pending extrinsics, potentially grouped by sender', + params: [], + type: 'Vec' + }, + submitExtrinsic: { + isSigned: true, + description: 'Submit a fully formatted extrinsic for block inclusion', + params: [ + { + name: 'extrinsic', + type: 'Extrinsic' + } + ], + type: 'Hash' + }, + submitAndWatchExtrinsic: { + description: 'Submit and subscribe to watch an extrinsic until unsubscribed', + isSigned: true, + params: [ + { + name: 'extrinsic', + type: 'Extrinsic' + } + ], + pubsub: [ + 'extrinsicUpdate', + 'submitAndWatchExtrinsic', + 'unwatchExtrinsic' + ], + type: 'ExtrinsicStatus' + } + }, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/author/index.ts b/packages/types/src/interfaces/author/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/author/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/author/types.ts b/packages/types/src/interfaces/author/types.ts new file mode 100644 index 0000000000..9d65972ca2 --- /dev/null +++ b/packages/types/src/interfaces/author/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_AUTHOR = 'author'; diff --git a/packages/types/src/interfaces/authorship/definitions.ts b/packages/types/src/interfaces/authorship/definitions.ts index 84a9da0b3a..f8f0c3b06b 100644 --- a/packages/types/src/interfaces/authorship/definitions.ts +++ b/packages/types/src/interfaces/authorship/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { UncleEntryItem: { _enum: { @@ -11,4 +14,4 @@ export default { } } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/authorship/index.ts b/packages/types/src/interfaces/authorship/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/authorship/index.ts +++ b/packages/types/src/interfaces/authorship/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/authorship/types.ts b/packages/types/src/interfaces/authorship/types.ts index b3c3ed1e6c..da25106631 100644 --- a/packages/types/src/interfaces/authorship/types.ts +++ b/packages/types/src/interfaces/authorship/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Option } from '@polkadot/types/codec'; @@ -12,3 +12,5 @@ export interface UncleEntryItem extends Enum { readonly isUncle: boolean; readonly asUncle: ITuple<[Hash, Option]>; } + +export type PHANTOM_AUTHORSHIP = 'authorship'; diff --git a/packages/types/src/interfaces/babe/definitions.ts b/packages/types/src/interfaces/babe/definitions.ts index ecce00ab27..3e5021c39c 100644 --- a/packages/types/src/interfaces/babe/definitions.ts +++ b/packages/types/src/interfaces/babe/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { BabeAuthorityWeight: 'u64', BabeBlockWeight: 'u32', @@ -59,4 +62,4 @@ export default { VrfData: '[u8; 32]', VrfProof: '[u8; 64]' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/babe/index.ts b/packages/types/src/interfaces/babe/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/babe/index.ts +++ b/packages/types/src/interfaces/babe/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/babe/types.ts b/packages/types/src/interfaces/babe/types.ts index 4af02efa9e..e052b6243c 100644 --- a/packages/types/src/interfaces/babe/types.ts +++ b/packages/types/src/interfaces/babe/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Enum, Option, Struct, U8aFixed } from '@polkadot/types/codec'; import { u32, u64 } from '@polkadot/types/primitive'; @@ -81,3 +81,5 @@ export interface VrfData extends U8aFixed {} /** @name VrfProof */ export interface VrfProof extends U8aFixed {} + +export type PHANTOM_BABE = 'babe'; diff --git a/packages/types/src/interfaces/balances/definitions.ts b/packages/types/src/interfaces/balances/definitions.ts index 6ded790ddc..5b848629ae 100644 --- a/packages/types/src/interfaces/balances/definitions.ts +++ b/packages/types/src/interfaces/balances/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AccountData: { free: 'Balance', @@ -42,4 +45,4 @@ export default { } } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/balances/index.ts b/packages/types/src/interfaces/balances/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/balances/index.ts +++ b/packages/types/src/interfaces/balances/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/balances/types.ts b/packages/types/src/interfaces/balances/types.ts index 762666c97a..7fd7428505 100644 --- a/packages/types/src/interfaces/balances/types.ts +++ b/packages/types/src/interfaces/balances/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Enum, Set, Struct } from '@polkadot/types/codec'; import { Balance, BlockNumber, LockIdentifier } from '@polkadot/types/interfaces/runtime'; @@ -55,3 +55,5 @@ export interface WithdrawReasons extends Set { readonly isFee: boolean; readonly isTip: boolean; } + +export type PHANTOM_BALANCES = 'balances'; diff --git a/packages/types/src/interfaces/chain/definitions.ts b/packages/types/src/interfaces/chain/definitions.ts new file mode 100644 index 0000000000..082f07075d --- /dev/null +++ b/packages/types/src/interfaces/chain/definitions.ts @@ -0,0 +1,84 @@ +// 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: { + getHeader: { + alias: ['chain_getHead'], + description: 'Retrieves the header for a specific block', + params: [ + { + name: 'hash', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Header' + }, + getBlock: { + description: 'Get header and body of a relay chain block', + params: [ + { + name: 'hash', + type: 'BlockHash', + isOptional: true + } + ], + type: 'SignedBlock' + }, + getBlockHash: { + description: 'Get the block hash for a specific block', + params: [ + { + name: 'blockNumber', + type: 'BlockNumber', + isOptional: true + } + ], + type: 'BlockHash' + }, + getFinalizedHead: { + alias: ['chain_getFinalisedHead'], + description: 'Get hash of the last finalized block in the canon chain', + params: [], + type: 'BlockHash' + }, + subscribeNewHeads: { + alias: ['chain_unsubscribeNewHeads', 'subscribe_newHead', 'unsubscribe_newHead'], + description: 'Retrieves the best header via subscription', + params: [], + // NOTE These still has the aliassed version, compatible with 1.x + pubsub: [ + 'newHead', + 'subscribeNewHead', + 'unsubscribeNewHead' + ], + type: 'Header' + }, + subscribeFinalizedHeads: { + alias: ['chain_subscribeFinalisedHeads', 'chain_unsubscribeFinalisedHeads'], + description: 'Retrieves the best finalized header via subscription', + params: [], + pubsub: [ + 'finalizedHead', + 'subscribeFinalizedHeads', + 'unsubscribeFinalizedHeads' + ], + type: 'Header' + }, + subscribeAllHeads: { + description: 'Retrieves the newest header via subscription', + params: [], + pubsub: [ + 'allHead', + 'subscribeAllHeads', + 'unsubscribeAllHeads' + ], + type: 'Header' + } + }, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/chain/index.ts b/packages/types/src/interfaces/chain/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/chain/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/chain/types.ts b/packages/types/src/interfaces/chain/types.ts new file mode 100644 index 0000000000..b18a95c418 --- /dev/null +++ b/packages/types/src/interfaces/chain/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_CHAIN = 'chain'; diff --git a/packages/types/src/interfaces/claims/definitions.ts b/packages/types/src/interfaces/claims/definitions.ts index e922536aaf..2af23d57a0 100644 --- a/packages/types/src/interfaces/claims/definitions.ts +++ b/packages/types/src/interfaces/claims/definitions.ts @@ -2,8 +2,11 @@ // 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: {}, types: { EthereumAddress: 'H160' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/claims/index.ts b/packages/types/src/interfaces/claims/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/claims/index.ts +++ b/packages/types/src/interfaces/claims/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/claims/types.ts b/packages/types/src/interfaces/claims/types.ts index 9e50f09df3..ce0f4ac050 100644 --- a/packages/types/src/interfaces/claims/types.ts +++ b/packages/types/src/interfaces/claims/types.ts @@ -1,7 +1,9 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { H160 } from '@polkadot/types/interfaces/runtime'; /** @name EthereumAddress */ export interface EthereumAddress extends H160 {} + +export type PHANTOM_CLAIMS = 'claims'; diff --git a/packages/types/src/interfaces/collective/definitions.ts b/packages/types/src/interfaces/collective/definitions.ts index 3d7bf5acfc..9e0c3935c2 100644 --- a/packages/types/src/interfaces/collective/definitions.ts +++ b/packages/types/src/interfaces/collective/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { MemberCount: 'u32', ProposalIndex: 'u32', @@ -20,4 +23,4 @@ export default { end: 'BlockNumber' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/collective/index.ts b/packages/types/src/interfaces/collective/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/collective/index.ts +++ b/packages/types/src/interfaces/collective/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/collective/types.ts b/packages/types/src/interfaces/collective/types.ts index e0fd33ce49..af1f53759a 100644 --- a/packages/types/src/interfaces/collective/types.ts +++ b/packages/types/src/interfaces/collective/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { u32 } from '@polkadot/types/primitive'; @@ -27,3 +27,5 @@ export interface VotesTo230 extends Struct { readonly ayes: Vec; readonly nays: Vec; } + +export type PHANTOM_COLLECTIVE = 'collective'; diff --git a/packages/types/src/interfaces/consensus/definitions.ts b/packages/types/src/interfaces/consensus/definitions.ts index c033248159..94e7563148 100644 --- a/packages/types/src/interfaces/consensus/definitions.ts +++ b/packages/types/src/interfaces/consensus/definitions.ts @@ -2,8 +2,11 @@ // 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: {}, types: { AuthorityId: 'AccountId' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/consensus/index.ts b/packages/types/src/interfaces/consensus/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/consensus/index.ts +++ b/packages/types/src/interfaces/consensus/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/consensus/types.ts b/packages/types/src/interfaces/consensus/types.ts index a035debdbd..ec21d1437f 100644 --- a/packages/types/src/interfaces/consensus/types.ts +++ b/packages/types/src/interfaces/consensus/types.ts @@ -1,7 +1,9 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { AccountId } from '@polkadot/types/interfaces/runtime'; /** @name AuthorityId */ export interface AuthorityId extends AccountId {} + +export type PHANTOM_CONSENSUS = 'consensus'; diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index 58d12269fd..76408aed0b 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -2,7 +2,45 @@ // 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: { + call: { + description: 'Executes a call to a contract', + params: [ + { + name: 'callRequest', + type: 'ContractCallRequest' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'ContractExecResult' + }, + getStorage: { + description: 'Returns the value under a specified storage key in a contract', + params: [ + { + name: 'address', + type: 'AccountId' + }, + { + name: 'key', + type: 'H256' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Option' + } + }, types: { AliveContractInfo: { trieId: 'TrieId', @@ -85,4 +123,4 @@ export default { TombstoneContractInfo: 'Hash', TrieId: 'Bytes' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/contracts/index.ts b/packages/types/src/interfaces/contracts/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/contracts/index.ts +++ b/packages/types/src/interfaces/contracts/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index 121f44a053..11c3b0d56f 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Compact, Enum, Option, Raw, Struct, U8aFixed } from '@polkadot/types/codec'; import { Bytes, Null, bool, u32, u64, u8 } from '@polkadot/types/primitive'; @@ -113,3 +113,5 @@ export interface TombstoneContractInfo extends Hash {} /** @name TrieId */ export interface TrieId extends Bytes {} + +export type PHANTOM_CONTRACTS = 'contracts'; diff --git a/packages/types/src/interfaces/definitions.ts b/packages/types/src/interfaces/definitions.ts index 45320d69d9..742a7f7b8a 100644 --- a/packages/types/src/interfaces/definitions.ts +++ b/packages/types/src/interfaces/definitions.ts @@ -41,3 +41,10 @@ export { default as parachains } from './parachains/definitions'; // pull in metadata & rpc last, assuming that is uses info from above export { default as metadata } from './metadata/definitions'; export { default as rpc } from './rpc/definitions'; + +// rpc-only 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 payment } from './payment/definitions'; +export { default as state } from './state/definitions'; diff --git a/packages/types/src/interfaces/democracy/definitions.ts b/packages/types/src/interfaces/democracy/definitions.ts index 4986c5cb79..175eae0ea8 100644 --- a/packages/types/src/interfaces/democracy/definitions.ts +++ b/packages/types/src/interfaces/democracy/definitions.ts @@ -2,25 +2,32 @@ // 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'; + +const AllConvictions = [ + // 0.1x votes, unlocked. + 'None', + // 1x votes, locked for an enactment period following a successful vote. + 'Locked1x', + // 2x votes, locked for 2x enactment periods following a successful vote. + 'Locked2x', + // 3x votes, locked for 4x... + 'Locked3x', + // 4x votes, locked for 8x... + 'Locked4x', + // 5x votes, locked for 16x... + 'Locked5x', + /// 6x votes, locked for 32x... + 'Locked6x' +]; + +export { AllConvictions }; + export default { + rpc: {}, types: { Conviction: { - _enum: [ - // 0.1x votes, unlocked. - 'None', - // 1x votes, locked for an enactment period following a successful vote. - 'Locked1x', - // 2x votes, locked for 2x enactment periods following a successful vote. - 'Locked2x', - // 3x votes, locked for 4x... - 'Locked3x', - // 4x votes, locked for 8x... - 'Locked4x', - // 5x votes, locked for 16x... - 'Locked5x', - /// 6x votes, locked for 32x... - 'Locked6x' - ] + _enum: AllConvictions }, PropIndex: 'u32', Proposal: 'Call', @@ -36,4 +43,4 @@ export default { delay: 'BlockNumber' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/democracy/index.ts b/packages/types/src/interfaces/democracy/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/democracy/index.ts +++ b/packages/types/src/interfaces/democracy/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/democracy/types.ts b/packages/types/src/interfaces/democracy/types.ts index c428173691..1ef5aa7b13 100644 --- a/packages/types/src/interfaces/democracy/types.ts +++ b/packages/types/src/interfaces/democracy/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Enum, Struct } from '@polkadot/types/codec'; import { u32 } from '@polkadot/types/primitive'; @@ -39,3 +39,5 @@ export interface ReferendumInfo extends Struct { readonly threshold: VoteThreshold; readonly delay: BlockNumber; } + +export type PHANTOM_DEMOCRACY = 'democracy'; diff --git a/packages/types/src/interfaces/elections/definitions.ts b/packages/types/src/interfaces/elections/definitions.ts index fb7d57eae6..3d9c7d7754 100644 --- a/packages/types/src/interfaces/elections/definitions.ts +++ b/packages/types/src/interfaces/elections/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { ApprovalFlag: 'u32', SetIndex: 'u32', @@ -22,4 +25,4 @@ export default { ] } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/elections/index.ts b/packages/types/src/interfaces/elections/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/elections/index.ts +++ b/packages/types/src/interfaces/elections/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/elections/types.ts b/packages/types/src/interfaces/elections/types.ts index 0484143cfb..20625e2ae6 100644 --- a/packages/types/src/interfaces/elections/types.ts +++ b/packages/types/src/interfaces/elections/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Enum, Struct } from '@polkadot/types/codec'; import { GenericVote } from '@polkadot/types/generic'; @@ -32,3 +32,5 @@ export interface VoteThreshold extends Enum { readonly isSupermajorityrejection: boolean; readonly isSimplemajority: boolean; } + +export type PHANTOM_ELECTIONS = 'elections'; diff --git a/packages/types/src/interfaces/engine/definitions.ts b/packages/types/src/interfaces/engine/definitions.ts index 273aaf9d44..54aee4f018 100644 --- a/packages/types/src/interfaces/engine/definitions.ts +++ b/packages/types/src/interfaces/engine/definitions.ts @@ -2,7 +2,45 @@ // 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: { + createBlock: { + description: 'Instructs the manual-seal authorship task to create a new block', + params: [ + { + name: 'createEmpty', + type: 'bool' + }, + { + name: 'finalize', + type: 'bool' + }, + { + name: 'parentHash', + type: 'BlockHash', + isOptional: true + } + ], + type: 'CreatedBlock' + }, + finalizeBlock: { + description: 'Instructs the manual-seal authorship task to finalize a block', + params: [ + { + name: 'hash', + type: 'BlockHash' + }, + { + name: 'justification', + type: 'Justification', + isOptional: true + } + ], + type: 'bool' + } + }, types: { CreatedBlock: { hash: 'BlockHash', @@ -17,4 +55,4 @@ export default { isNewBest: 'bool' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/engine/index.ts b/packages/types/src/interfaces/engine/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/engine/index.ts +++ b/packages/types/src/interfaces/engine/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/engine/types.ts b/packages/types/src/interfaces/engine/types.ts index becb795bf3..1ffd3f180f 100644 --- a/packages/types/src/interfaces/engine/types.ts +++ b/packages/types/src/interfaces/engine/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct } from '@polkadot/types/codec'; import { bool } from '@polkadot/types/primitive'; @@ -20,3 +20,5 @@ export interface ImportedAux extends Struct { readonly needsFinalityProof: bool; readonly isNewBest: bool; } + +export type PHANTOM_ENGINE = 'engine'; diff --git a/packages/types/src/interfaces/evm/definitions.ts b/packages/types/src/interfaces/evm/definitions.ts index 7bc8a72d9c..be574499d7 100644 --- a/packages/types/src/interfaces/evm/definitions.ts +++ b/packages/types/src/interfaces/evm/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { Account: { nonce: 'U256', @@ -14,4 +17,4 @@ export default { data: 'Bytes' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/evm/index.ts b/packages/types/src/interfaces/evm/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/evm/index.ts +++ b/packages/types/src/interfaces/evm/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/evm/types.ts b/packages/types/src/interfaces/evm/types.ts index 0945a95eb0..040a0d5287 100644 --- a/packages/types/src/interfaces/evm/types.ts +++ b/packages/types/src/interfaces/evm/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { Bytes, U256 } from '@polkadot/types/primitive'; @@ -17,3 +17,5 @@ export interface Log extends Struct { readonly topics: Vec; readonly data: Bytes; } + +export type PHANTOM_EVM = 'evm'; diff --git a/packages/types/src/interfaces/extrinsics/definitions.ts b/packages/types/src/interfaces/extrinsics/definitions.ts index 25bdd43789..8868644c11 100644 --- a/packages/types/src/interfaces/extrinsics/definitions.ts +++ b/packages/types/src/interfaces/extrinsics/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { Extrinsic: 'GenericExtrinsic', ExtrinsicEra: 'GenericExtrinsicEra', @@ -40,4 +43,4 @@ export default { Ed25519Signature: 'H512', Sr25519Signature: 'H512' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/extrinsics/index.ts b/packages/types/src/interfaces/extrinsics/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/extrinsics/index.ts +++ b/packages/types/src/interfaces/extrinsics/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/extrinsics/types.ts b/packages/types/src/interfaces/extrinsics/types.ts index dca8b06332..f1b6e64b17 100644 --- a/packages/types/src/interfaces/extrinsics/types.ts +++ b/packages/types/src/interfaces/extrinsics/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Enum, U8aFixed } from '@polkadot/types/codec'; import { GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericExtrinsicPayloadUnknown, GenericExtrinsicPayloadV1, GenericExtrinsicPayloadV2, GenericExtrinsicPayloadV3, GenericExtrinsicPayloadV4, GenericExtrinsicSignatureV1, GenericExtrinsicSignatureV2, GenericExtrinsicSignatureV3, GenericExtrinsicSignatureV4, GenericExtrinsicUnknown, GenericExtrinsicV1, GenericExtrinsicV2, GenericExtrinsicV3, GenericExtrinsicV4, GenericImmortalEra, GenericMortalEra, GenericSignerPayload } from '@polkadot/types/extrinsic'; @@ -86,3 +86,5 @@ export interface SignerPayload extends GenericSignerPayload {} /** @name Sr25519Signature */ export interface Sr25519Signature extends H512 {} + +export type PHANTOM_EXTRINSICS = 'extrinsics'; diff --git a/packages/types/src/interfaces/genericAsset/definitions.ts b/packages/types/src/interfaces/genericAsset/definitions.ts index ea91494f4e..8ce5b6d401 100644 --- a/packages/types/src/interfaces/genericAsset/definitions.ts +++ b/packages/types/src/interfaces/genericAsset/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AssetOptions: { initalIssuance: 'Compact', @@ -26,4 +29,4 @@ export default { }, PermissionLatest: 'PermissionsV1' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/genericAsset/index.ts b/packages/types/src/interfaces/genericAsset/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/genericAsset/index.ts +++ b/packages/types/src/interfaces/genericAsset/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/genericAsset/types.ts b/packages/types/src/interfaces/genericAsset/types.ts index a3e30c0e39..276d544cff 100644 --- a/packages/types/src/interfaces/genericAsset/types.ts +++ b/packages/types/src/interfaces/genericAsset/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Compact, Enum, Struct } from '@polkadot/types/codec'; import { AccountId, Balance } from '@polkadot/types/interfaces/runtime'; @@ -32,3 +32,5 @@ export interface PermissionVersions extends Enum { readonly isV1: boolean; readonly asV1: PermissionsV1; } + +export type PHANTOM_GENERICASSET = 'genericAsset'; diff --git a/packages/types/src/interfaces/grandpa/definitions.ts b/packages/types/src/interfaces/grandpa/definitions.ts index 733dede22b..8ed7d53ea8 100644 --- a/packages/types/src/interfaces/grandpa/definitions.ts +++ b/packages/types/src/interfaces/grandpa/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AuthorityIndex: 'u64', AuthorityList: 'Vec', @@ -39,4 +42,4 @@ export default { } } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/grandpa/index.ts b/packages/types/src/interfaces/grandpa/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/grandpa/index.ts +++ b/packages/types/src/interfaces/grandpa/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/grandpa/types.ts b/packages/types/src/interfaces/grandpa/types.ts index 33a70b8432..e140ffbf63 100644 --- a/packages/types/src/interfaces/grandpa/types.ts +++ b/packages/types/src/interfaces/grandpa/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Struct, Vec } from '@polkadot/types/codec'; @@ -50,3 +50,5 @@ export interface StoredState extends Enum { readonly isPendingResume: boolean; readonly asPendingResume: PendingResume; } + +export type PHANTOM_GRANDPA = 'grandpa'; diff --git a/packages/types/src/interfaces/identity/definitions.ts b/packages/types/src/interfaces/identity/definitions.ts index 89a296d48c..b4c79aa32d 100644 --- a/packages/types/src/interfaces/identity/definitions.ts +++ b/packages/types/src/interfaces/identity/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { IdentityFields: { _set: { @@ -54,4 +57,4 @@ export default { fields: 'IdentityFields' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/identity/index.ts b/packages/types/src/interfaces/identity/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/identity/index.ts +++ b/packages/types/src/interfaces/identity/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/identity/types.ts b/packages/types/src/interfaces/identity/types.ts index a95c81d430..34f4000d7a 100644 --- a/packages/types/src/interfaces/identity/types.ts +++ b/packages/types/src/interfaces/identity/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Option, Set, Struct, Vec } from '@polkadot/types/codec'; @@ -65,3 +65,5 @@ export interface Registration extends Struct { /** @name RegistrationJudgement */ export interface RegistrationJudgement extends ITuple<[RegistrarIndex, IdentityJudgement]> {} + +export type PHANTOM_IDENTITY = 'identity'; diff --git a/packages/types/src/interfaces/imOnline/definitions.ts b/packages/types/src/interfaces/imOnline/definitions.ts index 92edb47014..1fcaac788e 100644 --- a/packages/types/src/interfaces/imOnline/definitions.ts +++ b/packages/types/src/interfaces/imOnline/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AuthIndex: 'u32', AuthoritySignature: 'Signature', @@ -19,4 +22,4 @@ export default { externalAddresses: 'Vec' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/imOnline/index.ts b/packages/types/src/interfaces/imOnline/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/imOnline/index.ts +++ b/packages/types/src/interfaces/imOnline/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/imOnline/types.ts b/packages/types/src/interfaces/imOnline/types.ts index ff646471b4..518707d1c2 100644 --- a/packages/types/src/interfaces/imOnline/types.ts +++ b/packages/types/src/interfaces/imOnline/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { Bytes, u32 } from '@polkadot/types/primitive'; @@ -32,3 +32,5 @@ export interface OpaqueNetworkState extends Struct { /** @name OpaquePeerId */ export interface OpaquePeerId extends Bytes {} + +export type PHANTOM_IMONLINE = 'imOnline'; diff --git a/packages/types/src/interfaces/index.ts b/packages/types/src/interfaces/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/index.ts +++ b/packages/types/src/interfaces/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/jsonrpc.ts b/packages/types/src/interfaces/jsonrpc.ts new file mode 100644 index 0000000000..70290bcbb1 --- /dev/null +++ b/packages/types/src/interfaces/jsonrpc.ts @@ -0,0 +1,26 @@ +// 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 { DefinitionRpcExt, DefinitionRpcSub } from '../types'; + +import * as definitions from './definitions'; + +const jsonrpc: Record> = {}; + +Object + .keys(definitions) + .filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0) + .forEach((section): void => { + jsonrpc[section] = {}; + + Object + .entries(definitions[section as 'babe'].rpc) + .forEach(([method, def]): void => { + const isSubscription = !!(def as DefinitionRpcSub).pubsub; + + jsonrpc[section][method] = ({ ...def, isSubscription, jsonrpc: `${section}_${method}`, method, section }); + }); + }); + +export default jsonrpc; diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index e6adea2fa4..5c4d126ed1 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -2,7 +2,23 @@ // 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'; + +const AllHashers = { + Blake2_128: null, // eslint-disable-line @typescript-eslint/camelcase + Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase + Blake2_128Concat: null, // eslint-disable-line @typescript-eslint/camelcase + Twox128: null, + Twox256: null, + Twox64Concat: null, + // new in v11 + Identity: null +}; + +export { AllHashers }; + export default { + rpc: {}, types: { // v0 CallMetadataV0: { @@ -486,16 +502,7 @@ export default { items: 'Vec' }, StorageHasherV11: { - _enum: { - Blake2_128: null, // eslint-disable-line @typescript-eslint/camelcase - Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase - Blake2_128Concat: null, // eslint-disable-line @typescript-eslint/camelcase - Twox128: null, - Twox256: null, - Twox64Concat: null, - // new in v11 - Identity: null - } + _enum: AllHashers }, // This always maps to the latest @@ -533,4 +540,4 @@ export default { } } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/metadata/index.ts b/packages/types/src/interfaces/metadata/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/metadata/index.ts +++ b/packages/types/src/interfaces/metadata/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index 194e04fdf0..d2c6f805d7 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Option, Struct, Vec } from '@polkadot/types/codec'; @@ -865,3 +865,5 @@ export interface StorageMetadataV8 extends StorageMetadataV7 {} /** @name StorageMetadataV9 */ export interface StorageMetadataV9 extends StorageMetadataV8 {} + +export type PHANTOM_METADATA = 'metadata'; diff --git a/packages/types/src/interfaces/offences/definitions.ts b/packages/types/src/interfaces/offences/definitions.ts index 77d350a1c2..243d8ec514 100644 --- a/packages/types/src/interfaces/offences/definitions.ts +++ b/packages/types/src/interfaces/offences/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { Kind: '[u8; 16]', OffenceDetails: { @@ -14,4 +17,4 @@ export default { ReportIdOf: 'Hash', Reporter: 'AccountId' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/offences/index.ts b/packages/types/src/interfaces/offences/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/offences/index.ts +++ b/packages/types/src/interfaces/offences/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/offences/types.ts b/packages/types/src/interfaces/offences/types.ts index ddc05f4a34..ec09fcd276 100644 --- a/packages/types/src/interfaces/offences/types.ts +++ b/packages/types/src/interfaces/offences/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, U8aFixed, Vec } from '@polkadot/types/codec'; import { Bytes } from '@polkadot/types/primitive'; @@ -26,3 +26,5 @@ export interface Reporter extends AccountId {} /** @name ReportIdOf */ export interface ReportIdOf extends Hash {} + +export type PHANTOM_OFFENCES = 'offences'; diff --git a/packages/types/src/interfaces/parachains/definitions.ts b/packages/types/src/interfaces/parachains/definitions.ts index e817f8fa35..574b8c9231 100644 --- a/packages/types/src/interfaces/parachains/definitions.ts +++ b/packages/types/src/interfaces/parachains/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AttestedCandidate: { candidate: 'CandidateReceipt', @@ -100,4 +103,4 @@ export default { WinningDataEntry: '(AccountId, ParaIdOf, BalanceOf)', WinningData: '[WinningDataEntry; 10]' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/parachains/index.ts b/packages/types/src/interfaces/parachains/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/parachains/index.ts +++ b/packages/types/src/interfaces/parachains/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/parachains/types.ts b/packages/types/src/interfaces/parachains/types.ts index ee530f7182..f2c6ea213d 100644 --- a/packages/types/src/interfaces/parachains/types.ts +++ b/packages/types/src/interfaces/parachains/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Struct, Vec } from '@polkadot/types/codec'; @@ -151,3 +151,5 @@ export interface WinningData extends Vec {} /** @name WinningDataEntry */ export interface WinningDataEntry extends ITuple<[AccountId, ParaIdOf, BalanceOf]> {} + +export type PHANTOM_PARACHAINS = 'parachains'; diff --git a/packages/types/src/interfaces/payment/definitions.ts b/packages/types/src/interfaces/payment/definitions.ts new file mode 100644 index 0000000000..c5a617bd61 --- /dev/null +++ b/packages/types/src/interfaces/payment/definitions.ts @@ -0,0 +1,26 @@ +// 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: { + queryInfo: { + description: 'Retrieves the fee information for an encoded extrinsic', + params: [ + { + name: 'extrinsic', + type: 'Bytes' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'RuntimeDispatchInfo' + } + }, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/payment/index.ts b/packages/types/src/interfaces/payment/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/payment/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/payment/types.ts b/packages/types/src/interfaces/payment/types.ts new file mode 100644 index 0000000000..373aa1958f --- /dev/null +++ b/packages/types/src/interfaces/payment/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_PAYMENT = 'payment'; diff --git a/packages/types/src/interfaces/recovery/definitions.ts b/packages/types/src/interfaces/recovery/definitions.ts index ab7ce461a4..ea22692ec0 100644 --- a/packages/types/src/interfaces/recovery/definitions.ts +++ b/packages/types/src/interfaces/recovery/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { ActiveRecovery: { created: 'BlockNumber', @@ -16,4 +19,4 @@ export default { threshold: 'u16' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/recovery/index.ts b/packages/types/src/interfaces/recovery/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/recovery/index.ts +++ b/packages/types/src/interfaces/recovery/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/recovery/types.ts b/packages/types/src/interfaces/recovery/types.ts index df601f26b9..cdf58f0fb6 100644 --- a/packages/types/src/interfaces/recovery/types.ts +++ b/packages/types/src/interfaces/recovery/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { u16 } from '@polkadot/types/primitive'; @@ -19,3 +19,5 @@ export interface RecoveryConfig extends Struct { readonly friends: Vec; readonly threshold: u16; } + +export type PHANTOM_RECOVERY = 'recovery'; diff --git a/packages/types/src/interfaces/rpc/definitions.ts b/packages/types/src/interfaces/rpc/definitions.ts index d443602a26..00ab3f309a 100644 --- a/packages/types/src/interfaces/rpc/definitions.ts +++ b/packages/types/src/interfaces/rpc/definitions.ts @@ -2,7 +2,16 @@ // 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: { + methods: { + description: 'Retrieves the list of RPC methods that are exposed by the node', + params: [], + type: 'RpcMethods' + } + }, types: { ApiId: '[u8; 8]', BlockHash: 'Hash', @@ -113,4 +122,4 @@ export default { changes: 'Vec' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/rpc/index.ts b/packages/types/src/interfaces/rpc/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/rpc/index.ts +++ b/packages/types/src/interfaces/rpc/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/rpc/types.ts b/packages/types/src/interfaces/rpc/types.ts index efe0cf524d..91be8114dd 100644 --- a/packages/types/src/interfaces/rpc/types.ts +++ b/packages/types/src/interfaces/rpc/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, HashMap, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec'; @@ -155,3 +155,5 @@ export interface StorageChangeSet extends Struct { readonly block: Hash; readonly changes: Vec; } + +export type PHANTOM_RPC = 'rpc'; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index 4b5bf07a10..7853add145 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { AccountId: 'GenericAccountId', AccountIdOf: 'AccountId', @@ -85,4 +88,4 @@ export default { Seal: '(ConsensusEngineId, Bytes)', Consensus: '(ConsensusEngineId, Bytes)' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/runtime/index.ts b/packages/types/src/interfaces/runtime/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/runtime/index.ts +++ b/packages/types/src/interfaces/runtime/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 4fe9693aaf..c699a0f087 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Compact, Enum, Int, Struct, U8aFixed, Vec } from '@polkadot/types/codec'; @@ -185,3 +185,5 @@ export interface Weight extends u32 {} /** @name WeightMultiplier */ export interface WeightMultiplier extends Fixed64 {} + +export type PHANTOM_RUNTIME = 'runtime'; diff --git a/packages/types/src/interfaces/session/definitions.ts b/packages/types/src/interfaces/session/definitions.ts index b26547b6ce..b0b50211d0 100644 --- a/packages/types/src/interfaces/session/definitions.ts +++ b/packages/types/src/interfaces/session/definitions.ts @@ -2,6 +2,8 @@ // 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'; + // The runtime definition of SessionKeys are passed as a Trait to session // Defined in `node/runtime/src/lib.rs` as follow // impl_opaque_keys! { @@ -24,10 +26,11 @@ const keyTypes = { }; export default { + rpc: {}, types: { ...keyTypes, FullIdentification: 'Exposure', IdentificationTuple: '(ValidatorId, FullIdentification)', SessionIndex: 'u32' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/session/index.ts b/packages/types/src/interfaces/session/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/session/index.ts +++ b/packages/types/src/interfaces/session/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/session/types.ts b/packages/types/src/interfaces/session/types.ts index 2469155def..07a5622ff6 100644 --- a/packages/types/src/interfaces/session/types.ts +++ b/packages/types/src/interfaces/session/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { u32 } from '@polkadot/types/primitive'; @@ -35,3 +35,5 @@ export interface SessionKeys5 extends ITuple<[AccountId, AccountId, AccountId, A /** @name SessionKeys6 */ export interface SessionKeys6 extends ITuple<[AccountId, AccountId, AccountId, AccountId, AccountId, AccountId]> {} + +export type PHANTOM_SESSION = 'session'; diff --git a/packages/types/src/interfaces/society/definitions.ts b/packages/types/src/interfaces/society/definitions.ts index e59b464c28..2ec1800013 100644 --- a/packages/types/src/interfaces/society/definitions.ts +++ b/packages/types/src/interfaces/society/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { Bid: { who: 'AccountId', @@ -28,4 +31,4 @@ export default { _enum: ['Vouching', 'Banned'] } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/society/index.ts b/packages/types/src/interfaces/society/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/society/index.ts +++ b/packages/types/src/interfaces/society/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/society/types.ts b/packages/types/src/interfaces/society/types.ts index 30bad2b01e..2ecbb48427 100644 --- a/packages/types/src/interfaces/society/types.ts +++ b/packages/types/src/interfaces/society/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Enum, Struct } from '@polkadot/types/codec'; @@ -43,3 +43,5 @@ export interface VouchingStatus extends Enum { readonly isVouching: boolean; readonly isBanned: boolean; } + +export type PHANTOM_SOCIETY = 'society'; diff --git a/packages/types/src/interfaces/staking/definitions.ts b/packages/types/src/interfaces/staking/definitions.ts index bb8ce62781..eaa2fe8f55 100644 --- a/packages/types/src/interfaces/staking/definitions.ts +++ b/packages/types/src/interfaces/staking/definitions.ts @@ -2,6 +2,8 @@ // 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'; + const deprecated = { Points: 'u32', EraPoints: { @@ -11,6 +13,7 @@ const deprecated = { }; export default { + rpc: {}, types: { ...deprecated, ActiveEraInfo: { @@ -156,4 +159,4 @@ export default { validatorPayment: 'Compact' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/staking/index.ts b/packages/types/src/interfaces/staking/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/staking/index.ts +++ b/packages/types/src/interfaces/staking/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/staking/types.ts b/packages/types/src/interfaces/staking/types.ts index a50b6c769f..6ff8f792b8 100644 --- a/packages/types/src/interfaces/staking/types.ts +++ b/packages/types/src/interfaces/staking/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { BTreeMap, Compact, Enum, Option, Struct, Vec } from '@polkadot/types/codec'; @@ -218,3 +218,5 @@ export interface ValidatorPrefsTo145 extends Struct { export interface ValidatorPrefsTo196 extends Struct { readonly validatorPayment: Compact; } + +export type PHANTOM_STAKING = 'staking'; diff --git a/packages/types/src/interfaces/state/definitions.ts b/packages/types/src/interfaces/state/definitions.ts new file mode 100644 index 0000000000..7c154a7099 --- /dev/null +++ b/packages/types/src/interfaces/state/definitions.ts @@ -0,0 +1,295 @@ +// 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: { + call: { + alias: ['state_callAt'], + description: 'Perform a call to a builtin on the chain', + params: [ + { + name: 'method', + type: 'Text' + }, + { + name: 'data', + type: 'Bytes' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Bytes' + }, + getKeys: { + description: 'Retrieves the keys with a certain prefix', + params: [ + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Vec' + }, + getKeysPaged: { + alias: ['state_getKeysPagedAt'], + description: 'Returns the keys with prefix with pagination support.', + params: [ + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'count', + type: 'u32' + }, + { + name: 'startKey', + type: 'StorageKey', + isOptional: true + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Vec' + }, + getStorage: { + alias: ['state_getStorageAt'], + description: 'Retrieves the storage for a key', + params: [ + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'StorageData' + }, + getStorageHash: { + alias: ['state_getStorageHashAt'], + description: 'Retrieves the storage hash', + params: [ + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Hash' + }, + getStorageSize: { + alias: ['state_getStorageSizeAt'], + description: 'Retrieves the storage size', + params: [ + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'u64' + }, + getChildKeys: { + description: 'Retrieves the keys with prefix of a specific child storage', + params: [ + { + name: 'childStorageKey', + type: 'StorageKey' + }, + { + name: 'childDefinition', + type: 'StorageKey' + }, + { + name: 'childType', + type: 'u32' + }, + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Vec' + }, + getChildStorage: { + description: 'Retrieves the child storage for a key', + params: [ + { + name: 'childStorageKey', + type: 'StorageKey' + }, + { + name: 'childDefinition', + type: 'StorageKey' + }, + { + name: 'childType', + type: 'u32' + }, + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'StorageData' + }, + getChildStorageHash: { + description: 'Retrieves the child storage hash', + params: [ + { + name: 'childStorageKey', + type: 'StorageKey' + }, + { + name: 'childDefinition', + type: 'StorageKey' + }, + { + name: 'childType', + type: 'u32' + }, + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Hash' + }, + getChildStorageSize: { + description: 'Retrieves the child storage size', + params: [ + { + name: 'childStorageKey', + type: 'StorageKey' + }, + { + name: 'childDefinition', + type: 'StorageKey' + }, + { + name: 'childType', + type: 'u32' + }, + { + name: 'key', + type: 'StorageKey' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'u64' + }, + getMetadata: { + description: 'Returns the runtime metadata', + params: [ + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Metadata' + }, + getRuntimeVersion: { + alias: ['chain_getRuntimeVersion'], + description: 'Get the runtime version', + params: [ + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'RuntimeVersion' + }, + queryStorage: { + description: 'Query historical storage entries (by key) starting from a start block', + params: [ + { + name: 'keys', + type: 'Vec' + }, + { + name: 'startBlock', + type: 'Hash' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Vec' + }, + subscribeRuntimeVersion: { + alias: ['chain_subscribeRuntimeVersion', 'chain_unsubscribeRuntimeVersion'], + description: 'Retrieves the runtime version via subscription', + params: [], + pubsub: [ + 'runtimeVersion', + 'subscribeRuntimeVersion', + 'unsubscribeRuntimeVersion' + ], + type: 'RuntimeVersion' + }, + subscribeStorage: { + description: 'Subscribes to storage changes for the provided keys', + params: [ + { + name: 'keys', + type: 'Vec' + } + ], + pubsub: [ + 'storage', + 'subscribeStorage', + 'unsubscribeStorage' + ], + type: 'StorageChangeSet' + } + }, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/state/index.ts b/packages/types/src/interfaces/state/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/state/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/state/types.ts b/packages/types/src/interfaces/state/types.ts new file mode 100644 index 0000000000..cf2749b362 --- /dev/null +++ b/packages/types/src/interfaces/state/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_STATE = 'state'; diff --git a/packages/types/src/interfaces/system/definitions.ts b/packages/types/src/interfaces/system/definitions.ts index 103c7bd81b..328920e142 100644 --- a/packages/types/src/interfaces/system/definitions.ts +++ b/packages/types/src/interfaces/system/definitions.ts @@ -2,7 +2,46 @@ // 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: { + name: { + description: 'Retrieves the node name', + params: [], + type: 'Text' + }, + version: { + description: 'Retrieves the version of the node', + params: [], + type: 'Text' + }, + chain: { + description: 'Retrieves the chain', + params: [], + type: 'Text' + }, + properties: { + description: 'Get a custom set of properties as a JSON object, defined in the chain spec', + params: [], + type: 'ChainProperties' + }, + health: { + description: 'Return health status of the node', + params: [], + type: 'Health' + }, + peers: { + description: 'Returns the currently connected peers', + params: [], + type: 'Vec' + }, + networkState: { + description: 'Returns current state of the network', + params: [], + type: 'NetworkState' + } + }, types: { AccountInfo: { nonce: 'Index', @@ -55,4 +94,4 @@ export default { }, RefCount: 'u8' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/system/index.ts b/packages/types/src/interfaces/system/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/system/index.ts +++ b/packages/types/src/interfaces/system/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/system/types.ts b/packages/types/src/interfaces/system/types.ts index a60e67a373..03cb033f78 100644 --- a/packages/types/src/interfaces/system/types.ts +++ b/packages/types/src/interfaces/system/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Compact, Enum, Option, Result, Struct, U8aFixed, Vec } from '@polkadot/types/codec'; @@ -99,3 +99,5 @@ export interface Phase extends Enum { /** @name RefCount */ export interface RefCount extends u8 {} + +export type PHANTOM_SYSTEM = 'system'; diff --git a/packages/types/src/interfaces/treasury/definitions.ts b/packages/types/src/interfaces/treasury/definitions.ts index bd1fbc2afb..5562aac8e8 100644 --- a/packages/types/src/interfaces/treasury/definitions.ts +++ b/packages/types/src/interfaces/treasury/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { OpenTipFinder: '(AccountId, Balance)', OpenTipTip: '(AccountId, Balance)', @@ -20,4 +23,4 @@ export default { bond: 'Balance' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/treasury/index.ts b/packages/types/src/interfaces/treasury/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/treasury/index.ts +++ b/packages/types/src/interfaces/treasury/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/treasury/types.ts b/packages/types/src/interfaces/treasury/types.ts index da6eba805f..bee7ba1be3 100644 --- a/packages/types/src/interfaces/treasury/types.ts +++ b/packages/types/src/interfaces/treasury/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { ITuple } from '@polkadot/types/types'; import { Option, Struct, Vec } from '@polkadot/types/codec'; @@ -27,3 +27,5 @@ export interface TreasuryProposal extends Struct { readonly beneficiary: AccountId; readonly bond: Balance; } + +export type PHANTOM_TREASURY = 'treasury'; diff --git a/packages/types/src/interfaces/txpayment/definitions.ts b/packages/types/src/interfaces/txpayment/definitions.ts index 6eea9bee9a..e6030e4cf4 100644 --- a/packages/types/src/interfaces/txpayment/definitions.ts +++ b/packages/types/src/interfaces/txpayment/definitions.ts @@ -2,8 +2,11 @@ // 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: {}, types: { Multiplier: 'Fixed64' } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/txpayment/index.ts b/packages/types/src/interfaces/txpayment/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/txpayment/index.ts +++ b/packages/types/src/interfaces/txpayment/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/txpayment/types.ts b/packages/types/src/interfaces/txpayment/types.ts index 4feea636dd..05259fdd80 100644 --- a/packages/types/src/interfaces/txpayment/types.ts +++ b/packages/types/src/interfaces/txpayment/types.ts @@ -1,7 +1,9 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Fixed64 } from '@polkadot/types/interfaces/runtime'; /** @name Multiplier */ export interface Multiplier extends Fixed64 {} + +export type PHANTOM_TXPAYMENT = 'txpayment'; diff --git a/packages/types/src/interfaces/types.ts b/packages/types/src/interfaces/types.ts index de8962933c..b7fc3c2e61 100644 --- a/packages/types/src/interfaces/types.ts +++ b/packages/types/src/interfaces/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './runtime/types'; export * from './authorship/types'; @@ -33,3 +33,8 @@ export * from './claims/types'; export * from './parachains/types'; export * from './metadata/types'; export * from './rpc/types'; +export * from './account/types'; +export * from './author/types'; +export * from './chain/types'; +export * from './payment/types'; +export * from './state/types'; diff --git a/packages/types/src/interfaces/utility/definitions.ts b/packages/types/src/interfaces/utility/definitions.ts index 1f65cb0744..4f305ea3cc 100644 --- a/packages/types/src/interfaces/utility/definitions.ts +++ b/packages/types/src/interfaces/utility/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { Timepoint: { height: 'BlockNumber', @@ -15,4 +18,4 @@ export default { approvals: 'Vec' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/utility/index.ts b/packages/types/src/interfaces/utility/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/utility/index.ts +++ b/packages/types/src/interfaces/utility/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/utility/types.ts b/packages/types/src/interfaces/utility/types.ts index 585f0f5ed4..f46ed57306 100644 --- a/packages/types/src/interfaces/utility/types.ts +++ b/packages/types/src/interfaces/utility/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct, Vec } from '@polkadot/types/codec'; import { u32 } from '@polkadot/types/primitive'; @@ -18,3 +18,5 @@ export interface Timepoint extends Struct { readonly height: BlockNumber; readonly index: u32; } + +export type PHANTOM_UTILITY = 'utility'; diff --git a/packages/types/src/interfaces/vesting/definitions.ts b/packages/types/src/interfaces/vesting/definitions.ts index b85231fd1b..2c93dd87ce 100644 --- a/packages/types/src/interfaces/vesting/definitions.ts +++ b/packages/types/src/interfaces/vesting/definitions.ts @@ -2,7 +2,10 @@ // 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: {}, types: { VestingInfo: { locked: 'Balance', @@ -10,4 +13,4 @@ export default { startingBlock: 'BlockNumber' } } -}; +} as Definitions; diff --git a/packages/types/src/interfaces/vesting/index.ts b/packages/types/src/interfaces/vesting/index.ts index 25784af928..2d307291c3 100644 --- a/packages/types/src/interfaces/vesting/index.ts +++ b/packages/types/src/interfaces/vesting/index.ts @@ -1,4 +1,4 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ export * from './types'; diff --git a/packages/types/src/interfaces/vesting/types.ts b/packages/types/src/interfaces/vesting/types.ts index 9bbd11ff26..ad3a1934fa 100644 --- a/packages/types/src/interfaces/vesting/types.ts +++ b/packages/types/src/interfaces/vesting/types.ts @@ -1,5 +1,5 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit -/* eslint-disable @typescript-eslint/no-empty-interface */ +/* eslint-disable */ import { Struct } from '@polkadot/types/codec'; import { Balance, BlockNumber } from '@polkadot/types/interfaces/runtime'; @@ -10,3 +10,5 @@ export interface VestingInfo extends Struct { readonly perBlock: Balance; readonly startingBlock: BlockNumber; } + +export type PHANTOM_VESTING = 'vesting'; diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index c67e635d0d..f3012c389e 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -7,7 +7,7 @@ import { AnyU8a, Codec, InterfaceTypes, Registry } from '../types'; import { assert, isFunction, isString, isU8a } from '@polkadot/util'; -import metadataDefs from '../interfaces/metadata/definitions'; +import { AllHashers } from '@polkadot/types/interfaces/metadata/definitions'; import Bytes from './Bytes'; export interface StorageEntry { @@ -32,7 +32,7 @@ interface StorageKeyExtra { section: string; } -const HASHER_MAP: Record = { +const HASHER_MAP: Record = { // opaque Blake2_128: [16, false], // eslint-disable-line @typescript-eslint/camelcase Blake2_256: [32, false], // eslint-disable-line @typescript-eslint/camelcase diff --git a/packages/types/src/types/definitions.ts b/packages/types/src/types/definitions.ts new file mode 100644 index 0000000000..ed9056796f --- /dev/null +++ b/packages/types/src/types/definitions.ts @@ -0,0 +1,44 @@ +// 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. + +export type DefinitionTypeType = string; + +export type DefinitionTypeEnum = { _enum: DefinitionTypeType[] } | { _enum: Record }; + +export type DefinitionTypeSet = { _set: Record }; + +// Don't believe the `& object` here is proper, but cannot do `& Record` +export type DefinitionTypeStruct = Record | { _alias?: Record } & object; + +export type DefinitionType = string | DefinitionTypeEnum | DefinitionTypeSet | DefinitionTypeStruct; + +export interface DefinitionRpcParam { + isOptional?: boolean; + name: string; + type: DefinitionTypeType; +} + +export interface DefinitionRpc { + alias?: string[]; + description: string; + params: DefinitionRpcParam[]; + type: DefinitionTypeType; +} + +export interface DefinitionRpcExt extends DefinitionRpc { + isSubscription: boolean; + jsonrpc: string; + method: string; + pubsub?: [string, string, string]; + section: string; +} + +export interface DefinitionRpcSub extends DefinitionRpc { + pubsub: [string, string, string]; +} + +export interface Definitions { + rpc: Record; + types: Record; +} diff --git a/packages/types/src/types/index.ts b/packages/types/src/types/index.ts index 815c9e5a18..15905130ea 100644 --- a/packages/types/src/types/index.ts +++ b/packages/types/src/types/index.ts @@ -8,6 +8,7 @@ import '@polkadot/types/augment'; export * from '../create/types'; export * from './calls'; export * from './codec'; +export * from './definitions'; export * from './extrinsic'; export * from './helpers'; export * from './interfaces'; diff --git a/tsconfig.json b/tsconfig.json index afdf1b2f41..545b2abcb2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,8 +15,6 @@ "@polkadot/api-contract/*": ["packages/api-contract/src/*"], "@polkadot/api-derive": ["packages/api-derive/src"], "@polkadot/api-derive/*": ["packages/api-derive/src/*"], - "@polkadot/jsonrpc": ["packages/jsonrpc/src"], - "@polkadot/jsonrpc/*": ["packages/jsonrpc/src/*"], "@polkadot/metadata": ["packages/metadata/src"], "@polkadot/metadata/*": ["packages/metadata/src/*"], "@polkadot/rpc-core": ["packages/rpc-core/src"], diff --git a/yarn.lock b/yarn.lock index d6f6e010f8..c31c10d4f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2668,16 +2668,6 @@ __metadata: languageName: node linkType: hard -"@polkadot/jsonrpc@1.8.0-beta.2, @polkadot/jsonrpc@workspace:packages/jsonrpc": - version: 0.0.0-use.local - resolution: "@polkadot/jsonrpc@workspace:packages/jsonrpc" - dependencies: - "@babel/runtime": ^7.8.7 - "@polkadot/types": 1.8.0-beta.2 - "@polkadot/util": ^2.6.2 - languageName: unknown - linkType: soft - "@polkadot/keyring@npm:^2.6.2": version: 2.6.2 resolution: "@polkadot/keyring@npm:2.6.2" @@ -2707,7 +2697,6 @@ __metadata: resolution: "@polkadot/rpc-core@workspace:packages/rpc-core" dependencies: "@babel/runtime": ^7.8.7 - "@polkadot/jsonrpc": 1.8.0-beta.2 "@polkadot/keyring": ^2.6.2 "@polkadot/metadata": 1.8.0-beta.2 "@polkadot/rpc-provider": 1.8.0-beta.2 @@ -2723,7 +2712,6 @@ __metadata: resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider" dependencies: "@babel/runtime": ^7.8.7 - "@polkadot/jsonrpc": 1.8.0-beta.2 "@polkadot/keyring": ^2.6.2 "@polkadot/metadata": 1.8.0-beta.2 "@polkadot/types": 1.8.0-beta.2 @@ -2755,7 +2743,6 @@ __metadata: "@babel/register": ^7.8.6 "@babel/runtime": ^7.8.7 "@polkadot/api": 1.8.0-beta.2 - "@polkadot/jsonrpc": 1.8.0-beta.2 "@polkadot/metadata": 1.8.0-beta.2 "@polkadot/rpc-provider": 1.8.0-beta.2 "@polkadot/types": 1.8.0-beta.2