@@ -8,7 +8,9 @@ import { Keys, SessionIndex, SessionKeysPolkadot, SessionKeysSubstrate } from '.
|
||||
import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa';
|
||||
import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from './interfaces/elections';
|
||||
import { InclusionHeight, Uncle, UncleEntryItem } from './interfaces/authorship';
|
||||
import { RawAuraPreDigest } from './interfaces/aura';
|
||||
import { BabeWeight, RawBabePreDigest, SlotNumber } from './interfaces/babe';
|
||||
import { RawAuraBorosPreDigest } from './interfaces/abrs';
|
||||
import { BalanceLock, VestingSchedule, WithdrawReasons } from './interfaces/balances';
|
||||
import { MemberCount, ProposalIndex, Votes } from './interfaces/collective';
|
||||
import { AliveContractInfo, CodeHash, ContractInfo, ContractStorageKey, Gas, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, SeedOf, TombstoneContractInfo, TrieId } from './interfaces/contracts';
|
||||
@@ -311,6 +313,9 @@ export interface InterfaceRegistry {
|
||||
UncleEntryItem: UncleEntryItem;
|
||||
'Option<UncleEntryItem>': Option<UncleEntryItem>;
|
||||
'Vec<UncleEntryItem>': Vec<UncleEntryItem>;
|
||||
RawAuraPreDigest: RawAuraPreDigest;
|
||||
'Option<RawAuraPreDigest>': Option<RawAuraPreDigest>;
|
||||
'Vec<RawAuraPreDigest>': Vec<RawAuraPreDigest>;
|
||||
BabeWeight: BabeWeight;
|
||||
'Compact<BabeWeight>': Compact<BabeWeight>;
|
||||
'Option<BabeWeight>': Option<BabeWeight>;
|
||||
@@ -322,6 +327,9 @@ export interface InterfaceRegistry {
|
||||
RawBabePreDigest: RawBabePreDigest;
|
||||
'Option<RawBabePreDigest>': Option<RawBabePreDigest>;
|
||||
'Vec<RawBabePreDigest>': Vec<RawBabePreDigest>;
|
||||
RawAuraBorosPreDigest: RawAuraBorosPreDigest;
|
||||
'Option<RawAuraBorosPreDigest>': Option<RawAuraBorosPreDigest>;
|
||||
'Vec<RawAuraBorosPreDigest>': Vec<RawAuraBorosPreDigest>;
|
||||
VestingSchedule: VestingSchedule;
|
||||
'Option<VestingSchedule>': Option<VestingSchedule>;
|
||||
'Vec<VestingSchedule>': Vec<VestingSchedule>;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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: {
|
||||
RawAuraBorosPreDigest: {
|
||||
_enum: {
|
||||
Aura: 'RawAuraPreDigest',
|
||||
Babe: 'RawBabePreDigest'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,17 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum } from '../../codec';
|
||||
import { RawAuraPreDigest } from '../aura';
|
||||
import { RawBabePreDigest } from '../babe';
|
||||
|
||||
/** Enum */
|
||||
export interface RawAuraBorosPreDigest extends Enum {
|
||||
/** 0:: Aura(RawAuraPreDigest) */
|
||||
readonly isAura: boolean;
|
||||
/** RawAuraPreDigest */
|
||||
readonly asAura: RawAuraPreDigest;
|
||||
/** 1:: Babe(RawBabePreDigest) */
|
||||
readonly isBabe: boolean;
|
||||
/** RawBabePreDigest */
|
||||
readonly asBabe: RawBabePreDigest;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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: {
|
||||
RawAuraPreDigest: {
|
||||
slotNumber: 'u64'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,10 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Struct } from '../../codec';
|
||||
import { u64 } from '../../primitive';
|
||||
|
||||
/** Struct */
|
||||
export interface RawAuraPreDigest extends Struct {
|
||||
/** u64 */
|
||||
readonly slotNumber: u64;
|
||||
}
|
||||
@@ -21,9 +21,13 @@ export { default as grandpa } from './grandpa/definitions';
|
||||
// elections before democracy
|
||||
export { default as elections } from './elections/definitions';
|
||||
|
||||
// remaining, alphabetical odering
|
||||
// authoring, abra uses babe & aura
|
||||
export { default as authorship } from './authorship/definitions';
|
||||
export { default as aura } from './aura/definitions';
|
||||
export { default as babe } from './babe/definitions';
|
||||
export { default as abrs } from './abrs/definitions';
|
||||
|
||||
// remaining, alphabetical odering
|
||||
export { default as balances } from './balances/definitions';
|
||||
export { default as collective } from './collective/definitions';
|
||||
export { default as contracts } from './contracts/definitions';
|
||||
|
||||
@@ -6,7 +6,9 @@ export * from './session/types';
|
||||
export * from './grandpa/types';
|
||||
export * from './elections/types';
|
||||
export * from './authorship/types';
|
||||
export * from './aura/types';
|
||||
export * from './babe/types';
|
||||
export * from './abrs/types';
|
||||
export * from './balances/types';
|
||||
export * from './collective/types';
|
||||
export * from './contracts/types';
|
||||
|
||||
@@ -10,13 +10,13 @@ import { bnToBn } from '@polkadot/util';
|
||||
import createType from '../../codec/createType';
|
||||
import Bytes from '../Bytes';
|
||||
import U32 from '../U32';
|
||||
import U64 from '../U64';
|
||||
|
||||
const CID_ABRS = 0x53524241; // 'ABRS'
|
||||
const CID_AURA = 0x61727561; // 'aura'
|
||||
const CID_BABE = 0x45424142; // 'BABE'
|
||||
const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1)
|
||||
|
||||
export { CID_AURA, CID_BABE, CID_GRPA };
|
||||
export { CID_ABRS, CID_AURA, CID_BABE, CID_GRPA };
|
||||
|
||||
/**
|
||||
* @name ConsensusEngineId
|
||||
@@ -38,6 +38,13 @@ export default class ConsensusEngineId extends U32 {
|
||||
.reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches abrs
|
||||
*/
|
||||
public get isAbrs (): boolean {
|
||||
return this.eq(CID_ABRS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches aura
|
||||
*/
|
||||
@@ -59,19 +66,42 @@ export default class ConsensusEngineId extends U32 {
|
||||
return this.eq(CID_GRPA);
|
||||
}
|
||||
|
||||
private getAbrsAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
const pre = createType('RawAuraBorosPreDigest', bytes.toU8a(true));
|
||||
|
||||
return sessionValidators[
|
||||
pre.isBabe
|
||||
? pre.asBabe.authorityIndex.toNumber()
|
||||
: pre.asAura.slotNumber.modn(sessionValidators.length)
|
||||
];
|
||||
}
|
||||
|
||||
private getAuraAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
return sessionValidators[
|
||||
createType('RawAuraPreDigest', bytes.toU8a(true))
|
||||
.slotNumber
|
||||
.modn(sessionValidators.length)
|
||||
];
|
||||
}
|
||||
|
||||
private getBabeAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
return sessionValidators[
|
||||
createType('RawBabePreDigest', bytes.toU8a(true))
|
||||
.authorityIndex
|
||||
.toNumber()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the input bytes, decode into an author
|
||||
*/
|
||||
public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
if (this.isAura) {
|
||||
// TODO We really want proper decoding of the digest as below (i.e. via type)
|
||||
return sessionValidators[
|
||||
new U64(bytes.toU8a(true).subarray(0, 8)).modn(sessionValidators.length)
|
||||
];
|
||||
if (this.isAbrs) {
|
||||
return this.getAbrsAuthor(bytes, sessionValidators);
|
||||
} else if (this.isAura) {
|
||||
return this.getAuraAuthor(bytes, sessionValidators);
|
||||
} else if (this.isBabe) {
|
||||
return sessionValidators[
|
||||
createType('RawBabePreDigest', bytes.toU8a(true)).authorityIndex.toNumber()
|
||||
];
|
||||
return this.getBabeAuthor(bytes, sessionValidators);
|
||||
}
|
||||
|
||||
throw new Error('Invalid engine for extractAuthor conversion');
|
||||
|
||||
Reference in New Issue
Block a user