tree

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: AGPL-3.0 Imports: 11 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyProof = types.Proof{}
)
View Source
var (
	ErrInvalidIndex = errors.New("invalid index")
)

Functions

func CalculateRoot added in v0.4.0

func CalculateRoot(leafHash common.Hash, proof [types.DefaultHeight]common.Hash, index uint32) common.Hash

CalculateRoot calculates the Merkle Root based on the leaf and proof of inclusion

Types

type AppendOnlyTree

type AppendOnlyTree struct {
	*Tree
	// contains filtered or unexported fields
}

AppendOnlyTree is a tree where leaves are added sequentially (by index)

func NewAppendOnlyTree

func NewAppendOnlyTree(db *sql.DB, dbPrefix string) *AppendOnlyTree

NewAppendOnlyTree creates a AppendOnlyTree

func (*AppendOnlyTree) AddLeaf

func (t *AppendOnlyTree) AddLeaf(tx db.Txer, blockNum, blockPosition uint64, leaf types.Leaf) error

type Tree

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

func (*Tree) GetLastRoot

func (t *Tree) GetLastRoot(tx db.Querier) (types.Root, error)

GetLastRoot returns the last processed root

func (*Tree) GetLeaf

func (t *Tree) GetLeaf(tx db.Querier, index uint32, root common.Hash) (common.Hash, error)

func (*Tree) GetProof

func (t *Tree) GetProof(ctx context.Context, index uint32, root common.Hash) (types.Proof, error)

GetProof returns the merkle proof for a given index and root.

func (*Tree) GetRootByHash

func (t *Tree) GetRootByHash(ctx context.Context, hash common.Hash) (*types.Root, error)

GetRootByHash returns the root associated to the hash

func (*Tree) GetRootByIndex

func (t *Tree) GetRootByIndex(ctx context.Context, index uint32) (types.Root, error)

GetRootByIndex returns the root associated to the index

func (*Tree) Reorg

func (t *Tree) Reorg(tx db.Txer, firstReorgedBlock uint64) error

Reorg deletes all the data relevant from firstReorgedBlock (includded) and onwards

type UpdatableTree

type UpdatableTree struct {
	*Tree
}

UpdatableTree is a tree that have updatable leaves, and doesn't need to have sequential inserts

func NewUpdatableTree

func NewUpdatableTree(db *sql.DB, dbPrefix string) *UpdatableTree

NewUpdatableTree returns an UpdatableTree

func (*UpdatableTree) UpsertLeaf

func (t *UpdatableTree) UpsertLeaf(tx db.Txer, blockNum, blockPosition uint64, leaf types.Leaf) (common.Hash, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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