fuel_core_interfaces/model/
da_block_height.rs

1use derive_more::{
2    Add,
3    Deref,
4    Display,
5    From,
6    Into,
7    Rem,
8    Sub,
9};
10use std::ops::Add;
11
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13#[derive(
14    Sub,
15    Copy,
16    Clone,
17    Debug,
18    Default,
19    PartialEq,
20    PartialOrd,
21    Eq,
22    Add,
23    Ord,
24    Display,
25    Into,
26    From,
27    Rem,
28    Deref,
29    Hash,
30)]
31#[rem(forward)]
32pub struct DaBlockHeight(pub u64);
33
34impl From<DaBlockHeight> for Vec<u8> {
35    fn from(height: DaBlockHeight) -> Self {
36        height.0.to_be_bytes().to_vec()
37    }
38}
39
40impl From<usize> for DaBlockHeight {
41    fn from(n: usize) -> Self {
42        DaBlockHeight(n as u64)
43    }
44}
45
46impl Add<u64> for DaBlockHeight {
47    type Output = Self;
48
49    fn add(self, other: u64) -> Self::Output {
50        Self::from(self.0 + other)
51    }
52}
53
54impl DaBlockHeight {
55    pub fn to_bytes(self) -> [u8; 8] {
56        self.0.to_be_bytes()
57    }
58
59    pub fn to_usize(self) -> usize {
60        self.0 as usize
61    }
62
63    pub fn as_usize(&self) -> usize {
64        self.0 as usize
65    }
66
67    pub fn as_u64(&self) -> u64 {
68        self.0
69    }
70}