mmr

package
v0.4.0-rc17 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const ValueSize = 40

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockNode

type BlockNode struct {
	Leaf

	ID         uint64         // ID of node in the MMR Tree, if ID < math.MaxInt32, ID == block height in main chain.
	PrevNodeID uint64         // PrevNodeID hash of previous block
	ActualRoot chainhash.Hash // ActualRoot is a root of the MMR Tree when this node was latest
}

func (*BlockNode) Clone

func (n *BlockNode) Clone() *BlockNode

type BlocksMMRTree

type BlocksMMRTree interface {
	Current() *BlockNode
	Parent(height int32) *BlockNode
	Block(height int32) *BlockNode
	CurrentRoot() chainhash.Hash
	RootForHeight(height int32) chainhash.Hash

	LookupNodeByRoot(chainhash.Hash) (*BlockNode, bool)

	AddBlock(hash chainhash.Hash, difficulty uint64)
	SetBlock(hash chainhash.Hash, difficulty uint64, height int32)
	RmBlock(hash chainhash.Hash, height int32)
	ResetRootTo(hash chainhash.Hash, height int32)
}

type Leaf

type Leaf struct {
	Hash   chainhash.Hash
	Weight uint64
	// contains filtered or unexported fields
}

func BuildMerkleTreeStore

func BuildMerkleTreeStore(blocks []Leaf) []*Leaf

func HashMerkleBranches

func HashMerkleBranches(left, right *Leaf) *Leaf

func (*Leaf) Value

func (b *Leaf) Value() Value

type Tree

type Tree struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTree

func NewTree() *Tree

func (*Tree) AddBlock

func (t *Tree) AddBlock(hash chainhash.Hash, difficulty uint64)

AddBlock adds block as latest leaf, increases height and rebuild tree.

func (*Tree) Block

func (t *Tree) Block(height int32) *BlockNode

func (*Tree) Current

func (t *Tree) Current() *BlockNode

func (*Tree) CurrentRoot

func (t *Tree) CurrentRoot() chainhash.Hash

func (*Tree) Fork

func (t *Tree) Fork() BlocksMMRTree

func (*Tree) LookupNodeByRoot

func (t *Tree) LookupNodeByRoot(hash chainhash.Hash) (*BlockNode, bool)

func (*Tree) Parent

func (t *Tree) Parent(height int32) *BlockNode

func (*Tree) ResetRootTo

func (t *Tree) ResetRootTo(hash chainhash.Hash, height int32)

ResetRootTo sets provided block with <hash, height> as latest and drops all blocks after this.

func (*Tree) RmBlock

func (t *Tree) RmBlock(hash chainhash.Hash, height int32)

RmBlock drops all block from latest to (including) provided block with <hash, height>.

func (*Tree) RootForHeight

func (t *Tree) RootForHeight(height int32) chainhash.Hash

func (*Tree) SetBlock

func (t *Tree) SetBlock(hash chainhash.Hash, difficulty uint64, height int32)

SetBlock sets provided block with <hash, height> as latest. If block height is not latest, then reset tree to height - 1 and add AddBLock.

type Value

type Value [ValueSize]byte

func (Value) Block

func (v Value) Block() (b Leaf)

Jump to

Keyboard shortcuts

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