diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a2cdaa87f..7b9c4678d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 9a334b8077..c544a48068 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -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; diff --git a/packages/types-codec/src/types/registry.ts b/packages/types-codec/src/types/registry.ts index f2d67f3b52..356045984c 100644 --- a/packages/types-codec/src/types/registry.ts +++ b/packages/types-codec/src/types/registry.ts @@ -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; isLookupType (value: string): boolean; diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 3a5a5e3a05..49bbdeb92f 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -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}`], diff --git a/packages/types/src/interfaces/system/definitions.ts b/packages/types/src/interfaces/system/definitions.ts index 88650b3237..6b40702bb0 100644 --- a/packages/types/src/interfaces/system/definitions.ts +++ b/packages/types/src/interfaces/system/definitions.ts @@ -214,6 +214,10 @@ export default { index: 'u8', error: 'u8' }, + DispatchErrorModuleU8a: { + index: 'u8', + error: '[u8; 4]' + }, DispatchErrorTo198: { module: 'Option', error: 'u8' diff --git a/packages/types/src/interfaces/system/types.ts b/packages/types/src/interfaces/system/types.ts index ad25c8ddd9..59a41fba2e 100644 --- a/packages/types/src/interfaces/system/types.ts +++ b/packages/types/src/interfaces/system/types.ts @@ -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; diff --git a/packages/types/src/metadata/decorate/errors/index.ts b/packages/types/src/metadata/decorate/errors/index.ts index fb9335035c..0238da3a3f 100644 --- a/packages/types/src/metadata/decorate/errors/index.ts +++ b/packages/types/src/metadata/decorate/errors/index.ts @@ -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)]) })) ); diff --git a/packages/types/src/metadata/decorate/types.ts b/packages/types/src/metadata/decorate/types.ts index 2542de1969..834feaa852 100644 --- a/packages/types/src/metadata/decorate/types.ts +++ b/packages/types/src/metadata/decorate/types.ts @@ -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 { diff --git a/packages/types/src/types/augmentRegistry.ts b/packages/types/src/types/augmentRegistry.ts index 71e5348073..3ad382dfe5 100644 --- a/packages/types/src/types/augmentRegistry.ts +++ b/packages/types/src/types/augmentRegistry.ts @@ -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