merkletree

package
v0.0.0-...-a0055f1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content interface {
	CalculateHash() []byte
	Equals(other Content) bool
}

Content represents the data that is stored and verified by the tree. A type that implements this interface can be used as an item in the tree.

type MerkleTree

type MerkleTree struct {
	Root *Node

	Leafs []*Node
	// contains filtered or unexported fields
}

MerkleTree is the container for the tree. It holds a pointer to the root of the tree, a list of pointers to the leaf nodes, and the merkle root.

func NewTree

func NewTree(cs []Content) (*MerkleTree, error)

NewTree creates a new Merkle Tree using the content cs.

func (*MerkleTree) MerkleRoot

func (m *MerkleTree) MerkleRoot() []byte

MerkleRoot returns the unverified Merkle Root (hash of the root node) of the tree.

func (*MerkleTree) ProvideBinaryProof

func (m *MerkleTree) ProvideBinaryProof(contentIndex int) ([]byte, error)

ProvideBinaryProof generates byte encoded proof for the element

func (*MerkleTree) ProvideBinaryProofForContent

func (m *MerkleTree) ProvideBinaryProofForContent(content Content) ([]byte, error)

func (*MerkleTree) RebuildTree

func (m *MerkleTree) RebuildTree() error

RebuildTree is a helper function that will rebuild the tree reusing only the content that it holds in the leaves.

func (*MerkleTree) RebuildTreeWith

func (m *MerkleTree) RebuildTreeWith(cs []Content) error

RebuildTreeWith replaces the content of the tree and does a complete rebuild; while the root of the tree will be replaced the MerkleTree completely survives this operation. Returns an error if the list of content cs contains no entries.

func (*MerkleTree) String

func (m *MerkleTree) String() string

String returns a string representation of the tree. Only leaf nodes are included in the output.

func (*MerkleTree) VerifyBinaryProof

func (m *MerkleTree) VerifyBinaryProof(expectedMerkleRoot []byte, proof []byte, content Content) (bool, error)

VerifyBinaryProof verifies if the content is in the tree

func (*MerkleTree) VerifyContent

func (m *MerkleTree) VerifyContent(expectedMerkleRoot []byte, content Content) bool

VerifyContent indicates whether a given content is in the tree and the hashes are valid for that content. Returns true if the expected Merkle Root is equivalent to the Merkle root calculated on the critical path for a given content. Returns true if valid and false otherwise.

func (*MerkleTree) VerifyTree

func (m *MerkleTree) VerifyTree() bool

VerifyTree verify tree validates the hashes at each level of the tree and returns true if the resulting hash at the root of the tree matches the resulting root hash; returns false otherwise.

type Node

type Node struct {
	Parent *Node
	Left   *Node
	Right  *Node

	Hash []byte
	C    Content
	// contains filtered or unexported fields
}

Node represents a node, root, or leaf in the tree. It stores pointers to its immediate relationships, a hash, the content stored if it is a leaf, and other metadata.

type PaddingContent

type PaddingContent struct {
	PaddingElement []byte
}

func NewPaddingNode

func NewPaddingNode() PaddingContent

func (PaddingContent) CalculateHash

func (t PaddingContent) CalculateHash() []byte

CalculateHash hashes the values of a TestContent

func (PaddingContent) Equals

func (t PaddingContent) Equals(other Content) bool

Equals tests for equality of two Contents

type TransactionContent

type TransactionContent struct {
	RLPEncodedTransaction []byte
}

func NewTransactionContent

func NewTransactionContent(bytes []byte) TransactionContent

func (TransactionContent) CalculateHash

func (t TransactionContent) CalculateHash() []byte

func (TransactionContent) Equals

func (t TransactionContent) Equals(other Content) bool

Jump to

Keyboard shortcuts

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