melstructs/
lib.rs

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