From 7ae22eff2ba38338633ae72a5f817efba9b1158c Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Thu, 13 Dec 2018 13:44:50 +0000 Subject: [PATCH] add hash() to tip for safety (#2145) --- chain/src/types.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chain/src/types.rs b/chain/src/types.rs index 9a6ced64a..7e784b809 100644 --- a/chain/src/types.rs +++ b/chain/src/types.rs @@ -64,8 +64,7 @@ pub struct Tip { } impl Tip { - /// TODO - why do we have Tip when we could just use a block header? - /// Creates a new tip based on header. + /// Creates a new tip based on provided header. pub fn from_header(header: &BlockHeader) -> Tip { Tip { height: header.height, @@ -74,6 +73,12 @@ impl Tip { total_difficulty: header.total_difficulty(), } } + + /// *Really* easy to accidentally call hash() on a tip (thinking its a header). + /// So lets make hash() do the right thing here. + pub fn hash(&self) -> Hash { + self.last_block_h + } } impl Default for Tip {