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:
Jaco
2022-03-30 17:57:41 +03:00
committed by GitHub
parent 29d5460cdd
commit 84abaff414
9 changed files with 44 additions and 14 deletions
+13
View File
@@ -1,5 +1,18 @@
# CHANGELOG
## master
Contributed:
- Export `WellKnownChain` for `substrate-connect` (Thanks to https://github.com/josepot)
- Add support for `{entries, keys}Paged` in `.at` (Thanks to https://github.com/xlc)
- Align `WeightsPerClass` interface on `maxExtrinsic` (Thanks to https://github.com/HackFisher)
Changes:
- Cater for `DispatchError` with `error` as `[u8; 4]`
## 7.14.3 Mar 28, 2022
Changes:
@@ -53,7 +53,7 @@ import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, Vouching
import type { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactAssignmentsTo265, CompactAssignmentsWith16, CompactAssignmentsWith24, CompactScore, CompactScoreCompact, ElectionCompute, ElectionPhase, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, ExtendedBalance, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RawSolution, RawSolutionTo265, RawSolutionWith16, RawSolutionWith24, ReadySolution, RewardDestination, RewardPoint, RoundSnapshot, SeatHolder, SignedSubmission, SignedSubmissionOf, SignedSubmissionTo276, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SolutionOrSnapshotSize, SolutionSupport, SolutionSupports, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, SubmissionIndicesOf, Supports, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196, ValidatorPrefsWithBlocked, ValidatorPrefsWithCommission, VoteWeight, Voter } from '@polkadot/types/interfaces/staking';
import type { ApiId, BlockTrace, BlockTraceEvent, BlockTraceEventData, BlockTraceSpan, KeyValueOption, MigrationStatusResult, ReadProof, RuntimeVersion, RuntimeVersionApi, RuntimeVersionPartial, SpecVersion, StorageChangeSet, TraceBlockResponse, TraceError } from '@polkadot/types/interfaces/state';
import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
import type { AccountInfo, AccountInfoWithDualRefCount, AccountInfoWithProviders, AccountInfoWithRefCount, AccountInfoWithRefCountU8, AccountInfoWithTripleRefCount, ApplyExtrinsicResult, ArithmeticError, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClassU32, PerDispatchClassWeight, PerDispatchClassWeightsPerClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TokenError, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system';
import type { AccountInfo, AccountInfoWithDualRefCount, AccountInfoWithProviders, AccountInfoWithRefCount, AccountInfoWithRefCountU8, AccountInfoWithTripleRefCount, ApplyExtrinsicResult, ArithmeticError, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorModuleU8a, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClassU32, PerDispatchClassWeight, PerDispatchClassWeightsPerClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TokenError, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system';
import type { Bounty, BountyIndex, BountyStatus, BountyStatusActive, BountyStatusCuratorProposed, BountyStatusPendingPayout, OpenTip, OpenTipFinderTo225, OpenTipTip, OpenTipTo225, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import type { Multiplier } from '@polkadot/types/interfaces/txpayment';
import type { ClassDetails, ClassId, ClassMetadata, DepositBalance, DepositBalanceOf, DestroyWitness, InstanceDetails, InstanceId, InstanceMetadata } from '@polkadot/types/interfaces/uniques';
@@ -307,6 +307,7 @@ declare module '@polkadot/types/types/registry' {
DispatchClass: DispatchClass;
DispatchError: DispatchError;
DispatchErrorModule: DispatchErrorModule;
DispatchErrorModuleU8a: DispatchErrorModuleU8a;
DispatchErrorTo198: DispatchErrorTo198;
DispatchFeePayment: DispatchFeePayment;
DispatchInfo: DispatchInfo;
+1 -1
View File
@@ -60,7 +60,7 @@ export interface Registry {
createdAtHash?: IU8a;
findMetaCall (callIndex: Uint8Array): CallFunction;
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN }): RegistryError;
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN } | { error: BN | Uint8Array, index: BN }): RegistryError;
findMetaEvent (eventIndex: Uint8Array): CodecClass<any>;
isLookupType (value: string): boolean;
+8 -3
View File
@@ -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