From fd443f88d2258ea9ca12f6cdfe77c2b49e3154ed Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 20 Jan 2021 17:22:13 +0100 Subject: [PATCH 1/2] modify extractAuthor to support Moonbeam --- packages/api-derive/src/type/util.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/api-derive/src/type/util.ts b/packages/api-derive/src/type/util.ts index 7904ebf16c73..0f0e171b6a70 100644 --- a/packages/api-derive/src/type/util.ts +++ b/packages/api-derive/src/type/util.ts @@ -4,23 +4,29 @@ 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'); + let author; + const citems = digest.logs.filter(({ type }) => type === 'Consensus'); - // extract from the substrate 2.0 PreRuntime digest - if (pitem) { - const [engine, data] = pitem.asPreRuntime; + if (citems.length > 0) { + citems.forEach((citem) => { + // extract author from the consensus (substrate 1.0, digest) + const [, data] = citem.asConsensus; - return engine.extractAuthor(data, sessionValidators); + if (data.length === 20) { + // This is used by Moonbeam with an h160 address for the author + author = data.toString(); + } + }); } else { - const [citem] = digest.logs.filter(({ type }) => type === 'Consensus'); + // Aura and Babe use PreRunti;e digest now + 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); + author = engine.extractAuthor(data, sessionValidators); } } - return undefined; + return author; } From 256c60a743fa2b7ce53fcff60d3ff5f309929f36 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 20 Jan 2021 17:28:06 +0100 Subject: [PATCH 2/2] typo --- packages/api-derive/src/type/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-derive/src/type/util.ts b/packages/api-derive/src/type/util.ts index 0f0e171b6a70..6d750595c210 100644 --- a/packages/api-derive/src/type/util.ts +++ b/packages/api-derive/src/type/util.ts @@ -18,7 +18,7 @@ export function extractAuthor (digest: Digest, sessionValidators: AccountId[] = } }); } else { - // Aura and Babe use PreRunti;e digest now + // Aura and Babe use PreRuntime digest now const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime'); if (pitem) {