merkletree2

package
v4.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: BSD-3-Clause, BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChildIndex

type ChildIndex uint32

ChildIndex specifies one of an iNode's child nodes.

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config defines the shape of the MerkleTree.

func NewConfig

func NewConfig(h Hasher, logChildrenPerNode uint8, valuesPerLeaf int, keysByteLength int, valueConstructor ValueConstructor) (Config, error)

NewConfig makes a new config object. It takes a a Hasher (for example sha512.Sum512), logChildrenPerNode which is the base 2 logarithm of the number of children per interior node, valuesPerLeaf the maximum number of entries in a leaf before the leaf is split into multiple nodes (at a lower level in the tree), keyByteLength the length of the Keys which the tree will store, and a valueConstructor (so that typed values can be pulled out of the Merkle Tree).

type Hash

type Hash []byte

Hash is a byte-array, used to represent a full collision-resistant hash.

type Hasher

type Hasher interface {
	Hash([]byte) Hash
}

Hasher is an interface for hashing MerkleTree data structures into their cryptographic hashes.

type InvalidConfigError

type InvalidConfigError struct {
	// contains filtered or unexported fields
}

InvalidConfigError happens when trying to construct an invalid tree configuration.

func NewInvalidConfigError

func NewInvalidConfigError(reason string) InvalidConfigError

NewInvalidConfigError returns a new error

func (InvalidConfigError) Error

func (e InvalidConfigError) Error() string

type InvalidKeyError

type InvalidKeyError struct{}

InvalidKeyError is returned when trying to use a key of the wrong length in a tree.

func NewInvalidKeyError

func NewInvalidKeyError() InvalidKeyError

NewInvalidKeyError returns a new error

func (InvalidKeyError) Error

func (e InvalidKeyError) Error() string

type Key

type Key []byte

Key is a byte-array, and it is the type of the keys in the KeyValuePairs that the tree can store.

type Position

type Position big.Int

Position represents the position of a node in the tree. When converted to bytes, a Position can be interpreted as a 1 followed (from left to right) by a sequence of log2(Config.childrenPerNode)-bit symbols, where each such symbol identifies which child to descend to in a path from the root to a node. The sequence is padded with 0s on the left to the nearest byte. For example, in a binary tree the root has position 0x01 (i.e. 0b00000001), and the second child of the first child of the root has position 0x05 (0b00000101).

type Seqno

type Seqno uint

Seqno is an integer used to differentiate different versions of a merkle tree.

type Tree

type Tree struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Tree is the MerkleTree class; it needs an engine and a configuration to run

func NewTree

func NewTree(c Config) *Tree

NewTree makes a new tree

type ValueConstructor

type ValueConstructor interface {
	// Construct a new template empty value for the leaf, so that the
	// Unmarshalling routine has the correct type template.
	Construct() interface{}
}

ValueConstructor is an interface for constructing values, so that typed values can be pulled out of the Merkle Tree. We are of course assuming that there is only one type of Value at the leaves, which makes sense.

Jump to

Keyboard shortcuts

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