hexary

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVerify = errors.NewBase(errors.IllegalArgumentError, "VerifyError")

Functions

func LevelFromLen

func LevelFromLen(len int64) int

Types

type Accumulator

type Accumulator interface {
	Add(hash []byte) error

	// Len returns number of added hashes.
	Len() int64

	// SetLen sets length and rewinds an accumulator. Error if l is larger
	// than Len() of the accumulator.
	SetLen(l int64) error

	GetMerkleHeader() *MerkleHeader

	// Finalize finalizes node data
	Finalize() (header *MerkleHeader, err error)
}

func NewAccumulator

func NewAccumulator(
	treeBucket db.Bucket,
	accumulatorBucket db.Bucket,
	accumulatorDataKey string,
) (Accumulator, error)

NewAccumulator creates a new accumulator. Merkle node is written in tree bucket, accumulator is written on accumulator data key in accumulator bucket.

type MerkleHeader added in v0.9.10

type MerkleHeader struct {
	RootHash []byte
	Leaves   int64
}

func (MerkleHeader) String added in v0.9.10

func (mh MerkleHeader) String() string

type MerkleTree

type MerkleTree interface {
	Prover
	// Add verifies proof for given key and adds the proof in this accumulator.
	// Proof can be partial. If full proof has common prefix with proof of preceding
	// key (= key-1), the common prefix branches can be omitted.
	// Returns (hash, nil) if proof is correct,
	// (nil, wrapped ErrVerify) if proof is incorrect and
	// (nil, other error) if correctness cannot be checked due to some error.
	Add(key int64, hash []byte, proof [][]byte) (err error)
	Cap() int64
}

func NewMerkleTree

func NewMerkleTree(
	bk db.Bucket,
	header *MerkleHeader,
	cacheCap int,
) (MerkleTree, error)

NewMerkleTree creates a new hex-ary merkle tree. cacheCap is max number of branches in cache. Default value is used if -1.

type Prover

type Prover interface {
	// Prove returns proof for a key.
	// if from >= 0, first `from` elements are omitted.
	// if from < 0, only difference between proof for key and proof for key-1.
	// for example, if full proof for 0x00FF is [A, B, C, D] and full proof for
	// 0x0100 is [A, B, E, F], Prove(0x0100, -1) returns ([E, F], nil).
	Prove(key int64, from int) ([][]byte, error)
}

Jump to

Keyboard shortcuts

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