Update DispatchError as enum (#1682)

* Update DispatchError as enum

* Add DispatchResult

* Update tests for DispatchResult

* Rebuild
This commit is contained in:
Jaco Greeff
2019-12-19 15:37:36 +01:00
committed by GitHub
parent 416e2fbc96
commit 0c98593aee
10 changed files with 81 additions and 54 deletions
+1 -1
View File
@@ -45,6 +45,6 @@ describe('Result', (): void => {
});
it('returns a proper raw typedef rom a built-in', (): void => {
expect(createType(registry, 'DispatchResult').toRawType()).toEqual('Result<Null,Text>');
expect(createType(registry, 'DispatchResult').toRawType()).toEqual('Result<Null,{"_enum":{"Other":"Null","CannotLookup":"Null","BadOrigin":"Null","Module":"{\\"index\\":\\"u8\\",\\"error\\":\\"u8\\"}"}}>');
});
});
+16 -8
View File
@@ -21,10 +21,9 @@ import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetwor
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
import { EraIndex, EraPoints, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, Nominations, Points, RewardDestination, SlashJournalEntry, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { DigestOf, DispatchError, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase } from '@polkadot/types/interfaces/system';
import { DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase } from '@polkadot/types/interfaces/system';
import { TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { DispatchResult, DispatchResultOf } from '@polkadot/types/interfaces/utility';
import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
import { EthereumAddress } from '@polkadot/types/interfaces/claims';
import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
@@ -703,6 +702,21 @@ export interface InterfaceRegistry {
DispatchError: DispatchError;
'Option<DispatchError>': Option<DispatchError>;
'Vec<DispatchError>': Vec<DispatchError>;
DispatchErrorModule: DispatchErrorModule;
'Option<DispatchErrorModule>': Option<DispatchErrorModule>;
'Vec<DispatchErrorModule>': Vec<DispatchErrorModule>;
DispatchErrorTo198: DispatchErrorTo198;
'Option<DispatchErrorTo198>': Option<DispatchErrorTo198>;
'Vec<DispatchErrorTo198>': Vec<DispatchErrorTo198>;
DispatchResult: DispatchResult;
'Option<DispatchResult>': Option<DispatchResult>;
'Vec<DispatchResult>': Vec<DispatchResult>;
DispatchResultOf: DispatchResultOf;
'Option<DispatchResultOf>': Option<DispatchResultOf>;
'Vec<DispatchResultOf>': Vec<DispatchResultOf>;
DispatchResultTo198: DispatchResultTo198;
'Option<DispatchResultTo198>': Option<DispatchResultTo198>;
'Vec<DispatchResultTo198>': Vec<DispatchResultTo198>;
Event: Event;
'Option<Event>': Option<Event>;
'Vec<Event>': Vec<Event>;
@@ -731,12 +745,6 @@ export interface InterfaceRegistry {
Multiplier: Multiplier;
'Option<Multiplier>': Option<Multiplier>;
'Vec<Multiplier>': Vec<Multiplier>;
DispatchResult: DispatchResult;
'Option<DispatchResult>': Option<DispatchResult>;
'Vec<DispatchResult>': Vec<DispatchResult>;
DispatchResultOf: DispatchResultOf;
'Option<DispatchResultOf>': Option<DispatchResultOf>;
'Vec<DispatchResultOf>': Vec<DispatchResultOf>;
BlockAttestations: BlockAttestations;
'Option<BlockAttestations>': Option<BlockAttestations>;
'Vec<BlockAttestations>': Vec<BlockAttestations>;
@@ -26,7 +26,6 @@ export { default as staking } from './staking/definitions';
export { default as system } from './system/definitions';
export { default as treasury } from './treasury/definitions';
export { default as txpayment } from './txpayment/definitions';
export { default as utility } from './utility/definitions';
// polkadot-specific types
export { default as attestations } from './attestations/definitions';
@@ -6,9 +6,24 @@ export default {
types: {
DigestOf: 'Digest',
DispatchError: {
_enum: {
Other: 'Null',
CannotLookup: 'Null',
BadOrigin: 'Null',
Module: 'DispatchErrorModule'
}
},
DispatchErrorModule: {
index: 'u8',
error: 'u8'
},
DispatchErrorTo198: {
module: 'Option<u8>',
error: 'u8'
},
DispatchResult: 'Result<(), DispatchError>',
DispatchResultOf: 'DispatchResult',
DispatchResultTo198: 'Result<(), Text>',
Event: 'GenericEvent',
EventId: '[u8; 2]',
EventIndex: 'u32',
+48 -3
View File
@@ -2,21 +2,66 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Codec } from '@polkadot/types/types';
import { Enum, Option, Struct, Vec } from '@polkadot/types/codec';
import { Bytes, GenericEvent, u32, u8 } from '@polkadot/types/primitive';
import { Enum, Option, Result, Struct, Vec } from '@polkadot/types/codec';
import { Bytes, GenericEvent, Null, Text, u32, u8 } from '@polkadot/types/primitive';
import { Digest, Hash } from '@polkadot/types/interfaces/runtime';
/** Digest */
export interface DigestOf extends Digest {}
/** Enum */
export interface DispatchError extends Enum {
/** 0:: Other */
readonly isOther: boolean;
/** 1:: CannotLookup */
readonly isCannotLookup: boolean;
/** 2:: BadOrigin */
readonly isBadOrigin: boolean;
/** 3:: Module(DispatchErrorModule) */
readonly isModule: boolean;
/** DispatchErrorModule */
readonly asModule: DispatchErrorModule;
}
/** Struct */
export interface DispatchError extends Struct {
export interface DispatchErrorModule extends Struct {
/** u8 */
readonly index: u8;
/** u8 */
readonly error: u8;
}
/** Struct */
export interface DispatchErrorTo198 extends Struct {
/** Option<u8> */
readonly module: Option<u8>;
/** u8 */
readonly error: u8;
}
/** Result<Null, DispatchError> */
export interface DispatchResult extends Result<Null, DispatchError> {
/** Error:: (DispatchError) */
readonly isError: boolean;
/** DispatchError */
readonly asError: DispatchError;
/** Ok:: */
readonly isOk: boolean;
}
/** DispatchResult */
export interface DispatchResultOf extends DispatchResult {}
/** Result<Null, Text> */
export interface DispatchResultTo198 extends Result<Null, Text> {
/** Error:: (Text) */
readonly isError: boolean;
/** Text */
readonly asError: Text;
/** Ok:: */
readonly isOk: boolean;
}
/** GenericEvent */
export interface Event extends GenericEvent {}
-1
View File
@@ -22,7 +22,6 @@ export * from './staking/types';
export * from './system/types';
export * from './treasury/types';
export * from './txpayment/types';
export * from './utility/types';
export * from './attestations/types';
export * from './claims/types';
export * from './parachains/types';
@@ -1,11 +0,0 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export default {
types: {
// This is not deprecated, only there for a short while, replaced by Result<(), DispatchError>
DispatchResult: 'Result<(), Text>',
DispatchResultOf: 'DispatchResult'
}
};
@@ -1,4 +0,0 @@
// Auto-generated via `yarn build:interfaces`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './types';
@@ -1,18 +0,0 @@
// Auto-generated via `yarn build:interfaces`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Result } from '@polkadot/types/codec';
import { Null, Text } from '@polkadot/types/primitive';
/** Result<Null, Text> */
export interface DispatchResult extends Result<Null, Text> {
/** Error:: (Text) */
readonly isError: boolean;
/** Text */
readonly asError: Text;
/** Ok:: */
readonly isOk: boolean;
}
/** DispatchResult */
export interface DispatchResultOf extends DispatchResult {}