algae_mmr/cmp/
nodes.rs

1/*
2    Appellation: cmps <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4    Description: ... summary ...
5*/
6
7use decanter::prelude::{Hashable, H256};
8use serde::{Deserialize, Serialize};
9use std::convert::From;
10
11#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
12pub struct Node {
13    pub hash: H256,
14    pub pruned: bool,
15}
16
17impl Node {
18    pub fn new(hash: H256, pruned: bool) -> Node {
19        Node { hash, pruned }
20    }
21    pub fn prune(&mut self) {
22        self.pruned = true;
23    }
24    pub fn is_pruned(&self) -> bool {
25        self.pruned
26    }
27}
28
29impl Hashable for Node {
30    fn hash(&self) -> H256 {
31        self.hash
32    }
33}
34
35impl std::fmt::Display for Node {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        write!(f, "{}", self.hash)
38    }
39}
40
41impl From<H256> for Node {
42    fn from(data: H256) -> Self {
43        Self::new(data, false)
44    }
45}