Skip to main content

mrklt/
proof.rs

1use super::merge::Merge;
2
3/// A Merkle proof is a list of ProofElement.
4#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum ProofElem<T> {
7    Left(T),
8    Right(T),
9}
10
11impl<T> ProofElem<T> {
12    pub fn merge<M: Merge<Hash = T>>(&self, sibling: &M::Hash) -> M::Hash {
13        match self {
14            Self::Left(l) => M::merge(l, sibling),
15            Self::Right(r) => M::merge(sibling, r),
16        }
17    }
18}
19
20impl<T> ProofElem<&T> {
21    pub fn cloned(self) -> ProofElem<T>
22    where
23        T: Clone,
24    {
25        match self {
26            Self::Left(l) => ProofElem::Left(l.clone()),
27            Self::Right(r) => ProofElem::Left(r.clone()),
28        }
29    }
30}