Documentation
¶
Overview ¶
Package merkle contains types and functions to create and work with Merkle trees.
Index ¶
- Constants
- type DynTree
- func (t *DynTree) Add(leaf *types.Bytes32)
- func (t *DynTree) Leaf(index int) *types.Bytes32
- func (t *DynTree) LeavesLen() int
- func (t *DynTree) Path(index int) types.Path
- func (t *DynTree) Pause()
- func (t *DynTree) Resume()
- func (t *DynTree) Root() *types.Bytes32
- func (t *DynTree) Update(index int, hash *types.Bytes32)
- type DynTreeNode
- type StaticTree
- type Tree
Constants ¶
const ( // HashByteSize is the length of a hash or leaf measured in bytes. HashByteSize = types.Bytes32Size )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynTree ¶
type DynTree struct {
// contains filtered or unexported fields
}
DynTree is designed for Merkle trees that can mutate. It supports pausing/resuming the computation of hashes, which is useful when adding a large number of leaves to the tree to gain more performance
type DynTreeNode ¶
type DynTreeNode struct {
// contains filtered or unexported fields
}
DynTreeNode is a node within a DynTree.
func (*DynTreeNode) Hash ¶
func (n *DynTreeNode) Hash() *types.Bytes32
Hash returns the hash of the node.
func (*DynTreeNode) Left ¶
func (n *DynTreeNode) Left() *DynTreeNode
Left returns the node to the left, if any.
func (*DynTreeNode) Parent ¶
func (n *DynTreeNode) Parent() *DynTreeNode
Parent returns the parent node, if any.
func (*DynTreeNode) Right ¶
func (n *DynTreeNode) Right() *DynTreeNode
Right returns the node to the right, if any.
type StaticTree ¶
type StaticTree struct {
// contains filtered or unexported fields
}
StaticTree is designed for Merkle trees with leaves that do not change. It is ideal when computing a tree from a batch of hashes.
func NewStaticTree ¶
func NewStaticTree(leaves []types.Bytes32) (*StaticTree, error)
NewStaticTree creates a static Merkle tree from a slice of leaves.
func (*StaticTree) Leaf ¶
func (t *StaticTree) Leaf(index int) *types.Bytes32
Leaf returns the leaf at the specified index. Implements Tree.Leaf.
func (*StaticTree) LeavesLen ¶
func (t *StaticTree) LeavesLen() int
LeavesLen returns the number of leaves. Implements Tree.LeavesLen.
func (*StaticTree) Path ¶
func (t *StaticTree) Path(index int) types.Path
Path returns the path of a leaf to the Merkle root. Implements Tree.Path.
func (*StaticTree) Root ¶
func (t *StaticTree) Root() *types.Bytes32
Root returns the Merkle root. Implements Tree.Root.
type Tree ¶
type Tree interface { // LeavesLen returns the number of leaves. LeavesLen() int // Root returns the Merkle root. Root() *types.Bytes32 // Leaf returns the leaf at the specified index. Leaf(index int) *types.Bytes32 // Path returns the path of a leaf to the Merkle root. Path(index int) types.Path }
Tree must be implemented by Merkle tree implementations.
Directories
¶
Path | Synopsis |
---|---|
Package treetestcases contains test cases to test Merkle tree implementation.
|
Package treetestcases contains test cases to test Merkle tree implementation. |