DispatchError{U8, U8a} aliasing (w/ contracts RPC) (#4894)

* DispatchError{U8, U8a} aliasing (w/ contracts RPC)

* Rename
This commit is contained in:
Jaco
2022-06-06 08:40:35 +03:00
committed by GitHub
parent 3336f5530c
commit 56a3d4ece8
9 changed files with 19 additions and 45 deletions
+2
View File
@@ -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
@@ -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;
+2 -2
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, 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]]
: [
@@ -73,19 +73,6 @@ export default {
Error: 'Null'
}
},
ContractExecResultErrModule: {
index: 'u8',
error: 'u8',
message: 'Option<Text>'
},
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: {
@@ -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<Text>;
}
/** @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';
}
@@ -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<u8>',
error: 'u8'
@@ -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;
}
@@ -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) && (
@@ -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 <T extends AnyTuple> {