Expose partial runtimeVersion on api.at (#4920)
This commit is contained in:
@@ -2,9 +2,14 @@
|
||||
|
||||
## master
|
||||
|
||||
Contributed:
|
||||
|
||||
- Ensure typegen disconnects from WS endpoint (Thanks to https://github.com/rflechtner)
|
||||
|
||||
Changes:
|
||||
|
||||
- Cater for named event fields (expose on event data as available)
|
||||
- Expose (partial) `runtimeVersion` on `api.at` interfaces
|
||||
- Add aliases for `DispatchError{U8, U8a}` (default to new `U8a` variant)
|
||||
- Align `DispatchError` definition with latest Substrate
|
||||
- Adjust contracts RPC definitions with `DispatchError` return
|
||||
|
||||
@@ -19,7 +19,7 @@ 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 { arrayChunk, arrayFlatten, assert, assertReturn, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, u8aToHex } from '@polkadot/util';
|
||||
import { arrayChunk, arrayFlatten, assert, assertReturn, BN, compactStripLength, lazyMethod, lazyMethods, logger, nextTick, objectSpread, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { augmentObject } from '../util/augmentObject';
|
||||
@@ -243,6 +243,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
decoratedApi.queryMulti = blockHash
|
||||
? this._decorateMultiAt(decoratedApi, this._decorateMethod, blockHash)
|
||||
: this._decorateMulti(this._decorateMethod);
|
||||
decoratedApi.runtimeVersion = registry.runtimeVersion;
|
||||
|
||||
return {
|
||||
decoratedApi,
|
||||
@@ -285,7 +286,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
* backwards compatible endpoint for metadata injection, may be removed in the future (However, it is still useful for testing injection)
|
||||
*/
|
||||
public injectMetadata (metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void {
|
||||
this._injectMetadata({ metadata, registry: registry || this.#registry, specName: this.#registry.createType('Text'), specVersion: BN_ZERO }, fromEmpty);
|
||||
this._injectMetadata({ metadata, registry: registry || this.#registry, runtimeVersion: this.#registry.createType('RuntimeVersionPartial') }, fromEmpty);
|
||||
}
|
||||
|
||||
private _decorateFunctionMeta (input: MetaDecoration, output: MetaDecoration): MetaDecoration {
|
||||
|
||||
@@ -129,7 +129,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
this._initRegistry(registry, this._runtimeChain as Text, version, metadata);
|
||||
|
||||
// add our new registry
|
||||
const result = { lastBlockHash: blockHash, metadata, registry, specName: version.specName, specVersion: version.specVersion };
|
||||
const result = { lastBlockHash: blockHash, metadata, registry, runtimeVersion: version };
|
||||
|
||||
this.#registries.push(result);
|
||||
|
||||
@@ -162,7 +162,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
if (version) {
|
||||
// check for pre-existing registries. We also check specName, e.g. it
|
||||
// could be changed like in Westmint with upgrade from shell -> westmint
|
||||
const existingViaVersion = this.#registries.find(({ specName, specVersion }) =>
|
||||
const existingViaVersion = this.#registries.find(({ runtimeVersion: { specName, specVersion } }) =>
|
||||
specName.eq(version.specName) &&
|
||||
specVersion.eq(version.specVersion)
|
||||
);
|
||||
@@ -289,7 +289,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
// setup the data as per the current versions
|
||||
thisRegistry.metadata = metadata;
|
||||
thisRegistry.specVersion = version.specVersion;
|
||||
thisRegistry.runtimeVersion = version;
|
||||
|
||||
this._initRegistry(this.registry, this._runtimeChain as Text, version, metadata);
|
||||
this._injectMetadata(thisRegistry, true);
|
||||
@@ -333,7 +333,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
// setup the initial registry, when we have none
|
||||
if (!this.#registries.length) {
|
||||
this.#registries.push({ isDefault: true, metadata, registry: this.registry, specName: runtimeVersion.specName, specVersion: runtimeVersion.specVersion });
|
||||
this.#registries.push({ isDefault: true, metadata, registry: this.registry, runtimeVersion });
|
||||
}
|
||||
|
||||
// get unique types & validate
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// Copyright 2017-2022 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Metadata } from '@polkadot/types/metadata';
|
||||
import type { Metadata } from '@polkadot/types';
|
||||
import type { RuntimeVersionPartial } from '@polkadot/types/interfaces';
|
||||
import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
||||
import type { Text } from '@polkadot/types/primitive';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiDecoration, ApiTypes } from '../types';
|
||||
|
||||
export interface VersionedRegistry<ApiType extends ApiTypes> {
|
||||
@@ -15,6 +14,5 @@ export interface VersionedRegistry<ApiType extends ApiTypes> {
|
||||
lastBlockHash?: Uint8Array | null;
|
||||
metadata: Metadata;
|
||||
registry: Registry;
|
||||
specName: Text;
|
||||
specVersion: BN;
|
||||
runtimeVersion: RuntimeVersionPartial;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { DecoratedEvents } from '@polkadot/api-base/types/events';
|
||||
import type { QueryableStorage } from '@polkadot/api-base/types/storage';
|
||||
import type { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
|
||||
import type { Call, Extrinsic, Hash } from '@polkadot/types/interfaces';
|
||||
import type { Call, Extrinsic, Hash, RuntimeVersionPartial } from '@polkadot/types/interfaces';
|
||||
import type { CallFunction, DefinitionRpc, DefinitionRpcSub, RegisteredTypes, Registry, RegistryError, SignatureOptions, Signer } from '@polkadot/types/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
@@ -95,6 +95,7 @@ export interface ApiDecoration<ApiType extends ApiTypes> {
|
||||
events: DecoratedEvents<ApiType>;
|
||||
query: QueryableStorage<ApiType>;
|
||||
registry: Registry;
|
||||
runtimeVersion: RuntimeVersionPartial;
|
||||
rx: {
|
||||
query: QueryableStorage<'rxjs'>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user