use crate::tally::TallyList;
use crate::utilstring::to_hex;
#[cfg(feature = "with-serde")]
use serde::{Deserialize, Serialize};
use std::fmt;
pub type ProofHash = [u8; 32];
pub type ProofNode = (ProofHash, Option<TallyList>);
pub type ProofBranch = (Option<ProofNode>, Option<ProofNode>);
#[derive(Debug, Default, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Proof {
pub branches: Vec<ProofBranch>,
}
impl fmt::Display for Proof {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Proof {{")?;
for (left, right) in &self.branches {
let l = if let Some((hash, _tally)) = left {
to_hex(hash.as_slice()).unwrap()
} else {
"None".to_string()
};
let r = if let Some((hash, _tally)) = right {
to_hex(hash.as_slice()).unwrap()
} else {
"None".to_string()
};
writeln!(f, " ({}, {}) ", l, r)?;
}
write!(f, "}}")
}
}