tree

package
v0.7.1-rc7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0, MIT Imports: 12 Imported by: 0

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

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

func VerifyProof added in v0.7.1

func VerifyProof(leaf common.Hash, proof types.Proof, index uint32, expectedRoot common.Hash) error

VerifyProof validates a Merkle proof for a given leaf index against an expected root. It returns nil when the proof is valid or an error describing the mismatch.

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 dbtypes.Txer, blockNum, blockPosition uint64, leaf types.Leaf) error

func (*AppendOnlyTree) InitCache added in v0.7.1

func (t *AppendOnlyTree) InitCache(tx dbtypes.Txer) error

type Tree

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

func (*Tree) GetLastRoot

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

GetLastRoot returns the last processed root

func (*Tree) GetLeaf

func (t *Tree) GetLeaf(tx dbtypes.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 dbtypes.Txer, firstReorgedBlock uint64) error

Reorg deletes all the data relevant from firstReorgedBlock (included) 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 dbtypes.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