mpt

package
v0.0.0-...-970aaa6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyNodeRaw     = []byte{}
	EmptyNodeHash, _ = hex.DecodeString("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)

Functions

func AreEqualTries

func AreEqualTries(root1 Node, root2 Node) bool

debug equality of two tries

func Hash

func Hash(node Node) []byte

func IsEmptyNode

func IsEmptyNode(node Node) bool

func IsNibble

func IsNibble(nibble byte) bool

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func PrefixMatchedLen

func PrefixMatchedLen(node1 []Nibble, node2 []Nibble) int

[0,1,2,3], [0,1,2] => 3 [0,1,2,3], [0,1,2,3] => 4 [0,1,2,3], [0,1,2,3,4] => 4

func Serialize

func Serialize(node Node) []byte

func ToBytes

func ToBytes(ns []Nibble) []byte

ToBytes converts a slice of nibbles to a byte slice assuming the nibble slice has even number of nibbles.

func VerifyProof

func VerifyProof(rootHash []byte, key []byte, proof Proof) (value []byte, err error)

VerifyProof verify the proof for the given key under the given root hash using go-ethereum's VerifyProof implementation. It returns the value for the key if the proof is valid, otherwise error will be returned

Types

type Batch

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

func (*Batch) Delete

func (b *Batch) Delete(key []byte)

func (*Batch) Put

func (b *Batch) Put(key []byte, value []byte)

type BranchNode

type BranchNode struct {
	Branches [16]Node
	Value    []byte
}

func NewBranchNode

func NewBranchNode() *BranchNode

func (BranchNode) HasValue

func (b BranchNode) HasValue() bool

func (BranchNode) Hash

func (b BranchNode) Hash() []byte

func (BranchNode) Raw

func (b BranchNode) Raw() []interface{}

func (*BranchNode) RemoveBranch

func (b *BranchNode) RemoveBranch(nibble Nibble)

func (*BranchNode) RemoveValue

func (b *BranchNode) RemoveValue()

func (BranchNode) Serialize

func (b BranchNode) Serialize() []byte

func (*BranchNode) SetBranch

func (b *BranchNode) SetBranch(nibble Nibble, node Node)

func (*BranchNode) SetValue

func (b *BranchNode) SetValue(value []byte)

type DB

type DB interface {
	Put(key []byte, value []byte) error
	Get(key []byte) (value []byte, err error)
	Delete(key []byte) error
	NewBatch() DBBatch
	BatchWrite(batch DBBatch) error
}

type DBBatch

type DBBatch interface {
	Put(key []byte, value []byte)
	Delete(key []byte)
}

type Database

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

func NewDatabase

func NewDatabase(levelDB *leveldb.DB) *Database

func (*Database) BatchWrite

func (db *Database) BatchWrite(batch DBBatch) error

func (*Database) Delete

func (db *Database) Delete(key []byte) error

func (*Database) Get

func (db *Database) Get(key []byte) (value []byte, err error)

func (*Database) NewBatch

func (db *Database) NewBatch() DBBatch

func (*Database) Put

func (db *Database) Put(key []byte, value []byte) error

type ExtensionNode

type ExtensionNode struct {
	Path []Nibble
	Next Node
}

func NewExtensionNode

func NewExtensionNode(nibbles []Nibble, next Node) *ExtensionNode

func (ExtensionNode) Hash

func (e ExtensionNode) Hash() []byte

func (ExtensionNode) Raw

func (e ExtensionNode) Raw() []interface{}

func (ExtensionNode) Serialize

func (e ExtensionNode) Serialize() []byte

type LeafNode

type LeafNode struct {
	Path  []Nibble
	Value []byte
}

func NewLeafNodeFromBytes

func NewLeafNodeFromBytes(key, value []byte) *LeafNode

func NewLeafNodeFromKeyValue

func NewLeafNodeFromKeyValue(key, value string) *LeafNode

func NewLeafNodeFromNibbleBytes

func NewLeafNodeFromNibbleBytes(nibbles []byte, value []byte) (*LeafNode, error)

func NewLeafNodeFromNibbles

func NewLeafNodeFromNibbles(nibbles []Nibble, value []byte) *LeafNode

func (LeafNode) Hash

func (l LeafNode) Hash() []byte

func (LeafNode) Raw

func (l LeafNode) Raw() []interface{}

func (LeafNode) Serialize

func (l LeafNode) Serialize() []byte

type MockDB

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

func NewMockDB

func NewMockDB() *MockDB

func (*MockDB) BatchWrite

func (db *MockDB) BatchWrite(batch DBBatch) error

func (*MockDB) Delete

func (db *MockDB) Delete(key []byte) error

func (*MockDB) Get

func (db *MockDB) Get(key []byte) (value []byte, err error)

func (*MockDB) NewBatch

func (db *MockDB) NewBatch() DBBatch

func (*MockDB) Put

func (db *MockDB) Put(key []byte, value []byte) error

type MockDBBatch

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

func (*MockDBBatch) Delete

func (b *MockDBBatch) Delete(key []byte)

func (*MockDBBatch) Put

func (b *MockDBBatch) Put(key []byte, value []byte)

type MockOperation

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

type Nibble

type Nibble byte

func FromByte

func FromByte(b byte) []Nibble

func FromBytes

func FromBytes(bs []byte) []Nibble

func FromNibbleByte

func FromNibbleByte(n byte) (Nibble, error)

func FromNibbleBytes

func FromNibbleBytes(nibbles []byte) ([]Nibble, error)

nibbles contain one nibble per byte

func FromString

func FromString(s string) []Nibble

func RemovePrefix

func RemovePrefix(ns []Nibble) (noPrefixNs []Nibble, isLeafNode bool)

RemovePrefix removes nibble prefix from a slice of nibbles and tells if the nibbles belong to a leaf node

func ToPrefixed

func ToPrefixed(ns []Nibble, isLeafNode bool) []Nibble

ToPrefixed add nibble prefix to a slice of nibbles to make its length even the prefix indicts whether a node is a leaf node.

type Node

type Node interface {
	Hash() []byte // common.Hash
	Raw() []interface{}
}

func Deserialize

func Deserialize(serializedNode []byte, db DB) Node

func FromRaw

func FromRaw(rawNode []interface{}, db DB) Node

type Proof

type Proof interface {
	// Put inserts the given value into the key-value data store.
	Put(key []byte, value []byte) error

	// Delete removes the key from the key-value data store.
	Delete(key []byte) error

	// Has retrieves if a key is present in the key-value data store.
	Has(key []byte) (bool, error)

	// Get retrieves the given key if it's present in the key-value data store.
	Get(key []byte) ([]byte, error)
}

type ProofDB

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

func NewProofDB

func NewProofDB() *ProofDB

func (*ProofDB) Delete

func (w *ProofDB) Delete(key []byte) error

func (*ProofDB) Get

func (w *ProofDB) Get(key []byte) ([]byte, error)

func (*ProofDB) Has

func (w *ProofDB) Has(key []byte) (bool, error)

func (*ProofDB) Put

func (w *ProofDB) Put(key []byte, value []byte) error

type Transaction

type Transaction struct {
	AccountNonce uint64          `json:"nonce"    `
	Price        *big.Int        `json:"gasPrice" `
	GasLimit     uint64          `json:"gas"      `
	Recipient    *common.Address `json:"to"       `
	Amount       *big.Int        `json:"value"    `
	Payload      []byte          `json:"input"    `

	// Signature values
	V *big.Int `json:"v" `
	R *big.Int `json:"r" `
	S *big.Int `json:"s" `
}

func (Transaction) GetRLP

func (t Transaction) GetRLP() ([]byte, error)

type Trie

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

func NewTrie

func NewTrie() *Trie

func (*Trie) GenerateFromDB

func (t *Trie) GenerateFromDB(db DB)

func (*Trie) Get

func (t *Trie) Get(key []byte) ([]byte, bool)

func (*Trie) Hash

func (t *Trie) Hash() []byte

func (*Trie) PersistInDB

func (t *Trie) PersistInDB(db DB)

func (*Trie) Prove

func (t *Trie) Prove(key []byte) (Proof, bool)

Prove returns the merkle proof for the given key, which is

func (*Trie) Put

func (t *Trie) Put(key []byte, value []byte)

Put adds a key value pair to the trie In general, the rule is: - When stopped at an EmptyNode, replace it with a new LeafNode with the remaining path. - When stopped at a LeafNode, convert it to an ExtensionNode and add a new branch and a new LeafNode. - When stopped at an ExtensionNode, convert it to another ExtensionNode with shorter path and create a new BranchNode points to the ExtensionNode.

func (*Trie) ToDBBatch

func (t *Trie) ToDBBatch(db DB) DBBatch

Jump to

Keyboard shortcuts

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