use moonproof_ledger::serialize::Serializable;
use super::DustState;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DustTreeRoots {
pub commitment: String,
pub generation: String,
}
impl DustTreeRoots {
#[must_use]
pub fn of(state: &DustState) -> Self {
let local = state.local();
Self {
commitment: encode(local.commitment_tree.root()),
generation: encode(local.generating_tree.root()),
}
}
}
fn encode<T: Serializable>(root: Option<T>) -> String {
root.map_or_else(String::new, |root| {
let mut bytes = Vec::with_capacity(root.serialized_size());
root.serialize(&mut bytes)
.expect("serializing into a Vec cannot fail");
hex::encode(bytes)
})
}