go-merkletree: github.com/arnaucube/go-merkletree Index | Files

package merkletree

import "github.com/arnaucube/go-merkletree"

Index

Package Files

db.go merkletree.go node.go print.go utils.go

Constants

const (
    // EmptyNodeType indicates the type of an EmptyNodeValue Node
    EmptyNodeType = 00
)

Variables

var (
    // ErrNodeAlreadyExists is an error that indicates that a node already exists in the merkletree database
    ErrNodeAlreadyExists = errors.New("node already exists")

    // EmptyNodeValue is a [32]byte EmptyNodeValue array, all to zero
    EmptyNodeValue = Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)

func BytesToHex Uses

func BytesToHex(bs []byte) string

BytesToHex encodes an array of bytes into a string in hex.

func BytesToUint32 Uses

func BytesToUint32(b []byte) uint32

BytesToUint32 returns a uint32 from a byte array

func CheckProof Uses

func CheckProof(root Hash, proof []byte, hi Hash, ht Hash, numLevels int) bool

CheckProof validates the Merkle Proof for the leafHash and root

func HexToBytes Uses

func HexToBytes(h string) ([]byte, error)

HexToBytes decodes a hex string into an array of bytes.

func Uint32ToBytes Uses

func Uint32ToBytes(u uint32) []byte

Uint32ToBytes returns a byte array from a uint32

type Hash Uses

type Hash [32]byte

Hash used in this tree, is the [32]byte keccak()

func HashBytes Uses

func HashBytes(b []byte) (hash Hash)

HashBytes performs a Keccak256 hash over the bytes

func (Hash) Bytes Uses

func (hash Hash) Bytes() []byte

Bytes returns a byte array from a Hash

func (Hash) Hex Uses

func (hash Hash) Hex() string

Hex returns a hex string from the Hash type

type MerkleTree Uses

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

MerkleTree struct with the main elements of the Merkle Tree

func New Uses

func New(storage *leveldb.DB, numLevels int) (*MerkleTree, error)

New generates a new Merkle Tree

func (*MerkleTree) Add Uses

func (mt *MerkleTree) Add(v Value) error

Add adds the leaf to the MT

func (*MerkleTree) GenerateProof Uses

func (mt *MerkleTree) GenerateProof(hi Hash) ([]byte, error)

GenerateProof generates the Merkle Proof from a given leafHash for the current root

func (*MerkleTree) Get Uses

func (mt *MerkleTree) Get(key Hash) (byte, uint32, []byte, error)

func (*MerkleTree) GetValueInPos Uses

func (mt *MerkleTree) GetValueInPos(hi Hash) ([]byte, error)

GetValueInPos returns the merkletree value in the position of the Hash of the Index (Hi)

func (*MerkleTree) Insert Uses

func (mt *MerkleTree) Insert(key Hash, nodeType byte, indexLength uint32, nodeBytes []byte) error

func (*MerkleTree) NumLevels Uses

func (mt *MerkleTree) NumLevels() int

NumLevels returns the merkletree.NumLevels

func (*MerkleTree) PrintFullMT Uses

func (mt *MerkleTree) PrintFullMT()

PrintFullMT prints the tree in the terminal, all the levels with all the nodes

func (*MerkleTree) PrintLevelsMT Uses

func (mt *MerkleTree) PrintLevelsMT(maxLevel int)

PrintLevelsMT prints the tree in the terminal until a specified depth

func (*MerkleTree) Root Uses

func (mt *MerkleTree) Root() Hash

Root returns the merkletree.Root

type Value Uses

type Value interface {
    IndexLength() uint32 // returns the index length value
    Bytes() []byte       // returns the value in byte array representation
}

Value is the interface of a generic leaf, a key value object stored in the leveldb

Package merkletree imports 9 packages (graph). Updated 2019-08-02. Refresh now. Tools for package owners.