Adapted to display moonbeam author (#3108)

* adapted to display moonbeam author

* refactor and lint

* removed comments
This commit is contained in:
Antoine Estienne
2021-01-25 18:16:41 +01:00
committed by GitHub
parent af36e3a52c
commit f6bb200146
2 changed files with 15 additions and 8 deletions
+6 -8
View File
@@ -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);
}