stratus/eth/primitives/
difficulty.rs1use alloy_primitives::U256;
2use display_json::DebugAsJson;
3#[cfg(test)]
4use fake::Dummy;
5#[cfg(test)]
6use fake::Faker;
7
8#[derive(DebugAsJson, derive_more::Display, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
9#[serde(transparent)]
10pub struct Difficulty(pub U256);
11
12#[cfg(test)]
13impl Dummy<Faker> for Difficulty {
14 fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
15 rng.next_u64().into()
16 }
17}
18
19impl From<u8> for Difficulty {
24 fn from(value: u8) -> Self {
25 Self(U256::from(value))
26 }
27}
28
29impl From<u16> for Difficulty {
30 fn from(value: u16) -> Self {
31 Self(U256::from(value))
32 }
33}
34
35impl From<u32> for Difficulty {
36 fn from(value: u32) -> Self {
37 Self(U256::from(value))
38 }
39}
40
41impl From<u64> for Difficulty {
42 fn from(value: u64) -> Self {
43 Self(U256::from(value))
44 }
45}
46
47impl From<u128> for Difficulty {
48 fn from(value: u128) -> Self {
49 Self(U256::from(value))
50 }
51}
52
53impl From<U256> for Difficulty {
54 fn from(value: U256) -> Self {
55 Self(value)
56 }
57}
58
59impl From<usize> for Difficulty {
60 fn from(value: usize) -> Self {
61 Self(U256::from(value))
62 }
63}
64
65impl From<i32> for Difficulty {
66 fn from(value: i32) -> Self {
67 Self(U256::from(value as u32))
68 }
69}
70
71impl From<[u64; 4]> for Difficulty {
72 fn from(value: [u64; 4]) -> Self {
73 Self(U256::from_limbs(value))
74 }
75}