From 783db16cea438391a4c6bd6f00e2a039f5218ccf Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 8 Jan 2019 13:18:09 +0100 Subject: [PATCH] Consistency in exposing header hashes (#546) * Consistency in exposing header hashes * Cleanup comments --- packages/types/src/Block.ts | 27 +++++++++++++++++---------- packages/types/src/SignedBlock.ts | 8 ++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/types/src/Block.ts b/packages/types/src/Block.ts index 15d7fb245b..021ea0bab1 100644 --- a/packages/types/src/Block.ts +++ b/packages/types/src/Block.ts @@ -30,23 +30,30 @@ export default class Block extends Struct { } /** - * @description The [[Extrinsics]] conatined in the block + * @description Encodes a content [[Hash]] for the block */ - get extrinsics (): Extrinsics { - return this.get('extrinsics') as Extrinsics; - } - - /** - * @description Coinvenience getter, encoded the [[Hash]] for the block - */ - get hash (): Hash { + get contentHash (): Hash { return new Hash( blake2AsU8a(this.toU8a(), 256) ); } /** - * @description The [[Header]] in the block + * @description The [[Extrinsics]] contained in the block + */ + get extrinsics (): Extrinsics { + return this.get('extrinsics') as Extrinsics; + } + + /** + * @description Block/header [[Hash]] + */ + get hash (): Hash { + return this.header.hash; + } + + /** + * @description The [[Header]] of the block */ get header (): Header { return this.get('header') as Header; diff --git a/packages/types/src/SignedBlock.ts b/packages/types/src/SignedBlock.ts index 92df73c042..9ebdf724ec 100644 --- a/packages/types/src/SignedBlock.ts +++ b/packages/types/src/SignedBlock.ts @@ -6,6 +6,7 @@ import { AnyU8a } from './types'; import Struct from './codec/Struct'; import Block, { BlockValue } from './Block'; +import Hash from './Hash'; import Justification from './Justification'; type SignedBlockValue = { @@ -33,6 +34,13 @@ export default class SignedBlock extends Struct { return this.get('block') as Block; } + /** + * @description Block/header [[Hash]] + */ + get hash (): Hash { + return this.block.hash; + } + /** * @description The wrapped [[Justification]] */