pub fn merkle_add(
db_info: DbHandle,
db_roots: DbHandle,
root_key: &[u8],
tree_key: &[u8],
elements: &[MerkleNode],
) -> GenericResult<()>
Expand description
Add given elements into a Merkle tree. Used for inclusion proofs.
db_info
is a handle for a database where the Merkle tree is stored.db_roots
is a handle for a database where all the new Merkle roots are stored.root_key
is the serialized key pointing to the latest Merkle root indb_info
tree_key
is the serialized key pointing to the Merkle tree indb_info
.elements
are the items we want to add to the Merkle tree.
There are 2 databases:
db_info
stores general metadata or info.db_roots
stores a log of all the merkle roots.
Inside db_info
we store:
- The [latest root hash:32] under
root_key
. - The incremental merkle tree under
tree_key
.
Inside db_roots
we store:
- All [merkle root:32]s as keys. The value is the current [tx_hash:32][call_idx:1]. If no new values are added, then the root key is updated to the current (tx_hash, call_idx).