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
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum BlockType {
PoS,
#[default]
PoW,
}
impl std::convert::From<bool> for BlockType {
fn from(data: bool) -> Self {
match data {
true => Self::PoS,
false => Self::PoW,
}
}
}
impl std::fmt::Display for BlockType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
serde_json::to_string(&self).unwrap().to_lowercase()
)
}
}