Dedupe findCall/findError (#4028)
This commit is contained in:
@@ -18,13 +18,14 @@ import { decorateDerive, ExactDerive } 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, BN, BN_ZERO, compactStripLength, logger, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { arrayChunk, arrayFlatten, assert, BN, BN_ZERO, compactStripLength, logger, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { augmentObject } from '../util/augmentObject';
|
||||
import { decorateSections, DeriveAllSections } from '../util/decorate';
|
||||
import { extractStorageArgs } from '../util/validate';
|
||||
import { Events } from './Events';
|
||||
import { findCall, findError } from './find';
|
||||
|
||||
interface MetaDecoration {
|
||||
callIndex?: Uint8Array;
|
||||
@@ -172,20 +173,6 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
return this.#registry.createType(type, ...params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Finds the definition for a specific [[CallFunction]] based on the index supplied
|
||||
*/
|
||||
public findCall (callIndex: Uint8Array | string): CallFunction {
|
||||
return this.registry.findMetaCall(u8aToU8a(callIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Finds the definition for a specific [[RegistryError]] based on the index supplied
|
||||
*/
|
||||
public findError (errorIndex: Uint8Array | string): RegistryError {
|
||||
return this.registry.findMetaError(u8aToU8a(errorIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Register additional user-defined of chain-specific types in the type registry
|
||||
*/
|
||||
@@ -241,9 +228,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
augmentObject('query', storageRx, decoratedApi.rx.query, fromEmpty);
|
||||
|
||||
decoratedApi.findCall = (callIndex: Uint8Array | string): CallFunction =>
|
||||
registry.registry.findMetaCall(u8aToU8a(callIndex));
|
||||
findCall(registry.registry, callIndex);
|
||||
decoratedApi.findError = (errorIndex: Uint8Array | string): RegistryError =>
|
||||
registry.registry.findMetaError(u8aToU8a(errorIndex));
|
||||
findError(registry.registry, errorIndex);
|
||||
|
||||
return {
|
||||
decoratedApi,
|
||||
|
||||
@@ -5,11 +5,13 @@ import type { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import type { Text } from '@polkadot/types';
|
||||
import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { Metadata } from '@polkadot/types/metadata';
|
||||
import type { CallFunction, RegistryError } from '@polkadot/types/types';
|
||||
import type { ApiDecoration, ApiInterfaceRx, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
|
||||
|
||||
import { assertReturn } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from '../packageInfo';
|
||||
import { findCall, findError } from './find';
|
||||
import { Init } from './Init';
|
||||
|
||||
interface PkgJson {
|
||||
@@ -210,4 +212,18 @@ export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> im
|
||||
public get tx (): SubmittableExtrinsics<ApiType> {
|
||||
return assertResult(this._extrinsics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Finds the definition for a specific [[CallFunction]] based on the index supplied
|
||||
*/
|
||||
public findCall (callIndex: Uint8Array | string): CallFunction {
|
||||
return findCall(this.registry, callIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Finds the definition for a specific [[RegistryError]] based on the index supplied
|
||||
*/
|
||||
public findError (errorIndex: Uint8Array | string): RegistryError {
|
||||
return findError(this.registry, errorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { CallFunction, Registry, RegistryError } from '@polkadot/types/types';
|
||||
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
|
||||
export function findCall (registry: Registry, callIndex: Uint8Array | string): CallFunction {
|
||||
return registry.findMetaCall(u8aToU8a(callIndex));
|
||||
}
|
||||
|
||||
export function findError (registry: Registry, errorIndex: Uint8Array | string): RegistryError {
|
||||
return registry.findMetaError(u8aToU8a(errorIndex));
|
||||
}
|
||||
Reference in New Issue
Block a user