Add support to extract PoW author (#2627)

* Add PoW engine ID and author fetching logic

* Fix Pow CID order
This commit is contained in:
Wei Tang
2020-09-20 18:00:21 +02:00
committed by GitHub
parent 5e2a1753af
commit af074500b6
@@ -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;
}