Adapted to display moonbeam author (#3108)
* adapted to display moonbeam author * refactor and lint * removed comments
This commit is contained in:
@@ -4,19 +4,17 @@
|
||||
import type { AccountId, Digest } from '@polkadot/types/interfaces';
|
||||
|
||||
export function extractAuthor (digest: Digest, sessionValidators: AccountId[] = []): AccountId | undefined {
|
||||
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
|
||||
const [citem] = digest.logs.filter(({ type }) => type === 'Consensus');
|
||||
|
||||
// extract from the substrate 2.0 PreRuntime digest
|
||||
if (pitem) {
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
if (citem) {
|
||||
const [engine, data] = citem.asConsensus;
|
||||
|
||||
return engine.extractAuthor(data, sessionValidators);
|
||||
} else {
|
||||
const [citem] = digest.logs.filter(({ type }) => type === 'Consensus');
|
||||
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
|
||||
|
||||
// extract author from the consensus (substrate 1.0, digest)
|
||||
if (citem) {
|
||||
const [engine, data] = citem.asConsensus;
|
||||
if (pitem) {
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
return engine.extractAuthor(data, sessionValidators);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,10 @@ export class GenericConsensusEngineId extends u32 {
|
||||
return this.registry.createType('AccountId', bytes);
|
||||
}
|
||||
|
||||
private _getH160Author (bytes: Bytes): AccountId {
|
||||
return this.registry.createType('AccountId', bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the input bytes, decode into an author
|
||||
*/
|
||||
@@ -104,6 +108,11 @@ export class GenericConsensusEngineId extends u32 {
|
||||
return this._getPowAuthor(bytes);
|
||||
}
|
||||
|
||||
// Moonbeam is neither Aura nor Babe nor Pow and uses h160 addresses
|
||||
if (bytes.length === 20) {
|
||||
return this._getH160Author(bytes);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user