trie

package
v0.0.0-...-34de315 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("key already exists")
	ErrNotFound      = errors.New("key not found")
)

A list of errors that can be returned by the functions of the trie.

Functions

This section is empty.

Types

type Bin

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

Bin represents our own implementation of the patricia merkle trie as specified in the Ethereum yellow paper, with a few simplications due to the simpler structure of the Alvalor blockchain.

func NewBin

func NewBin() *Bin

NewBin creates a new empty hex trie.

func (*Bin) Del

func (t *Bin) Del(key []byte) error

Del will try to delete the hash located at the path provided by the given key. If no hash is found at the given location, it returns false.

func (*Bin) Get

func (t *Bin) Get(key []byte) ([]byte, error)

Get will retrieve the hash located at the path provided by the given key. If the path doesn't exist or there is no hash at the given location, it returns a nil slice and false.

func (*Bin) Hash

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

Hash will return the hash that represents the trie in its entirety by returning the hash of the root node. Currently, it does not do any caching and recomputes the hash from the leafs up. If the root is not initialized, it will return the hash of an empty byte array to uniquely represent a trie without state.

func (*Bin) MustPut

func (t *Bin) MustPut(key []byte, data []byte)

MustPut will insert the given data for the given key and will overwrite any data that might already be stored under the given key.

func (*Bin) Put

func (t *Bin) Put(key []byte, data []byte) error

Put will insert the given data for the given key. It will fail if there already is data with the given key.

type Hex

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

Hex represents our own implementation of the patricia merkle trie as specified in the Ethereum yellow paper, with a few simplications due to the simpler structure of the Alvalor blockchain.

func NewHex

func NewHex() *Hex

NewHex creates a new empty hex trie.

func (*Hex) Del

func (t *Hex) Del(key []byte) error

Del will try to delete the hash located at the path provided by the given key. If no hash is found at the given location, it returns false.

func (*Hex) Get

func (t *Hex) Get(key []byte) ([]byte, error)

Get will retrieve the hash located at the path provided by the given key. If the path doesn't exist or there is no hash at the given location, it returns a nil slice and false.

func (*Hex) Hash

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

Hash will return the hash that represents the trie in its entirety by returning the hash of the root node. Currently, it does not do any caching and recomputes the hash from the leafs up. If the root is not initialized, it will return the hash of an empty byte array to uniquely represent a trie without state.

func (*Hex) MustPut

func (t *Hex) MustPut(key []byte, data []byte)

MustPut will insert the given data for the given key and will overwrite any data that might already be stored under the given key.

func (*Hex) Put

func (t *Hex) Put(key []byte, data []byte) error

Put will insert the given data for the given key. It will fail if there already is data with the given key.

Jump to

Keyboard shortcuts

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