From af074500b6c9d11236c16538de8389860bd61402 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 20 Sep 2020 18:00:21 +0200 Subject: [PATCH] Add support to extract PoW author (#2627) * Add PoW engine ID and author fetching logic * Fix Pow CID order --- .../types/src/generic/ConsensusEngineId.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/types/src/generic/ConsensusEngineId.ts b/packages/types/src/generic/ConsensusEngineId.ts index f44b0c8220..ecd2ee7fdd 100644 --- a/packages/types/src/generic/ConsensusEngineId.ts +++ b/packages/types/src/generic/ConsensusEngineId.ts @@ -12,8 +12,9 @@ import U32 from '../primitive/U32'; const CID_AURA = 0x61727561; // 'aura' const CID_BABE = 0x45424142; // 'BABE' const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1) +const CID_POW = 0x5f776f70; // 'pow_' -export { CID_AURA, CID_BABE, CID_GRPA }; +export { CID_AURA, CID_BABE, CID_GRPA, CID_POW }; /** * @name ConsensusEngineId @@ -56,6 +57,13 @@ export default class ConsensusEngineId extends U32 { return this.eq(CID_GRPA); } + /** + * @description `true` is the engine matches pow + */ + public get isPow (): boolean { + return this.eq(CID_POW); + } + private _getAuraAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId { return sessionValidators[ this.registry.createType('RawAuraPreDigest', bytes.toU8a(true)) @@ -73,6 +81,10 @@ export default class ConsensusEngineId extends U32 { ]; } + private _getPowAuthor (bytes: Bytes): AccountId { + return this.registry.createType('AccountId', bytes); + } + /** * @description From the input bytes, decode into an author */ @@ -85,6 +97,10 @@ export default class ConsensusEngineId extends U32 { } } + if (this.isPow) { + return this._getPowAuthor(bytes); + } + return undefined; }