diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index afdd9dae7d..efc5d9f05f 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -6,7 +6,7 @@ import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageData, StorageHashe import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime'; import { InclusionHeight, Uncle, UncleEntryItem } from './interfaces/authorship'; import { RawAuraPreDigest } from './interfaces/aura'; -import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, MaybeVrf, RawBabePreDigest, RawBabePreDigest0to159, RawBabePreDigestPrimary, RawBabePreDigestPrimary0to159, RawBabePreDigestSecondary, RawBabePreDigestSecondary0to159, SlotNumber, VrfData, VrfProof } from './interfaces/babe'; +import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, MaybeVrf, RawBabePreDigest, RawBabePreDigest0to159, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimary0to159, RawBabePreDigestSecondary, RawBabePreDigestSecondary0to159, SlotNumber, VrfData, VrfProof } from './interfaces/babe'; import { BalanceLock, VestingSchedule, WithdrawReasons } from './interfaces/balances'; import { MemberCount, ProposalIndex, Votes } from './interfaces/collective'; import { AuthorityId } from './interfaces/consensus'; @@ -323,6 +323,9 @@ export interface InterfaceRegistry { RawBabePreDigestSecondary0to159: RawBabePreDigestSecondary0to159; 'Option': Option; 'Vec': Vec; + RawBabePreDigestCompat: RawBabePreDigestCompat; + 'Option': Option; + 'Vec': Vec; SlotNumber: SlotNumber; 'Compact': Compact; 'Option': Option; diff --git a/packages/types/src/interfaces/babe/definitions.ts b/packages/types/src/interfaces/babe/definitions.ts index c850fb4b92..37fd1115ce 100644 --- a/packages/types/src/interfaces/babe/definitions.ts +++ b/packages/types/src/interfaces/babe/definitions.ts @@ -44,6 +44,17 @@ export default { slotNumber: 'SlotNumber', weight: 'BabeBlockWeight' }, + // a cross old/new compatible version of the digest, that is _only_ useful + // for partial parsing and extraction of the author. This assumes that all + // entries has the authorityIndex in the first position - and that it is all + // we are interested in + RawBabePreDigestCompat: { + _enum: { + Zero: 'u32', + One: 'u32', + Two: 'u32' + } + }, SlotNumber: 'u64', VrfData: '[u8; 32]', VrfProof: '[u8; 64]' diff --git a/packages/types/src/interfaces/babe/types.ts b/packages/types/src/interfaces/babe/types.ts index f7e057cf90..60c25e2193 100644 --- a/packages/types/src/interfaces/babe/types.ts +++ b/packages/types/src/interfaces/babe/types.ts @@ -43,6 +43,22 @@ export interface RawBabePreDigest0to159 extends Enum { readonly asSecondary: RawBabePreDigestSecondary0to159; } +/** Enum */ +export interface RawBabePreDigestCompat extends Enum { + /** 0:: Zero(u32) */ + readonly isZero: boolean; + /** u32 */ + readonly asZero: u32; + /** 1:: One(u32) */ + readonly isOne: boolean; + /** u32 */ + readonly asOne: u32; + /** 2:: Two(u32) */ + readonly isTwo: boolean; + /** u32 */ + readonly asTwo: u32; +} + /** Struct */ export interface RawBabePreDigestPrimary extends Struct { /** u32 */ diff --git a/packages/types/src/primitive/Generic/ConsensusEngineId.ts b/packages/types/src/primitive/Generic/ConsensusEngineId.ts index 63868f6955..2ad12f8482 100644 --- a/packages/types/src/primitive/Generic/ConsensusEngineId.ts +++ b/packages/types/src/primitive/Generic/ConsensusEngineId.ts @@ -67,13 +67,11 @@ export default class ConsensusEngineId extends U32 { } private getBabeAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId { - const digest = createType('RawBabePreDigest', bytes.toU8a(true)); + const digest = createType('RawBabePreDigestCompat', bytes.toU8a(true)); - return sessionValidators[( - digest.isPrimary - ? digest.asPrimary - : digest.asSecondary - ).authorityIndex.toNumber()]; + return sessionValidators[ + (digest.value as U32).toNumber() + ]; } /**