stratus/eth/primitives/
miner_nonce.rs

1use alloy_primitives::B64;
2use display_json::DebugAsJson;
3use fake::Dummy;
4use fake::Faker;
5
6/// The nonce of an Ethereum block.
7#[derive(DebugAsJson, derive_more::Display, Clone, Copy, Default, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
8pub struct MinerNonce(B64);
9
10impl Dummy<Faker> for MinerNonce {
11    fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
12        B64::random_with(rng).into()
13    }
14}
15
16// -----------------------------------------------------------------------------
17// Conversions: Other -> Self
18// -----------------------------------------------------------------------------
19
20impl From<B64> for MinerNonce {
21    fn from(value: B64) -> Self {
22        Self(value)
23    }
24}
25
26impl From<[u8; 8]> for MinerNonce {
27    fn from(value: [u8; 8]) -> Self {
28        Self(B64::from(value))
29    }
30}
31
32// -----------------------------------------------------------------------------
33// Conversions: Self -> Other
34// -----------------------------------------------------------------------------
35impl From<MinerNonce> for B64 {
36    fn from(value: MinerNonce) -> Self {
37        value.0
38    }
39}
40
41impl From<MinerNonce> for [u8; 8] {
42    fn from(value: MinerNonce) -> Self {
43        B64::from(value).0
44    }
45}