Expose findCall/findError on api.at (#4027)
* Expose findCall/findError on api.at * Move findError/findCall
This commit is contained in:
@@ -7,7 +7,7 @@ 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, RegistryTypes } from '@polkadot/types/types';
|
||||
import type { AnyFunction, AnyTuple, CallFunction, Codec, DefinitionRpc, DefinitionRpcSub, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from '@polkadot/types/types';
|
||||
import type { SubmittableExtrinsic } from '../submittable/types';
|
||||
import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecoratedRpcSection, DecorateMethod, PaginationOptions, QueryableConsts, QueryableModuleStorage, QueryableModuleStorageAt, QueryableStorage, QueryableStorageAt, QueryableStorageEntry, QueryableStorageEntryAt, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
|
||||
import type { VersionedRegistry } from './types';
|
||||
@@ -18,7 +18,7 @@ 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 } from '@polkadot/util';
|
||||
import { arrayChunk, arrayFlatten, assert, BN, BN_ZERO, compactStripLength, logger, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { augmentObject } from '../util/augmentObject';
|
||||
@@ -172,6 +172,20 @@ 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
|
||||
*/
|
||||
@@ -226,6 +240,11 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
augmentObject('query', storage, decoratedApi.query, fromEmpty);
|
||||
augmentObject('query', storageRx, decoratedApi.rx.query, fromEmpty);
|
||||
|
||||
decoratedApi.findCall = (callIndex: Uint8Array | string): CallFunction =>
|
||||
registry.registry.findMetaCall(u8aToU8a(callIndex));
|
||||
decoratedApi.findError = (errorIndex: Uint8Array | string): RegistryError =>
|
||||
registry.registry.findMetaError(u8aToU8a(errorIndex));
|
||||
|
||||
return {
|
||||
decoratedApi,
|
||||
decoratedMeta: registry.decoratedMeta
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { CallFunction, RegistryError, SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
import type { SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
import type { ApiOptions, ApiTypes, DecorateMethod, Signer } from '../types';
|
||||
|
||||
import { assert, isString, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
@@ -55,20 +55,6 @@ export abstract class ApiBase<ApiType extends ApiTypes> extends Getters<ApiType>
|
||||
return this._rpcCore.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-
|
||||
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
|
||||
import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { Metadata } from '@polkadot/types/metadata';
|
||||
import type { DefinitionRpc, DefinitionRpcSub, RegisteredTypes, Registry, SignatureOptions, Signer } from '@polkadot/types/types';
|
||||
import type { CallFunction, DefinitionRpc, DefinitionRpcSub, RegisteredTypes, Registry, RegistryError, SignatureOptions, Signer } from '@polkadot/types/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiBase } from '../base';
|
||||
import type { DeriveAllSections } from '../util/decorate';
|
||||
@@ -118,4 +118,7 @@ export interface ApiDecoration<ApiType extends ApiTypes> {
|
||||
rx: {
|
||||
query: QueryableStorage<'rxjs'>;
|
||||
}
|
||||
|
||||
findCall (callIndex: Uint8Array | string): CallFunction;
|
||||
findError (errorIndex: Uint8Array | string): RegistryError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user