DispatchError.error as [u8; 4] (#4570)
* DispatchError.error as [u8; 4] * Adjust Error.is * Adjust * Adjust * U8a applies to error only * CHANGELOG
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
import type { Codec, CodecClass, IU8a } from '@polkadot/types-codec/types';
|
||||
import type { CreateOptions, TypeDef } from '@polkadot/types-create/types';
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
||||
import type { ChainProperties, DispatchErrorModule, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
|
||||
import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
|
||||
import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
|
||||
|
||||
import { DoNotConstruct, Json, Raw } from '@polkadot/types-codec';
|
||||
@@ -288,10 +288,15 @@ export class TypeRegistry implements Registry {
|
||||
}
|
||||
|
||||
// finds an error
|
||||
public findMetaError (errorIndex: Uint8Array | DispatchErrorModule): RegistryError {
|
||||
public findMetaError (errorIndex: Uint8Array | DispatchErrorModule | DispatchErrorModuleU8a): RegistryError {
|
||||
const [section, method] = isU8a(errorIndex)
|
||||
? [errorIndex[0], errorIndex[1]]
|
||||
: [errorIndex.index.toNumber(), errorIndex.error.toNumber()];
|
||||
: [
|
||||
errorIndex.index.toNumber(),
|
||||
isU8a(errorIndex.error)
|
||||
? errorIndex.error[0]
|
||||
: errorIndex.error.toNumber()
|
||||
];
|
||||
|
||||
return assertReturn(
|
||||
this.#metadataErrors[`${section}`] && this.#metadataErrors[`${section}`][`${method}`],
|
||||
|
||||
@@ -214,6 +214,10 @@ export default {
|
||||
index: 'u8',
|
||||
error: 'u8'
|
||||
},
|
||||
DispatchErrorModuleU8a: {
|
||||
index: 'u8',
|
||||
error: '[u8; 4]'
|
||||
},
|
||||
DispatchErrorTo198: {
|
||||
module: 'Option<u8>',
|
||||
error: 'u8'
|
||||
|
||||
@@ -125,6 +125,12 @@ export interface DispatchErrorModule extends Struct {
|
||||
readonly error: u8;
|
||||
}
|
||||
|
||||
/** @name DispatchErrorModuleU8a */
|
||||
export interface DispatchErrorModuleU8a extends Struct {
|
||||
readonly index: u8;
|
||||
readonly error: U8aFixed;
|
||||
}
|
||||
|
||||
/** @name DispatchErrorTo198 */
|
||||
export interface DispatchErrorTo198 extends Struct {
|
||||
readonly module: Option<u8>;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
import type { Text, u8 } from '@polkadot/types-codec';
|
||||
import type { Registry } from '@polkadot/types-codec/types';
|
||||
import type { DispatchErrorModule, MetadataLatest, SiField, SiVariant } from '../../../interfaces';
|
||||
import type { DispatchErrorModule, DispatchErrorModuleU8a, MetadataLatest, SiField, SiVariant } from '../../../interfaces';
|
||||
import type { PortableRegistry } from '../../../metadata';
|
||||
import type { Errors, IsError } from '../types';
|
||||
|
||||
import { lazyMethod, objectSpread, stringCamelCase } from '@polkadot/util';
|
||||
import { isU8a, lazyMethod, objectSpread, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { lazyVariants } from '../../../create/lazy';
|
||||
import { objectNameToString } from '../util';
|
||||
@@ -39,9 +39,12 @@ export function decorateErrors (registry: Registry, { lookup, pallets }: Metadat
|
||||
|
||||
lazyMethod(result, stringCamelCase(name), () =>
|
||||
lazyVariants(lookup, errors.unwrap(), objectNameToString, (variant: SiVariant): IsError => ({
|
||||
is: ({ error, index }: DispatchErrorModule) =>
|
||||
index.eq(sectionIndex) &&
|
||||
error.eq(variant.index),
|
||||
is: ({ error, index }: DispatchErrorModule | DispatchErrorModuleU8a) =>
|
||||
index.eq(sectionIndex) && (
|
||||
isU8a(error)
|
||||
? error[0] === variant.index.toNumber()
|
||||
: error.eq(variant.index)
|
||||
),
|
||||
meta: registry.createTypeUnsafe('ErrorMetadataLatest', [variantToMeta(lookup, variant)])
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyTuple, Codec, Registry } from '@polkadot/types-codec/types';
|
||||
import type { DispatchErrorModule, ErrorMetadataLatest, EventMetadataLatest, PalletConstantMetadataLatest } from '../../interfaces';
|
||||
import type { DispatchErrorModule, DispatchErrorModuleU8a, ErrorMetadataLatest, EventMetadataLatest, PalletConstantMetadataLatest } from '../../interfaces';
|
||||
import type { StorageEntry } from '../../primitive/types';
|
||||
import type { CallFunction, IEvent } from '../../types';
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface ConstantCodec extends Codec {
|
||||
export interface IsError {
|
||||
readonly meta: ErrorMetadataLatest;
|
||||
|
||||
is: (moduleError: DispatchErrorModule) => boolean;
|
||||
is: (moduleError: DispatchErrorModule | DispatchErrorModuleU8a) => boolean;
|
||||
}
|
||||
|
||||
export interface IsEvent <T extends AnyTuple> {
|
||||
|
||||
@@ -5,7 +5,6 @@ import '@polkadot/types-create/types/augmentRegistry';
|
||||
|
||||
import type { Codec, CodecClass } from '@polkadot/types-codec/types';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
||||
import type { MetadataLatest } from '../interfaces/metadata';
|
||||
import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo';
|
||||
@@ -27,7 +26,6 @@ declare module '@polkadot/types-codec/types/registry' {
|
||||
readonly signedExtensions: string[];
|
||||
|
||||
findMetaCall (callIndex: Uint8Array): CallFunctionExt;
|
||||
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN }): RegistryError;
|
||||
|
||||
clearCache (): void
|
||||
|
||||
|
||||
Reference in New Issue
Block a user