add hash() to tip for safety (#2145)

This commit is contained in:
Antioch Peverell
2018-12-13 13:44:50 +00:00
committed by GitHub
parent df62fd6d95
commit 7ae22eff2b
+7 -2
View File
@@ -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 {