From abdbd372155f4cae33fd7a86a6e1537e71fcde55 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 30 Jun 2022 09:23:00 +0200 Subject: [PATCH] Add runtime decoration defaults (#4993) * Add runtime decoration defaults * Default exports * Additional * hash + version --- packages/api-augment/src/kusama/index.ts | 1 + packages/api-augment/src/kusama/runtime.ts | 41 +++++++++ packages/api-augment/src/polkadot/index.ts | 1 + packages/api-augment/src/polkadot/runtime.ts | 41 +++++++++ packages/api-augment/src/substrate/index.ts | 1 + packages/api-augment/src/substrate/runtime.ts | 30 +++++++ packages/api-base/src/types/calls.ts | 3 +- packages/api/src/base/Decorate.ts | 85 ++++++++++++++----- packages/typegen/src/fromChain.ts | 2 +- packages/typegen/src/generate/runtime.ts | 18 ++-- packages/typegen/src/templates/calls.hbs | 1 + .../types-augment/src/registry/interfaces.ts | 3 +- packages/types/src/interfaces/aura/runtime.ts | 3 +- packages/types/src/interfaces/babe/runtime.ts | 2 +- .../types/src/interfaces/beefy/definitions.ts | 6 +- .../types/src/interfaces/beefy/runtime.ts | 15 +++- packages/types/src/interfaces/beefy/types.ts | 7 ++ .../types/src/interfaces/contracts/runtime.ts | 3 +- packages/types/src/interfaces/definitions.ts | 2 + .../src/interfaces/discovery/definitions.ts | 15 ++++ .../types/src/interfaces/discovery/index.ts | 4 + .../types/src/interfaces/discovery/runtime.ts | 19 +++++ .../types/src/interfaces/discovery/types.ts | 4 + .../src/interfaces/finality/definitions.ts | 15 ++++ .../types/src/interfaces/finality/index.ts | 4 + .../types/src/interfaces/finality/runtime.ts | 23 +++++ .../types/src/interfaces/finality/types.ts | 4 + .../types/src/interfaces/grandpa/runtime.ts | 1 + .../types/src/interfaces/metadata/runtime.ts | 3 +- .../types/src/interfaces/payment/runtime.ts | 3 +- .../src/interfaces/runtime/definitions.ts | 3 + .../types/src/interfaces/runtime/runtime.ts | 20 +++++ .../types/src/interfaces/session/runtime.ts | 3 +- .../types/src/interfaces/system/runtime.ts | 3 +- packages/types/src/interfaces/types.ts | 2 + packages/types/src/types/definitions.ts | 2 +- 36 files changed, 352 insertions(+), 41 deletions(-) create mode 100644 packages/types/src/interfaces/discovery/definitions.ts create mode 100644 packages/types/src/interfaces/discovery/index.ts create mode 100644 packages/types/src/interfaces/discovery/runtime.ts create mode 100644 packages/types/src/interfaces/discovery/types.ts create mode 100644 packages/types/src/interfaces/finality/definitions.ts create mode 100644 packages/types/src/interfaces/finality/index.ts create mode 100644 packages/types/src/interfaces/finality/runtime.ts create mode 100644 packages/types/src/interfaces/finality/types.ts create mode 100644 packages/types/src/interfaces/runtime/runtime.ts diff --git a/packages/api-augment/src/kusama/index.ts b/packages/api-augment/src/kusama/index.ts index ab66a055ae..2de83d1b80 100644 --- a/packages/api-augment/src/kusama/index.ts +++ b/packages/api-augment/src/kusama/index.ts @@ -7,4 +7,5 @@ import './errors'; import './events'; import './query'; import './registry'; +import './runtime'; import './tx'; diff --git a/packages/api-augment/src/kusama/runtime.ts b/packages/api-augment/src/kusama/runtime.ts index edf2c82158..545df3d744 100644 --- a/packages/api-augment/src/kusama/runtime.ts +++ b/packages/api-augment/src/kusama/runtime.ts @@ -5,15 +5,18 @@ import type { ApiTypes } from '@polkadot/api-base/types'; import type { Bytes, Option, Vec, u32 } from '@polkadot/types-codec'; import type { AnyNumber, ITuple } from '@polkadot/types-codec/types'; import type { BabeGenesisConfiguration, Epoch, OpaqueKeyOwnershipProof } from '@polkadot/types/interfaces/babe'; +import type { ValidatorSet } from '@polkadot/types/interfaces/beefy'; import type { AuthorityId } from '@polkadot/types/interfaces/consensus'; import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; import type { AccountId, Index, KeyTypeId, Slot } from '@polkadot/types/interfaces/runtime'; +import type { RuntimeVersion } from '@polkadot/types/interfaces/state'; import type { Observable } from '@polkadot/types/types'; declare module '@polkadot/api-base/types/calls' { export interface AugmentedCalls { + /** 0xbc9d89904f5b923f/1 */ accountNonceApi: { /** * The API to query account nonce (aka transaction index) @@ -24,6 +27,18 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x687ad44ad37f03c2/1 */ + authorityDiscoveryApi: { + /** + * Retrieve authority identifiers of the current and next authority set. + **/ + authorities: AugmentedCall Observable>>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xcbca25e39f142387/2 */ babeApi: { /** * Return the genesis configuration for BABE. The configuration is only read on genesis. @@ -50,6 +65,29 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x49eaaf1b548a0cb0/1 */ + beefyApi: { + /** + * Return the current active BEEFY validator set + **/ + validatorSet: AugmentedCall Observable>>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xdf6acb689907609b/4 */ + core: { + /** + * Returns the version of the runtime. + **/ + version: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xed99c5acb25eedf5/3 */ grandpaApi: { /** * Get current GRANDPA authority set id. @@ -64,6 +102,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37e397fc7c91f5e4/1 */ metadata: { /** * Returns the metadata of a runtime @@ -74,6 +113,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0xab3c0572291feb8b/1 */ sessionKeys: { /** * Decode the given public session keys. @@ -88,6 +128,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37c8bb1350a9a2a8/1 */ transactionPaymentApi: { /** * The transaction fee details diff --git a/packages/api-augment/src/polkadot/index.ts b/packages/api-augment/src/polkadot/index.ts index ab66a055ae..2de83d1b80 100644 --- a/packages/api-augment/src/polkadot/index.ts +++ b/packages/api-augment/src/polkadot/index.ts @@ -7,4 +7,5 @@ import './errors'; import './events'; import './query'; import './registry'; +import './runtime'; import './tx'; diff --git a/packages/api-augment/src/polkadot/runtime.ts b/packages/api-augment/src/polkadot/runtime.ts index edf2c82158..545df3d744 100644 --- a/packages/api-augment/src/polkadot/runtime.ts +++ b/packages/api-augment/src/polkadot/runtime.ts @@ -5,15 +5,18 @@ import type { ApiTypes } from '@polkadot/api-base/types'; import type { Bytes, Option, Vec, u32 } from '@polkadot/types-codec'; import type { AnyNumber, ITuple } from '@polkadot/types-codec/types'; import type { BabeGenesisConfiguration, Epoch, OpaqueKeyOwnershipProof } from '@polkadot/types/interfaces/babe'; +import type { ValidatorSet } from '@polkadot/types/interfaces/beefy'; import type { AuthorityId } from '@polkadot/types/interfaces/consensus'; import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; import type { AccountId, Index, KeyTypeId, Slot } from '@polkadot/types/interfaces/runtime'; +import type { RuntimeVersion } from '@polkadot/types/interfaces/state'; import type { Observable } from '@polkadot/types/types'; declare module '@polkadot/api-base/types/calls' { export interface AugmentedCalls { + /** 0xbc9d89904f5b923f/1 */ accountNonceApi: { /** * The API to query account nonce (aka transaction index) @@ -24,6 +27,18 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x687ad44ad37f03c2/1 */ + authorityDiscoveryApi: { + /** + * Retrieve authority identifiers of the current and next authority set. + **/ + authorities: AugmentedCall Observable>>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xcbca25e39f142387/2 */ babeApi: { /** * Return the genesis configuration for BABE. The configuration is only read on genesis. @@ -50,6 +65,29 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x49eaaf1b548a0cb0/1 */ + beefyApi: { + /** + * Return the current active BEEFY validator set + **/ + validatorSet: AugmentedCall Observable>>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xdf6acb689907609b/4 */ + core: { + /** + * Returns the version of the runtime. + **/ + version: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xed99c5acb25eedf5/3 */ grandpaApi: { /** * Get current GRANDPA authority set id. @@ -64,6 +102,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37e397fc7c91f5e4/1 */ metadata: { /** * Returns the metadata of a runtime @@ -74,6 +113,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0xab3c0572291feb8b/1 */ sessionKeys: { /** * Decode the given public session keys. @@ -88,6 +128,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37c8bb1350a9a2a8/1 */ transactionPaymentApi: { /** * The transaction fee details diff --git a/packages/api-augment/src/substrate/index.ts b/packages/api-augment/src/substrate/index.ts index ab66a055ae..2de83d1b80 100644 --- a/packages/api-augment/src/substrate/index.ts +++ b/packages/api-augment/src/substrate/index.ts @@ -7,4 +7,5 @@ import './errors'; import './events'; import './query'; import './registry'; +import './runtime'; import './tx'; diff --git a/packages/api-augment/src/substrate/runtime.ts b/packages/api-augment/src/substrate/runtime.ts index 4fedc4dbc8..c5e18aa3fc 100644 --- a/packages/api-augment/src/substrate/runtime.ts +++ b/packages/api-augment/src/substrate/runtime.ts @@ -11,10 +11,12 @@ import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; import type { AccountId, Balance, Index, KeyTypeId, Slot } from '@polkadot/types/interfaces/runtime'; +import type { RuntimeVersion } from '@polkadot/types/interfaces/state'; import type { Observable } from '@polkadot/types/types'; declare module '@polkadot/api-base/types/calls' { export interface AugmentedCalls { + /** 0xbc9d89904f5b923f/1 */ accountNonceApi: { /** * The API to query account nonce (aka transaction index) @@ -25,6 +27,18 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x687ad44ad37f03c2/1 */ + authorityDiscoveryApi: { + /** + * Retrieve authority identifiers of the current and next authority set. + **/ + authorities: AugmentedCall Observable>>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xcbca25e39f142387/2 */ babeApi: { /** * Return the genesis configuration for BABE. The configuration is only read on genesis. @@ -51,6 +65,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x68b66ba122c93fa7/1 */ contractsApi: { /** * Perform a call from a specified account to a given contract. @@ -73,6 +88,18 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0xdf6acb689907609b/4 */ + core: { + /** + * Returns the version of the runtime. + **/ + version: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; + /** 0xed99c5acb25eedf5/3 */ grandpaApi: { /** * Get current GRANDPA authority set id. @@ -87,6 +114,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37e397fc7c91f5e4/1 */ metadata: { /** * Returns the metadata of a runtime @@ -97,6 +125,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0xab3c0572291feb8b/1 */ sessionKeys: { /** * Decode the given public session keys. @@ -111,6 +140,7 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + /** 0x37c8bb1350a9a2a8/1 */ transactionPaymentApi: { /** * The transaction fee details diff --git a/packages/api-base/src/types/calls.ts b/packages/api-base/src/types/calls.ts index b33871a129..cd379a54a1 100644 --- a/packages/api-base/src/types/calls.ts +++ b/packages/api-base/src/types/calls.ts @@ -3,6 +3,7 @@ import type { Observable } from 'rxjs'; import type { AnyFunction, Codec, DefinitionCall } from '@polkadot/types/types'; +import type { HexString } from '@polkadot/util/types'; import type { ApiTypes, ReturnCodec } from './base'; // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-interface @@ -32,6 +33,6 @@ export interface DefinitionCallNamed extends DefinitionCall { method: string; name: string; section: string; - sectionHash: Uint8Array; + sectionHash: HexString; version: number; } diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 8a15ae9626..b94cc3b06e 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -8,7 +8,8 @@ import type { Option, Raw, StorageKey, Text, u64 } from '@polkadot/types'; import type { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces'; import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types'; import type { StorageEntry } from '@polkadot/types/primitive/types'; -import type { AnyFunction, AnyTuple, CallFunction, Codec, DefinitionRpc, DefinitionRpcSub, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from '@polkadot/types/types'; +import type { AnyFunction, AnyTuple, CallFunction, Codec, DefinitionRpc, DefinitionRpcSub, Definitions, DefinitionsCall, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from '@polkadot/types/types'; +import type { HexString } from '@polkadot/util/types'; import type { SubmittableExtrinsic } from '../submittable/types'; import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, AugmentedQuery, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, GenericStorageEntryFunction, PaginationOptions, QueryableConsts, QueryableStorage, QueryableStorageEntry, QueryableStorageEntryAt, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics } from '../types'; import type { VersionedRegistry } from './types'; @@ -18,9 +19,9 @@ import { BehaviorSubject, combineLatest, from, map, of, switchMap, tap, toArray import { getAvailableDerives } from '@polkadot/api-derive'; import { memo, RpcCore } from '@polkadot/rpc-core'; import { WsProvider } from '@polkadot/rpc-provider'; -import { expandMetadata, Metadata, TypeRegistry, unwrapStorageType } from '@polkadot/types'; +import { expandMetadata, Metadata, typeDefinitions, TypeRegistry, unwrapStorageType } from '@polkadot/types'; import { arrayChunk, arrayFlatten, assert, assertReturn, BN, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, stringCamelCase, u8aConcatStrict, u8aToHex } from '@polkadot/util'; -import { blake2AsU8a } from '@polkadot/util-crypto'; +import { blake2AsHex } from '@polkadot/util-crypto'; import { createSubmittable } from '../submittable'; import { augmentObject } from '../util/augmentObject'; @@ -413,48 +414,88 @@ export abstract class Decorate extends Events { return out as DecoratedRpc; } + // extract all runtime definitions + protected _getRuntimeDefs (): DefinitionsCall { + const result = objectSpread({}, this._options.runtime); + const defValues = Object.values(typeDefinitions) as Definitions[]; + + for (let i = 0; i < defValues.length; i++) { + const rt = defValues[i].runtime; + + if (rt) { + const apiEntries = Object.entries(rt); + + for (let j = 0; j < apiEntries.length; j++) { + const [key, defs] = apiEntries[j]; + + if (!result[key]) { + // we don't have this runtime definition, add it + result[key] = defs; + } else { + for (let k = 0; k < defs.length; k++) { + const def = defs[k]; + + if (!result[key].some(({ version }) => def.version === version)) { + // we don't have this specific version, add it + result[key].push(def); + } + } + } + } + } + } + + return result; + } + // pre-metadata decoration protected _decorateCalls ({ registry, runtimeVersion: { apis } }: VersionedRegistry, decorateMethod: DecorateMethod, blockHash?: Uint8Array | string | null): QueryableCalls { const result = {} as QueryableCalls; - - if (!this._options.runtime) { - return result; - } - const named: Record> = {}; - const sections = Object.entries(this._options.runtime); + const sections = Object.entries(this._getRuntimeDefs()); + const hashes: HexString[] = []; for (let i = 0; i < sections.length; i++) { const [_section, secs] = sections[i]; - const sectionHash = blake2AsU8a(_section, 64); + const sectionHash = blake2AsHex(_section, 64); const rtApi = apis.find(([a]) => a.eq(sectionHash)); + hashes.push(sectionHash); + if (rtApi) { - const sec = secs.find(({ version = 1 }) => rtApi[1].eq(version)); + const sec = secs.find(({ version }) => rtApi[1].eq(version)); if (sec) { const section = stringCamelCase(_section); - - if (!named[section]) { - named[section] = {}; - } - const methods = Object.entries(sec.methods); - for (let m = 0; m < methods.length; m++) { - const [_method, def] = methods[m]; - const method = stringCamelCase(_method); + if (methods.length) { + if (!named[section]) { + named[section] = {}; + } - named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash, version: 1 }, def); + for (let m = 0; m < methods.length; m++) { + const [_method, def] = methods[m]; + const method = stringCamelCase(_method); + + named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash }, def); + } } } else { l.warn(`Not decorating runtime ${_section}, unable to find version ${rtApi[1].toString()}`); } - } else { - l.warn(`Not decorating runtime ${_section}, not found in available apis`); } } + // find the runtimes that we don't have hashes for + const notFound = apis + .filter(([a]) => !hashes.includes(a.toHex())) + .map(([a, v]) => `${a.toHex()}/${v.toString()}`); + + if (notFound.length) { + l.warn(`Not decorating runtime apis ${notFound.join(', ')}`); + } + const stateCall = blockHash ? (name: string, bytes: Uint8Array) => this._rpcCore.state.call(name, bytes, blockHash) : (name: string, bytes: Uint8Array) => this._rpcCore.state.call(name, bytes); diff --git a/packages/typegen/src/fromChain.ts b/packages/typegen/src/fromChain.ts index 4e5846cebf..781ada79b8 100644 --- a/packages/typegen/src/fromChain.ts +++ b/packages/typegen/src/fromChain.ts @@ -54,7 +54,7 @@ function generate (metaHex: HexString, version: Version | null, pkg: string | un [ HEADER('chain'), ...[ - ...['consts', 'errors', 'events', 'query', 'tx', 'rpc'] + ...['consts', 'errors', 'events', 'query', 'tx', 'rpc', 'runtime'] .filter((key) => !!key) .map((key) => `./augment-api-${key}`) ].map((path) => `import '${path}';\n`) diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 868230fe68..3def3c359f 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -33,11 +33,11 @@ function getDefs (apis: Apis | null, defs: Record): Record< for (let i = 0; i < sections.length; i++) { const [_section, sec] = sections[i]; - const apiHash = blake2AsHex(_section, 64); - const api = apis && apis.find(([h]) => h === apiHash); + const sectionHash = blake2AsHex(_section, 64); + const api = apis && apis.find(([h]) => h === sectionHash); if (api) { - const ver = sec.find(({ version = 1 }) => version === api[1]); + const ver = sec.find(({ version }) => version === api[1]); if (ver) { const methods = Object.entries(ver.methods); @@ -53,7 +53,7 @@ function getDefs (apis: Apis | null, defs: Record): Record< const [_method, def] = methods[m]; const method = stringCamelCase(_method); - named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section }, def); + named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section, sectionHash, version: ver.version }, def); } } } else { @@ -107,15 +107,21 @@ export function generateCallTypes (registry: TypeRegistry, dest: string, apis: A args: args.join(', '), docs: [def.description], name: methodName, + sectionHash: def.sectionHash, + sectionName: def.section, + sectionVersion: def.version, type: formatType(registry, allDefs, def.type, imports) }; }).sort((a, b) => a.name.localeCompare(b.name)); return { items: allMethods, - name: section || 'unknown' + name: section || 'unknown', + sectionHash: allMethods.length && allMethods[0].sectionHash, + sectionName: allMethods.length && allMethods[0].sectionName, + sectionVersion: allMethods.length && allMethods[0].sectionVersion }; - }).sort((a, b) => a.name.localeCompare(b.name)); + }).filter(({ items }) => items.length).sort((a, b) => a.name.localeCompare(b.name)); if (modules.length) { imports.typesTypes.Observable = true; diff --git a/packages/typegen/src/templates/calls.hbs b/packages/typegen/src/templates/calls.hbs index 3074b6e0d3..23f217f020 100644 --- a/packages/typegen/src/templates/calls.hbs +++ b/packages/typegen/src/templates/calls.hbs @@ -5,6 +5,7 @@ declare module '@polkadot/api-base/types/calls' { export interface AugmentedCalls { {{#each modules}} + /** {{{sectionHash}}}/{{{sectionVersion}}} */ {{{name}}}: { {{#each items}} {{> docs}} diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 21adba5fd9..1eaa738737 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -10,7 +10,7 @@ import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interface import type { UncleEntryItem } from '@polkadot/types/interfaces/authorship'; import type { AllowedSlots, BabeAuthorityWeight, BabeBlockWeight, BabeEpochConfiguration, BabeEquivocationProof, BabeGenesisConfiguration, BabeGenesisConfigurationV1, BabeWeight, Epoch, EpochAuthorship, MaybeRandomness, MaybeVrf, NextConfigDescriptor, NextConfigDescriptorV1, OpaqueKeyOwnershipProof, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondaryPlain, RawBabePreDigestSecondaryTo159, RawBabePreDigestSecondaryVRF, RawBabePreDigestTo159, SlotNumber, VrfData, VrfOutput, VrfProof } from '@polkadot/types/interfaces/babe'; import type { AccountData, BalanceLock, BalanceLockTo212, BalanceStatus, Reasons, ReserveData, ReserveIdentifier, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances'; -import type { BeefyAuthoritySet, BeefyCommitment, BeefyId, BeefyNextAuthoritySet, BeefyPayload, BeefyPayloadId, BeefySignedCommitment, MmrRootHash, ValidatorSetId } from '@polkadot/types/interfaces/beefy'; +import type { BeefyAuthoritySet, BeefyCommitment, BeefyId, BeefyNextAuthoritySet, BeefyPayload, BeefyPayloadId, BeefySignedCommitment, MmrRootHash, ValidatorSet, ValidatorSetId } from '@polkadot/types/interfaces/beefy'; import type { BridgeMessageId, BridgedBlockHash, BridgedBlockNumber, BridgedHeader, CallOrigin, ChainId, DeliveredMessages, DispatchFeePayment, InboundLaneData, InboundRelayer, InitializationData, LaneId, MessageData, MessageKey, MessageNonce, MessagesDeliveryProofOf, MessagesProofOf, OperatingMode, OutboundLaneData, OutboundMessageFee, OutboundPayload, Parameter, RelayerId, UnrewardedRelayer, UnrewardedRelayersState } from '@polkadot/types/interfaces/bridges'; import type { BlockHash } from '@polkadot/types/interfaces/chain'; import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate'; @@ -1059,6 +1059,7 @@ declare module '@polkadot/types/types/registry' { ValidatorPrefsTo196: ValidatorPrefsTo196; ValidatorPrefsWithBlocked: ValidatorPrefsWithBlocked; ValidatorPrefsWithCommission: ValidatorPrefsWithCommission; + ValidatorSet: ValidatorSet; ValidatorSetId: ValidatorSetId; ValidatorSignature: ValidatorSignature; ValidDisputeStatementKind: ValidDisputeStatementKind; diff --git a/packages/types/src/interfaces/aura/runtime.ts b/packages/types/src/interfaces/aura/runtime.ts index 7ab833f242..5274c7fb3e 100644 --- a/packages/types/src/interfaces/aura/runtime.ts +++ b/packages/types/src/interfaces/aura/runtime.ts @@ -17,7 +17,8 @@ export const runtime: DefinitionsCall = { params: [], type: 'SlotDuration' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/babe/runtime.ts b/packages/types/src/interfaces/babe/runtime.ts index b51cb7b536..959af1f7b8 100644 --- a/packages/types/src/interfaces/babe/runtime.ts +++ b/packages/types/src/interfaces/babe/runtime.ts @@ -35,7 +35,7 @@ const V1_V2_SHARED: Record = { params: [], type: 'Epoch' } - // TDODO Add submit_report_equivocation_unsigned_extrinsic + // TODO Add submit_report_equivocation_unsigned_extrinsic }; export const runtime: DefinitionsCall = { diff --git a/packages/types/src/interfaces/beefy/definitions.ts b/packages/types/src/interfaces/beefy/definitions.ts index b6ad09e108..90ae05db32 100644 --- a/packages/types/src/interfaces/beefy/definitions.ts +++ b/packages/types/src/interfaces/beefy/definitions.ts @@ -36,6 +36,10 @@ export default { BeefyPayload: 'Vec<(BeefyPayloadId, Bytes)>', BeefyPayloadId: '[u8;2]', MmrRootHash: 'H256', - ValidatorSetId: 'u64' + ValidatorSetId: 'u64', + ValidatorSet: { + validators: 'Vec', + id: 'ValidatorSetId' + } } } as Definitions; diff --git a/packages/types/src/interfaces/beefy/runtime.ts b/packages/types/src/interfaces/beefy/runtime.ts index eea1689104..235d4c0243 100644 --- a/packages/types/src/interfaces/beefy/runtime.ts +++ b/packages/types/src/interfaces/beefy/runtime.ts @@ -4,6 +4,18 @@ import type { DefinitionsCall } from '../../types'; export const runtime: DefinitionsCall = { + BeefyApi: [ + { + methods: { + validator_set: { + description: 'Return the current active BEEFY validator set', + params: [], + type: 'Option' + } + }, + version: 1 + } + ], BeefyMmrApi: [ { methods: { @@ -17,7 +29,8 @@ export const runtime: DefinitionsCall = { params: [], type: 'BeefyNextAuthoritySet' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/beefy/types.ts b/packages/types/src/interfaces/beefy/types.ts index d96da2465e..4835b5a638 100644 --- a/packages/types/src/interfaces/beefy/types.ts +++ b/packages/types/src/interfaces/beefy/types.ts @@ -3,6 +3,7 @@ import type { Bytes, Option, Struct, U8aFixed, Vec, u32, u64 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; +import type { AuthorityId } from '@polkadot/types/interfaces/consensus'; import type { EcdsaSignature } from '@polkadot/types/interfaces/extrinsics'; import type { BlockNumber, H256 } from '@polkadot/types/interfaces/runtime'; @@ -45,6 +46,12 @@ export interface BeefySignedCommitment extends Struct { /** @name MmrRootHash */ export interface MmrRootHash extends H256 {} +/** @name ValidatorSet */ +export interface ValidatorSet extends Struct { + readonly validators: Vec; + readonly id: ValidatorSetId; +} + /** @name ValidatorSetId */ export interface ValidatorSetId extends u64 {} diff --git a/packages/types/src/interfaces/contracts/runtime.ts b/packages/types/src/interfaces/contracts/runtime.ts index b711b19e4f..b2f3a4d3b3 100644 --- a/packages/types/src/interfaces/contracts/runtime.ts +++ b/packages/types/src/interfaces/contracts/runtime.ts @@ -103,7 +103,8 @@ export const runtime: DefinitionsCall = { ], type: 'CodeUploadResult' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/definitions.ts b/packages/types/src/interfaces/definitions.ts index 51e6b7608c..ab4d301b35 100644 --- a/packages/types/src/interfaces/definitions.ts +++ b/packages/types/src/interfaces/definitions.ts @@ -15,6 +15,7 @@ export { default as consensus } from './consensus/definitions'; export { default as contracts } from './contracts/definitions'; export { default as democracy } from './democracy/definitions'; export { default as dev } from './dev/definitions'; +export { default as discovery } from './discovery/definitions'; export { default as elections } from './elections/definitions'; export { default as engine } from './engine/definitions'; export { default as evm } from './evm/definitions'; @@ -48,6 +49,7 @@ export { default as bridges } from './bridges/definitions'; export { default as claims } from './claims/definitions'; export { default as crowdloan } from './crowdloan/definitions'; export { default as cumulus } from './cumulus/definitions'; +export { default as finality } from './finality/definitions'; export { default as parachains } from './parachains/definitions'; export { default as poll } from './poll/definitions'; export { default as purchase } from './purchase/definitions'; diff --git a/packages/types/src/interfaces/discovery/definitions.ts b/packages/types/src/interfaces/discovery/definitions.ts new file mode 100644 index 0000000000..cf1b866912 --- /dev/null +++ b/packages/types/src/interfaces/discovery/definitions.ts @@ -0,0 +1,15 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// order important in structs... :) +/* eslint-disable sort-keys */ + +import type { Definitions } from '../../types'; + +import { runtime } from './runtime'; + +export default { + rpc: {}, + runtime, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/discovery/index.ts b/packages/types/src/interfaces/discovery/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/discovery/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/discovery/runtime.ts b/packages/types/src/interfaces/discovery/runtime.ts new file mode 100644 index 0000000000..af56d2cf63 --- /dev/null +++ b/packages/types/src/interfaces/discovery/runtime.ts @@ -0,0 +1,19 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +export const runtime: DefinitionsCall = { + AuthorityDiscoveryApi: [ + { + methods: { + authorities: { + description: 'Retrieve authority identifiers of the current and next authority set.', + params: [], + type: 'Vec' + } + }, + version: 1 + } + ] +}; diff --git a/packages/types/src/interfaces/discovery/types.ts b/packages/types/src/interfaces/discovery/types.ts new file mode 100644 index 0000000000..1df057a7d4 --- /dev/null +++ b/packages/types/src/interfaces/discovery/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_DISCOVERY = 'discovery'; diff --git a/packages/types/src/interfaces/finality/definitions.ts b/packages/types/src/interfaces/finality/definitions.ts new file mode 100644 index 0000000000..cf1b866912 --- /dev/null +++ b/packages/types/src/interfaces/finality/definitions.ts @@ -0,0 +1,15 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// order important in structs... :) +/* eslint-disable sort-keys */ + +import type { Definitions } from '../../types'; + +import { runtime } from './runtime'; + +export default { + rpc: {}, + runtime, + types: {} +} as Definitions; diff --git a/packages/types/src/interfaces/finality/index.ts b/packages/types/src/interfaces/finality/index.ts new file mode 100644 index 0000000000..2d307291c3 --- /dev/null +++ b/packages/types/src/interfaces/finality/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/finality/runtime.ts b/packages/types/src/interfaces/finality/runtime.ts new file mode 100644 index 0000000000..8e4b14f026 --- /dev/null +++ b/packages/types/src/interfaces/finality/runtime.ts @@ -0,0 +1,23 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +// implemented by chains bridging into the relay, not the relay itself +const finalityV1 = { + methods: { + best_finalized: { + description: 'Returns number and hash of the best finalized header known to the bridge module.', + params: [], + type: '(BlockNumber, Hash)' + } + }, + version: 1 +}; + +export const runtime: DefinitionsCall = { + KusamaFinalityApi: [finalityV1], + PolkadotFinalityApi: [finalityV1], + RococoFinalityApi: [finalityV1], + WestendFinalityApi: [finalityV1] +}; diff --git a/packages/types/src/interfaces/finality/types.ts b/packages/types/src/interfaces/finality/types.ts new file mode 100644 index 0000000000..6fa253848c --- /dev/null +++ b/packages/types/src/interfaces/finality/types.ts @@ -0,0 +1,4 @@ +// Auto-generated via `yarn polkadot-types-from-defs`, do not edit +/* eslint-disable */ + +export type PHANTOM_FINALITY = 'finality'; diff --git a/packages/types/src/interfaces/grandpa/runtime.ts b/packages/types/src/interfaces/grandpa/runtime.ts index 9fcef70f8d..48d0e2633e 100644 --- a/packages/types/src/interfaces/grandpa/runtime.ts +++ b/packages/types/src/interfaces/grandpa/runtime.ts @@ -17,6 +17,7 @@ export const runtime: DefinitionsCall = { params: [], type: 'AuthorityList' } + // TODO submit_report_equivocation_unsigned_extrinsic, generate_key_ownership_proof }, version: 3 } diff --git a/packages/types/src/interfaces/metadata/runtime.ts b/packages/types/src/interfaces/metadata/runtime.ts index 4a64ba9d74..b701230e1b 100644 --- a/packages/types/src/interfaces/metadata/runtime.ts +++ b/packages/types/src/interfaces/metadata/runtime.ts @@ -12,7 +12,8 @@ export const runtime: DefinitionsCall = { params: [], type: 'OpaqueMetadata' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/payment/runtime.ts b/packages/types/src/interfaces/payment/runtime.ts index eb4fd47a02..d8498907db 100644 --- a/packages/types/src/interfaces/payment/runtime.ts +++ b/packages/types/src/interfaces/payment/runtime.ts @@ -35,7 +35,8 @@ export const runtime: DefinitionsCall = { ], type: 'RuntimeDispatchInfo' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index 614d43eaaa..90c5a8d4e4 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -8,6 +8,8 @@ import type { Definitions } from '../../types'; import { objectSpread } from '@polkadot/util'; +import { runtime } from './runtime'; + const numberTypes = { Fixed64: 'Int<64, Fixed64>', FixedI64: 'Int<64, FixedI64>', @@ -47,6 +49,7 @@ export const knownOrigins: Record = { export default { rpc: {}, + runtime, types: objectSpread({}, numberTypes, { AccountId: 'AccountId32', AccountId20: 'GenericEthereumAccountId', diff --git a/packages/types/src/interfaces/runtime/runtime.ts b/packages/types/src/interfaces/runtime/runtime.ts new file mode 100644 index 0000000000..4d015430f8 --- /dev/null +++ b/packages/types/src/interfaces/runtime/runtime.ts @@ -0,0 +1,20 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +export const runtime: DefinitionsCall = { + Core: [ + { + methods: { + version: { + description: 'Returns the version of the runtime.', + params: [], + type: 'RuntimeVersion' + } + }, + version: 4 + // TODO Add execute_block & initialize_block + } + ] +}; diff --git a/packages/types/src/interfaces/session/runtime.ts b/packages/types/src/interfaces/session/runtime.ts index 0e84820b1a..3941453281 100644 --- a/packages/types/src/interfaces/session/runtime.ts +++ b/packages/types/src/interfaces/session/runtime.ts @@ -27,7 +27,8 @@ export const runtime: DefinitionsCall = { ], type: 'Bytes' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/system/runtime.ts b/packages/types/src/interfaces/system/runtime.ts index c377a9dd21..7cda0f35b6 100644 --- a/packages/types/src/interfaces/system/runtime.ts +++ b/packages/types/src/interfaces/system/runtime.ts @@ -17,7 +17,8 @@ export const runtime: DefinitionsCall = { ], type: 'Index' } - } + }, + version: 1 } ] }; diff --git a/packages/types/src/interfaces/types.ts b/packages/types/src/interfaces/types.ts index fdd102b1f5..1947b9ca68 100644 --- a/packages/types/src/interfaces/types.ts +++ b/packages/types/src/interfaces/types.ts @@ -21,11 +21,13 @@ export * from './crowdloan/types'; export * from './cumulus/types'; export * from './democracy/types'; export * from './dev/types'; +export * from './discovery/types'; export * from './elections/types'; export * from './engine/types'; export * from './eth/types'; export * from './evm/types'; export * from './extrinsics/types'; +export * from './finality/types'; export * from './genericAsset/types'; export * from './gilt/types'; export * from './grandpa/types'; diff --git a/packages/types/src/types/definitions.ts b/packages/types/src/types/definitions.ts index 58238e0331..c1f43b6c72 100644 --- a/packages/types/src/types/definitions.ts +++ b/packages/types/src/types/definitions.ts @@ -61,7 +61,7 @@ export type DefinitionsRpc = Record; export type DefinitionsCall = Record; - version?: number; + version: number; }[]>; export type DefinitionsTypes = Record;