Skip to content

Commit d6ebe7f

Browse files
committed
feat(core): Introduce FromBlockHeader trait
This allows us to use any subset of a `Header` to construct checkpoint data. Currently, only `BlockHash` and `Header` implement this. Chain sources can bound the checkpoint data generic to this trait, so all checkpoint data types that implement `FromBlockHeader` is supported by the chain source.
1 parent 9d7f859 commit d6ebe7f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

crates/core/src/checkpoint.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ impl<D> Drop for CPInner<D> {
5555
}
5656
}
5757

58+
/// Trait that converts [`Header`] to subset data.
59+
pub trait FromBlockHeader {
60+
/// Returns the subset data from a block `header`.
61+
fn from_blockheader(header: Header) -> Self;
62+
}
63+
64+
impl FromBlockHeader for BlockHash {
65+
fn from_blockheader(header: Header) -> Self {
66+
header.block_hash()
67+
}
68+
}
69+
70+
impl FromBlockHeader for Header {
71+
fn from_blockheader(header: Header) -> Self {
72+
header
73+
}
74+
}
75+
5876
/// Trait that converts [`CheckPoint`] `data` to [`BlockHash`].
5977
///
6078
/// Implementations of [`ToBlockHash`] must always return the block's consensus-defined hash. If
@@ -204,7 +222,7 @@ impl<D> CheckPoint<D> {
204222
// Methods where `D: ToBlockHash`
205223
impl<D> CheckPoint<D>
206224
where
207-
D: ToBlockHash + fmt::Debug + Copy,
225+
D: ToBlockHash + fmt::Debug + Clone,
208226
{
209227
const MTP_BLOCK_COUNT: u32 = 11;
210228

0 commit comments

Comments
 (0)