]> Untitled Git - bdk/commitdiff
feat(core): Add `prev_blockhash` method to `ToBlockHash` trait
author志宇 <hello@evanlinjin.me>
Fri, 9 Jan 2026 09:09:03 +0000 (17:09 +0800)
committer志宇 <hello@evanlinjin.me>
Wed, 22 Apr 2026 04:48:17 +0000 (04:48 +0000)
crates/core/src/checkpoint.rs

index 0a394122a0913009e33ab20b91213c2d27b7011a..edb420dc06d1de40591d672804f07a3c918e6b9d 100644 (file)
@@ -65,6 +65,11 @@ impl<D> Drop for CPInner<D> {
 pub trait ToBlockHash {
     /// Returns the [`BlockHash`] for the associated [`CheckPoint`] `data` type.
     fn to_blockhash(&self) -> BlockHash;
+
+    /// Returns `None` if the type has no knowledge of the previous [`BlockHash`].
+    fn prev_blockhash(&self) -> Option<BlockHash> {
+        None
+    }
 }
 
 impl ToBlockHash for BlockHash {
@@ -77,6 +82,10 @@ impl ToBlockHash for Header {
     fn to_blockhash(&self) -> BlockHash {
         self.block_hash()
     }
+
+    fn prev_blockhash(&self) -> Option<BlockHash> {
+        Some(self.prev_blockhash)
+    }
 }
 
 /// Trait that extracts a block time from [`CheckPoint`] `data`.