Keep count of runtime decorations (#5130)
This commit is contained in:
@@ -10,6 +10,7 @@ Contributed:
|
||||
Changes:
|
||||
|
||||
- Add `noInitWarn: boolean` flag to API options, disabling runtime & RPC warning availability displays
|
||||
- Only log missing runtime calls on new metadata instances (not for internal instances)
|
||||
|
||||
|
||||
## 9.0.1 Jul 30, 2022
|
||||
|
||||
@@ -228,7 +228,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
} as ApiDecoration<ApiType>;
|
||||
}
|
||||
|
||||
protected _createDecorated (registry: VersionedRegistry<ApiType>, fromEmpty: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType> {
|
||||
protected _createDecorated (registry: VersionedRegistry<ApiType>, fromEmpty: boolean, withLogging: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType> {
|
||||
if (!decoratedApi) {
|
||||
decoratedApi = this._emptyDecorated(registry.registry, blockHash);
|
||||
}
|
||||
@@ -237,8 +237,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
registry.decoratedMeta = expandMetadata(registry.registry, registry.metadata);
|
||||
}
|
||||
|
||||
const runtime = this._decorateCalls(registry, this._decorateMethod, blockHash);
|
||||
const runtimeRx = this._decorateCalls<'rxjs'>(registry, this._rxDecorateMethod, blockHash);
|
||||
const runtime = this._decorateCalls(registry, this._decorateMethod, blockHash, withLogging);
|
||||
const runtimeRx = this._decorateCalls<'rxjs'>(registry, this._rxDecorateMethod, blockHash, false);
|
||||
const storage = this._decorateStorage(registry.decoratedMeta, this._decorateMethod, blockHash);
|
||||
const storageRx = this._decorateStorage<'rxjs'>(registry.decoratedMeta, this._rxDecorateMethod, blockHash);
|
||||
|
||||
@@ -271,7 +271,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
registry.decoratedApi = this._emptyDecorated(registry.registry);
|
||||
}
|
||||
|
||||
const { decoratedApi, decoratedMeta } = this._createDecorated(registry, fromEmpty, registry.decoratedApi);
|
||||
const { decoratedApi, decoratedMeta } = this._createDecorated(registry, fromEmpty, !registry.counter, registry.decoratedApi);
|
||||
|
||||
this._call = decoratedApi.call;
|
||||
this._consts = decoratedApi.consts;
|
||||
@@ -303,7 +303,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, runtimeVersion: this.#registry.createType('RuntimeVersionPartial') }, fromEmpty);
|
||||
this._injectMetadata({ counter: 0, metadata, registry: registry || this.#registry, runtimeVersion: this.#registry.createType('RuntimeVersionPartial') }, fromEmpty);
|
||||
}
|
||||
|
||||
private _decorateFunctionMeta (input: MetaDecoration, output: MetaDecoration): MetaDecoration {
|
||||
@@ -494,7 +494,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
}
|
||||
|
||||
// pre-metadata decoration
|
||||
protected _decorateCalls<ApiType extends ApiTypes> ({ registry, runtimeVersion: { apis, specName } }: VersionedRegistry<any>, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array | string | null): QueryableCalls<ApiType> {
|
||||
protected _decorateCalls<ApiType extends ApiTypes> ({ registry, runtimeVersion: { apis, specName } }: VersionedRegistry<any>, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array | string | null, withLogging = true): QueryableCalls<ApiType> {
|
||||
const result = {} as QueryableCalls<ApiType>;
|
||||
const named: Record<string, Record<string, DefinitionCallNamed>> = {};
|
||||
const hashes: Record<HexString, boolean> = {};
|
||||
@@ -540,7 +540,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
.filter(([a]) => !hashes[a])
|
||||
.map(([a, v]) => `${this._runtimeMap[a] || a}/${v}`);
|
||||
|
||||
if (!this._options.noInitWarn) {
|
||||
if (!this._options.noInitWarn && withLogging) {
|
||||
if (older.length) {
|
||||
l.warn(`Not decorating runtime apis without matching versions: ${older.join(', ')}`);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
// always create a new decoration - since we are pointing to a specific hash, this
|
||||
// means that all queries needs to use that hash (not a previous one already existing)
|
||||
return this._createDecorated(registry, true, null, u8aHash).decoratedApi;
|
||||
return this._createDecorated(registry, true, !registry.counter, null, u8aHash).decoratedApi;
|
||||
}
|
||||
|
||||
private async _createBlockRegistry (blockHash: Uint8Array, header: HeaderPartial, version: RuntimeVersionPartial): Promise<VersionedRegistry<ApiType>> {
|
||||
@@ -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, runtimeVersion: version };
|
||||
const result = { counter: 0, lastBlockHash: blockHash, metadata, registry, runtimeVersion: version };
|
||||
|
||||
this.#registries.push(result);
|
||||
|
||||
@@ -168,6 +168,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
);
|
||||
|
||||
if (existingViaVersion) {
|
||||
existingViaVersion.counter++;
|
||||
existingViaVersion.lastBlockHash = blockHash;
|
||||
|
||||
return existingViaVersion;
|
||||
@@ -337,7 +338,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, runtimeVersion });
|
||||
this.#registries.push({ counter: 0, isDefault: true, metadata, registry: this.registry, runtimeVersion });
|
||||
}
|
||||
|
||||
// get unique types & validate
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { Registry } from '@polkadot/types/types';
|
||||
import type { ApiDecoration, ApiTypes } from '../types';
|
||||
|
||||
export interface VersionedRegistry<ApiType extends ApiTypes> {
|
||||
counter: number;
|
||||
decoratedApi?: ApiDecoration<ApiType>;
|
||||
decoratedMeta?: DecoratedMeta;
|
||||
isDefault?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user