Documentation ¶
Index ¶
- Constants
- Variables
- func MergeJobs(x, y MerkleNode) job.Job
- type MerkleNode
- func (n MerkleNode) GetHash() []byte
- func (n MerkleNode) GetJob() job.Job
- func (n MerkleNode) GetLeftNode() MerkleNode
- func (n MerkleNode) GetRightNode() MerkleNode
- func (n *MerkleNode) IsEmpty() bool
- func (n MerkleNode) IsEqual(x MerkleNode) bool
- func (n *MerkleNode) IsLeaf() bool
- func (n MerkleNode) Serialize() ([]byte, error)
- func (n *MerkleNode) SetJob(j job.Job)
- func (n *MerkleNode) SetLeftNode(l MerkleNode)
- func (n *MerkleNode) SetRightNode(r MerkleNode)
- type MerkleTree
- func (m *MerkleTree) Build() error
- func (m MerkleTree) GetLeafNodes() []*MerkleNode
- func (m MerkleTree) GetRoot() []byte
- func (m MerkleTree) SearchJob(ID string) (*job.Job, error)
- func (m MerkleTree) SearchNode(hash []byte) (*MerkleNode, error)
- func (m MerkleTree) Serialize() ([]byte, error)
- func (m *MerkleTree) SetLeafNodes(l []*MerkleNode)
- func (m MerkleTree) VerifyTree() bool
Constants ¶
const MaxTreeJobs = 128
MaxTreeJobs - number of jobs in a block
Variables ¶
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 ¶
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) 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) 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) 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