Exemple #1
0
// MerkleRoot calculates the "root hash" formed by repeatedly concatenating
// and hashing a binary tree of hashes. If the number of leaves is not a
// power of 2, the orphan hash(es) are not rehashed. Examples:
//
//       ┌───┴──┐       ┌────┴───┐         ┌─────┴─────┐
//    ┌──┴──┐   │    ┌──┴──┐     │      ┌──┴──┐     ┌──┴──┐
//  ┌─┴─┐ ┌─┴─┐ │  ┌─┴─┐ ┌─┴─┐ ┌─┴─┐  ┌─┴─┐ ┌─┴─┐ ┌─┴─┐   │
//     (5-leaf)         (6-leaf)             (7-leaf)
func MerkleRoot(leaves [][]byte) (h Hash) {
	tree := merkletree.New(NewHash())
	for _, leaf := range leaves {
		tree.Push(leaf)
	}
	copy(h[:], tree.Root())
	return
}
Exemple #2
0
// NewTree returns a tree object that can be used to get the merkle root of a
// dataset.
func NewTree() MerkleTree {
	return MerkleTree{merkletree.New(NewHash())}
}
Exemple #3
0
// NewTree returns a tree object that can be used to get the merkle root of a
// dataset.
func NewTree() tree {
	return tree{merkletree.New(NewHash())}
}