6 个版本
| 0.3.3 | 2021年7月12日 | 
|---|---|
| 0.3.2 | 2021年7月10日 | 
| 0.2.1 | 2021年7月9日 | 
| 0.1.0 | 2021年7月8日 | 
在 数据结构 中排名 1549
19KB
387 行
排除完全二叉 Merkle 树
基于 Nervos 完全二叉 Merkle 树 的 Merkle 树,用于支持验证一个叶子不在某个树中。
示例用法
type StrKey = &'static str;
type StrLeaf = SimpleLeaf<StrKey>;
type StrRangeLeaf = SimpleRangeLeaf<StrKey, Blake2bHasher>;
// A helper to compute root and build proof
type StrExCBMT = SimpleExclusionCBMT<StrKey, Blake2bHasher, MergeBlake2bH256>;
// Can be seen as a black list
let all_leaves: Vec<StrLeaf> = vec!["b", "e", "g", "x"]
    .into_iter()
    .map(StrLeaf::new_with_key)
    .collect();
let root = StrExCBMT::compute_root(&all_leaves);
// The keys not in the black list
let excluded_keys = vec!["f", "y", "z", "a"];
let proof = StrExCBMT::build_proof(&all_leaves, &excluded_keys).unwrap();
assert_eq!(
    proof
        .range_leaves()
        .iter()
        .map(|l| (*l.key(), *l.next_key()))
        .collect::<Vec<_>>(),
    vec![("e", "g"), ("x", "b")]
);
assert!(proof
    .verify_exclusion(&root, &excluded_keys)
    .is_ok());
依赖项
~27KB