From 56a3d4ece85de039989719f2114c0a9b674042ae Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 6 Jun 2022 07:40:35 +0200 Subject: [PATCH] DispatchError{U8, U8a} aliasing (w/ contracts RPC) (#4894) * DispatchError{U8, U8a} aliasing (w/ contracts RPC) * Rename --- CHANGELOG.md | 2 ++ .../types-augment/src/registry/interfaces.ts | 7 +++---- packages/types/src/create/registry.ts | 4 ++-- .../src/interfaces/contracts/definitions.ts | 15 +------------- .../types/src/interfaces/contracts/types.ts | 20 +------------------ .../src/interfaces/system/definitions.ts | 3 ++- packages/types/src/interfaces/system/types.ts | 5 ++++- .../src/metadata/decorate/errors/index.ts | 4 ++-- packages/types/src/metadata/decorate/types.ts | 4 ++-- 9 files changed, 19 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5921a5fe65..d4c861e979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changes: +- Add aliases for `DispatchError{U8, U8a}` (default to new `U8a` variant) +- Adjust contracts RPC definitions with `DispatchError` return - Optimization for value returns on merged queries diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 4a45fdf61a..257b2f1e69 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -17,7 +17,7 @@ import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate'; import type { StatementKind } from '@polkadot/types/interfaces/claims'; import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective'; import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus'; -import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; +import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan'; import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus'; @@ -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, 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 { AccountInfo, AccountInfoWithDualRefCount, AccountInfoWithProviders, AccountInfoWithRefCount, AccountInfoWithRefCountU8, AccountInfoWithTripleRefCount, ApplyExtrinsicResult, ArithmeticError, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorModuleU8, 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'; @@ -240,8 +240,6 @@ declare module '@polkadot/types/types/registry' { ContractEventSpecV1: ContractEventSpecV1; ContractEventSpecV2: ContractEventSpecV2; ContractExecResult: ContractExecResult; - ContractExecResultErr: ContractExecResultErr; - ContractExecResultErrModule: ContractExecResultErrModule; ContractExecResultOk: ContractExecResultOk; ContractExecResultResult: ContractExecResultResult; ContractExecResultSuccessTo255: ContractExecResultSuccessTo255; @@ -307,6 +305,7 @@ declare module '@polkadot/types/types/registry' { DispatchClass: DispatchClass; DispatchError: DispatchError; DispatchErrorModule: DispatchErrorModule; + DispatchErrorModuleU8: DispatchErrorModuleU8; DispatchErrorModuleU8a: DispatchErrorModuleU8a; DispatchErrorTo198: DispatchErrorTo198; DispatchFeePayment: DispatchFeePayment; diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 7dede52cc5..f1e5f1a5c2 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, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types'; +import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8, 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,7 +288,7 @@ export class TypeRegistry implements Registry { } // finds an error - public findMetaError (errorIndex: Uint8Array | DispatchErrorModule | DispatchErrorModuleU8a): RegistryError { + public findMetaError (errorIndex: Uint8Array | DispatchErrorModule | DispatchErrorModuleU8 | DispatchErrorModuleU8a): RegistryError { const [section, method] = isU8a(errorIndex) ? [errorIndex[0], errorIndex[1]] : [ diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index d66aa95fd6..af60ca519d 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -73,19 +73,6 @@ export default { Error: 'Null' } }, - ContractExecResultErrModule: { - index: 'u8', - error: 'u8', - message: 'Option' - }, - ContractExecResultErr: { - _enum: { - Other: 'Text', - CannotLookup: 'Null', - BadOrigin: 'Null', - Module: 'ContractExecResultErrModule' - } - }, ContractExecResultOk: { flags: 'ContractReturnFlags', data: 'Bytes' @@ -93,7 +80,7 @@ export default { ContractExecResultResult: { _enum: { Ok: 'ContractExecResultOk', - Err: 'ContractExecResultErr' + Err: 'DispatchError' } }, ContractExecResultTo267: { diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index e7cbd28042..b5fdea3d88 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -78,24 +78,6 @@ export interface ContractExecResult extends Struct { readonly result: ContractExecResultResult; } -/** @name ContractExecResultErr */ -export interface ContractExecResultErr extends Enum { - readonly isOther: boolean; - readonly asOther: Text; - readonly isCannotLookup: boolean; - readonly isBadOrigin: boolean; - readonly isModule: boolean; - readonly asModule: ContractExecResultErrModule; - readonly type: 'Other' | 'CannotLookup' | 'BadOrigin' | 'Module'; -} - -/** @name ContractExecResultErrModule */ -export interface ContractExecResultErrModule extends Struct { - readonly index: u8; - readonly error: u8; - readonly message: Option; -} - /** @name ContractExecResultOk */ export interface ContractExecResultOk extends Struct { readonly flags: ContractReturnFlags; @@ -107,7 +89,7 @@ export interface ContractExecResultResult extends Enum { readonly isOk: boolean; readonly asOk: ContractExecResultOk; readonly isErr: boolean; - readonly asErr: ContractExecResultErr; + readonly asErr: DispatchError; readonly type: 'Ok' | 'Err'; } diff --git a/packages/types/src/interfaces/system/definitions.ts b/packages/types/src/interfaces/system/definitions.ts index 6b40702bb0..520e8bb956 100644 --- a/packages/types/src/interfaces/system/definitions.ts +++ b/packages/types/src/interfaces/system/definitions.ts @@ -210,7 +210,7 @@ export default { Arithmetic: 'ArithmeticError' } }, - DispatchErrorModule: { + DispatchErrorModuleU8: { index: 'u8', error: 'u8' }, @@ -218,6 +218,7 @@ export default { index: 'u8', error: '[u8; 4]' }, + DispatchErrorModule: 'DispatchErrorModuleU8a', DispatchErrorTo198: { module: 'Option', error: 'u8' diff --git a/packages/types/src/interfaces/system/types.ts b/packages/types/src/interfaces/system/types.ts index 59a41fba2e..392a81652e 100644 --- a/packages/types/src/interfaces/system/types.ts +++ b/packages/types/src/interfaces/system/types.ts @@ -120,7 +120,10 @@ export interface DispatchError extends Enum { } /** @name DispatchErrorModule */ -export interface DispatchErrorModule extends Struct { +export interface DispatchErrorModule extends DispatchErrorModuleU8a {} + +/** @name DispatchErrorModuleU8 */ +export interface DispatchErrorModuleU8 extends Struct { readonly index: u8; readonly error: u8; } diff --git a/packages/types/src/metadata/decorate/errors/index.ts b/packages/types/src/metadata/decorate/errors/index.ts index c42bd22ee6..4e38aff649 100644 --- a/packages/types/src/metadata/decorate/errors/index.ts +++ b/packages/types/src/metadata/decorate/errors/index.ts @@ -3,7 +3,7 @@ import type { Text, u8 } from '@polkadot/types-codec'; import type { Registry } from '@polkadot/types-codec/types'; -import type { DispatchErrorModule, DispatchErrorModuleU8a, MetadataLatest, SiField, SiVariant } from '../../../interfaces'; +import type { DispatchErrorModule, DispatchErrorModuleU8, DispatchErrorModuleU8a, MetadataLatest, SiField, SiVariant } from '../../../interfaces'; import type { PortableRegistry } from '../../../metadata'; import type { Errors, IsError } from '../types'; @@ -40,7 +40,7 @@ export function decorateErrors (registry: Registry, { lookup, pallets }: Metadat lazyMethod(result, stringCamelCase(name), () => lazyVariants(lookup, errors.unwrap(), objectNameToString, (variant: SiVariant): IsError => ({ // We sprinkle in isCodec & isU8a to ensure we are dealing with the correct objects - is: (errorMod: DispatchErrorModule | DispatchErrorModuleU8a) => + is: (errorMod: DispatchErrorModule | DispatchErrorModuleU8 | DispatchErrorModuleU8a) => isCodec(errorMod) && isCodec(errorMod.index) && errorMod.index.eq(sectionIndex) && ( diff --git a/packages/types/src/metadata/decorate/types.ts b/packages/types/src/metadata/decorate/types.ts index 834feaa852..acc83e8386 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, DispatchErrorModuleU8a, ErrorMetadataLatest, EventMetadataLatest, PalletConstantMetadataLatest } from '../../interfaces'; +import type { DispatchErrorModule, DispatchErrorModuleU8, 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 | DispatchErrorModuleU8a) => boolean; + is: (moduleError: DispatchErrorModule | DispatchErrorModuleU8 | DispatchErrorModuleU8a) => boolean; } export interface IsEvent {