merkleTree

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Left  = 0
	Right = 1
)

Variables

View Source
var (
	NilHash = common.FromHex("01ef55cdf3b9b0d65e6fb6317f79627534d971fd96c811281af618c0028d5e7a")
)

Functions

This section is empty.

Types

type Node

type Node struct {
	// node value
	Value []byte
	// left node
	Left *Node
	// right node
	Right *Node
	// parent node
	Parent *Node
	// height
	Height int
}

Node: node in the tree

func CreateLeafNode

func CreateLeafNode(hashVal []byte) *Node

func CreateLeaves

func CreateLeaves(hashState [][]byte) []*Node

CreateLeaves: transfer hashState to []node @hashState: hash state

type Tree

type Tree struct {
	// root Node
	RootNode *Node
	// leaves
	Leaves []*Node
	// max height
	MaxHeight int
	// nil hash tree
	NilHashValueConst [][]byte
	// hash function
	HashFunc hash.Hash
}

Tree: sparse merkle tree

func NewEmptyTree

func NewEmptyTree(maxHeight int, nilHash []byte, hFunc hash.Hash) (*Tree, error)

func NewTree

func NewTree(leaves []*Node, maxHeight int, nilHash []byte, hFunc hash.Hash) (*Tree, error)
	func: NewTree
	params: leaves []*Node, maxHeight int, nilHash []byte, hFunc hash.Hash
    desp: Use leaf nodes to initialize the tree,
          and call the BuildTree method through the root to initialize the hash value of the entire tree

func NewTreeByMap

func NewTreeByMap(leaves map[int64]*Node, maxHeight int, nilHash []byte, hFunc hash.Hash) (*Tree, error)
	func: NewTree
	params: leaves []*Node, maxHeight int, nilHash []byte, hFunc hash.Hash
    desp: Use leaf nodes to initialize the tree,
          and call the BuildTree method through the root to initialize the hash value of the entire tree

func (*Tree) BuildMerkleProofs

func (t *Tree) BuildMerkleProofs(index int64) (
	rMerkleProof [][]byte,
	rProofHelper []int,
	err error,
)

BuildMerkleProofs: construct merkle proofs

func (*Tree) BuildTree

func (t *Tree) BuildTree(nodes []*Node) (err error)

BuildTree: build sparse merkle tree

func (*Tree) HashSubTrees

func (t *Tree) HashSubTrees(l []byte, r []byte) []byte

HashSubTrees: hash sub-tree nodes

func (*Tree) InitNilHashValueConst

func (t *Tree) InitNilHashValueConst() (err error)

func (*Tree) IsEmptyTree

func (t *Tree) IsEmptyTree() bool

func (*Tree) Update

func (t *Tree) Update(index int64, nVal []byte) (err error)

func (*Tree) VerifyMerkleProofs

func (t *Tree) VerifyMerkleProofs(inclusionProofs [][]byte, helperProofs []int) bool

VerifyMerkleProofs: verify merkle proofs @inclusionProofs: inclusion proofs @helperProofs: helper function

Jump to

Keyboard shortcuts

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