/// Generate a proof-of-inclusion for the leaf node at the specified `index`.
Generate a proof-of-inclusion for the leaf node at the specified `index`.
Generate a proof - of - inclusion for the leaf node at the specified ` index ` .
pub fn compute_merkle_proof<D, L>(leaves: &[L], index: usize) -> Option<Proof<D>>
where
  D: DigestExt,
  L: AsLeaf<D>,
{
  #[inline]
  fn __generate<D, L>(digest: &mut D, path: &mut Vec<Node<D>>, leaves: &[L], index: usize)
  where
    D: DigestExt,
    L: AsLeaf<D>,
  {
    if leaves.len() > 1 {
      let k: usize = __pow2(leaves.len() as u32 - 1);
      let (this, that): _ = leaves.split_at(k);
      if index < k {
        __generate::<D, L>(digest, path, this, index);
        path.push(Node::R(compute_merkle_root::<D, L>(that)));
      } else {
        __generate::<D, L>(digest, path, that, index - k);
        path.push(Node::L(compute_merkle_root::<D, L>(this)));
      }
    }
  }
  match (index, leaves.len()) {
    (_, 0) => None,
    (0, 1) => Some(Proof::new(Box::new([]))),
    (_, 1) => None,
    (index, length) => {
      if index >= length {
        return None;
      }
      // TODO: Support proofs for any number of leaves
      if !length.is_power_of_two() {
        return None;
      }
      let height: usize = __log2c(leaves.len() as u32) as usize;
      let mut path: Vec<Node<D>> = Vec::with_capacity(height);
      __generate(&mut D::new(), &mut path, leaves, index);
      Some(Proof::new(path.into_boxed_slice()))
    }
  }
}
pub fn compute_merkle_proof < D , L > ( leaves : & [ L ] , index : usize ) -> Option < Proof < D > > where D : DigestExt , L : AsLeaf < D > , { # [ inline ] fn __generate < D , L > ( digest : & mut D , path : & mut Vec < Node < D > > , leaves : & [ L ] , index : usize ) where D : DigestExt , L : AsLeaf < D > , { if leaves . len ( ) > 1 { let k : usize = __pow2 ( leaves . len ( ) as u32 - 1 ) ; let ( this , that ) : _ = leaves . split_at ( k ) ; if index < k { __generate :: < D , L > ( digest , path , this , index ) ; path . push ( Node :: R ( compute_merkle_root :: < D , L > ( that ) ) ) ; } else { __generate :: < D , L > ( digest , path , that , index - k ) ; path . push ( Node :: L ( compute_merkle_root :: < D , L > ( this ) ) ) ; } } } match ( index , leaves . len ( ) ) { ( _ , 0 ) => None , ( 0 , 1 ) => Some ( Proof :: new ( Box :: new ( [ ] ) ) ) , ( _ , 1 ) => None , ( index , length ) => { if index >= length { return None ; } // TODO: Support proofs for any number of leaves if ! length . is_power_of_two ( ) { return None ; } let height : usize = __log2c ( leaves . len ( ) as u32 ) as usize ; let mut path : Vec < Node < D > > = Vec :: with_capacity ( height ) ; __generate ( & mut D :: new ( ) , & mut path , leaves , index ) ; Some ( Proof :: new ( path . into_boxed_slice ( ) ) ) } } }
Generate a proof-of-inclusion for the leaf node at the specified `index`.
Generate a proof - of - inclusion for the leaf node at the specified ` index ` .
leaves
&[L]
index
usize