merkle

package
v0.2.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package merkle contains types and functions to create and work with Merkle trees.

Index

Constants

View Source
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

func NewDynTree

func NewDynTree(initialCap int) *DynTree

NewDynTree creates a DynTree.

func (*DynTree) Add

func (t *DynTree) Add(leaf *types.Bytes32)

Add adds a leaf to the tree.

func (*DynTree) Leaf

func (t *DynTree) Leaf(index int) *types.Bytes32

Leaf returns the leaf at the specified index. Implements Tree.Leaf.

func (*DynTree) LeavesLen

func (t *DynTree) LeavesLen() int

LeavesLen returns the number of leaves. Implements Tree.LeavesLen.

func (*DynTree) Path

func (t *DynTree) Path(index int) types.Path

Path returns the path of a leaf to the Merkle root. Implements Tree.Path.

func (*DynTree) Pause

func (t *DynTree) Pause()

Pause pauses the computation of hashes.

func (*DynTree) Resume

func (t *DynTree) Resume()

Resume resumes the computation of hashes.

func (*DynTree) Root

func (t *DynTree) Root() *types.Bytes32

Root returns the Merkle root. Implements Tree.Root.

func (*DynTree) Update

func (t *DynTree) Update(index int, hash *types.Bytes32)

Update updates a leaf of the tree.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL