merkletree

package
v0.0.0-...-db26c95 Latest Latest
Warning

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

Go to latest
Published: May 26, 2018 License: MIT Imports: 8 Imported by: 9

Documentation

Index

Constants

View Source
const MaxTreeJobs = 128

MaxTreeJobs - number of jobs in a block

Variables

View Source
var (
	ErrNodeDoesntExist    = errors.New("core/merkletree: node doesn't exist")
	ErrLeafNodesEmpty     = errors.New("core/merkletree: leafnodes is empty")
	ErrTreeNotBuilt       = errors.New("core/merkletree: tree hasn't been built")
	ErrTreeRebuildAttempt = errors.New("core/merkle tree: attempt to rebuild tree")
	// ErrOddLeafNodes       = errors.New("core/merkle tree: odd number of leaf nodes")
	ErrTooMuchLeafNodes = errors.New("core/merkle tree: length of leaf nodes is greater than 24")
	ErrJobDoesntExist   = errors.New("core/merkletree: job doesn't exist")
)

Functions

func MergeJobs

func MergeJobs(x, y MerkleNode) job.Job

MergeJobs merges two jobs into one

Types

type MerkleNode

type MerkleNode struct {
	Hash  []byte //hash of a job struct
	Job   job.Job
	Left  *MerkleNode
	Right *MerkleNode
}

MerkleNode nodes that make a merkletree

func NewNode

func NewNode(j job.Job, lNode, rNode *MerkleNode) *MerkleNode

NewNode returns a new merklenode

func (MerkleNode) GetHash

func (n MerkleNode) GetHash() []byte

GetHash returns hash

func (MerkleNode) GetJob

func (n MerkleNode) GetJob() job.Job

GetJob returns job

func (MerkleNode) GetLeftNode

func (n MerkleNode) GetLeftNode() MerkleNode

GetLeftNode return leftnode

func (MerkleNode) GetRightNode

func (n MerkleNode) GetRightNode() MerkleNode

GetRightNode return rightnode

func (*MerkleNode) IsEmpty

func (n *MerkleNode) IsEmpty() bool

IsEmpty check if the merklenode is empty

func (MerkleNode) IsEqual

func (n MerkleNode) IsEqual(x MerkleNode) bool

IsEqual check if the input merklenode equals the merklenode calling the function

func (*MerkleNode) IsLeaf

func (n *MerkleNode) IsLeaf() bool

IsLeaf checks if the merklenode is a leaf node

func (MerkleNode) Serialize

func (n MerkleNode) Serialize() ([]byte, error)

Serialize returns the bytes of a merklenode

func (*MerkleNode) SetJob

func (n *MerkleNode) SetJob(j job.Job)

SetJob setter for job

func (*MerkleNode) SetLeftNode

func (n *MerkleNode) SetLeftNode(l MerkleNode)

SetLeftNode setter for leftnode

func (*MerkleNode) SetRightNode

func (n *MerkleNode) SetRightNode(r MerkleNode)

SetRightNode setter for rightnode

type MerkleTree

type MerkleTree struct {
	Root      []byte
	LeafNodes []*MerkleNode
}

MerkleTree tree of jobs

func NewMerkleTree

func NewMerkleTree(nodes []*MerkleNode) *MerkleTree

NewMerkleTree returns empty merkletree

func (*MerkleTree) Build

func (m *MerkleTree) Build() error

Build builds merkle tree from leafs to root, hashed the root and sets it as the root of the merkletree

func (MerkleTree) GetLeafNodes

func (m MerkleTree) GetLeafNodes() []*MerkleNode

GetLeafNodes return leafnodes

func (MerkleTree) GetRoot

func (m MerkleTree) GetRoot() []byte

GetRoot returns root

func (MerkleTree) SearchJob

func (m MerkleTree) SearchJob(ID string) (*job.Job, error)

SearchJob returns job from the tree

func (MerkleTree) SearchNode

func (m MerkleTree) SearchNode(hash []byte) (*MerkleNode, error)

SearchNode returns true if node with hash exists

func (MerkleTree) Serialize

func (m MerkleTree) Serialize() ([]byte, error)

Serialize returns the bytes of a merkletree

func (*MerkleTree) SetLeafNodes

func (m *MerkleTree) SetLeafNodes(l []*MerkleNode)

SetLeafNodes return leafnodes

func (MerkleTree) VerifyTree

func (m MerkleTree) VerifyTree() bool

VerifyTree returns true if tree is verified

Jump to

Keyboard shortcuts

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