Skip to content

Commit dcde237

Browse files
authored
Merge pull request #545 from rustaceanrob/26-3-6-cp-ord
Implement ordinality traits for `HeaderCheckpoint`
2 parents 114592d + ace8952 commit dcde237

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/chain/checkpoints.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::{constants::genesis_block, params::Params, BlockHash};
55
type Height = u32;
66

77
/// A known block hash in the chain of most work.
8-
#[derive(Debug, Clone, Copy)]
8+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
99
pub struct HeaderCheckpoint {
1010
/// The index of the block hash.
1111
pub height: Height,
@@ -45,6 +45,18 @@ impl HeaderCheckpoint {
4545
}
4646
}
4747

48+
impl std::cmp::PartialOrd for HeaderCheckpoint {
49+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
50+
Some(self.cmp(other))
51+
}
52+
}
53+
54+
impl std::cmp::Ord for HeaderCheckpoint {
55+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
56+
self.height.cmp(&other.height)
57+
}
58+
}
59+
4860
impl From<(u32, BlockHash)> for HeaderCheckpoint {
4961
fn from(value: (u32, BlockHash)) -> Self {
5062
HeaderCheckpoint::new(value.0, value.1)

0 commit comments

Comments
 (0)