1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
mod txbuilder;
use std::str::FromStr;
use thiserror::Error;
use tmelcrypt::HashVal;
pub use txbuilder::*;
mod units;
pub use units::*;
mod constants;
pub use constants::*;
mod transaction;
pub use transaction::*;
mod stake;
pub use stake::*;
mod melswap;
pub use melswap::*;
mod header;
pub use header::*;
#[derive(Debug, Clone)]
pub struct Checkpoint {
pub height: BlockHeight,
pub header_hash: HashVal,
}
#[derive(Error, Debug)]
pub enum ParseCheckpointError {
#[error("expected a ':' character to split the height and header hash")]
ParseSplitError,
#[error("height is not an integer")]
ParseIntError(#[from] std::num::ParseIntError),
#[error("failed to parse header hash as a hash")]
ParseHeaderHash(#[from] hex::FromHexError),
}
impl FromStr for Checkpoint {
type Err = ParseCheckpointError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (height_str, hash_str) = s
.split_once(':')
.ok_or(ParseCheckpointError::ParseSplitError)?;
let height = BlockHeight::from_str(height_str)?;
let header_hash = HashVal::from_str(hash_str)?;
Ok(Self {
height,
header_hash,
})
}
}