basedb

package
v0.0.0-...-5fb9e85 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package basedb

@author: xwc1125

Package basedb

@author: xwc1125

Package basedb

@author: xwc1125

Package basedb

@author: xwc1125

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// OpenTree 打开主账户树
	OpenTree(root types.Hash) (Tree, error)
	// OpenStorageTree 打开账户树
	OpenStorageTree(addrHash types.Hash, root types.Hash) (Tree, error)
	// CopyTree 复制树
	CopyTree(Tree) Tree

	// ContractCode 获取合约的bytes
	ContractCode(addrHash, codeHash types.Hash) ([]byte, error)

	// ContractCodeSize 获取合约的bytes长度
	ContractCodeSize(addrHash, codeHash types.Hash) (int, error)

	// TreeDB 获取tree database
	TreeDB() *tree.Database
}

func NewDatabase

func NewDatabase(db kvstore.Database) Database

func NewDatabaseWithCache

func NewDatabaseWithCache(db kvstore.Database, cache int) Database

NewDatabaseWithCache creates a backing store for state. The returned database is safe for concurrent use and retains a lot of collapsed RLP trie nodes in a large memory cache.

type Journal

type Journal struct {
	Dirties   map[string]int // Dirty accounts and the number of changes
	Pending   map[string]struct{}
	Committer map[string]JournalCommitter
	// contains filtered or unexported fields
}

func NewJournal

func NewJournal() *Journal

NewJournal create a new initialized Journal.

func (*Journal) Append

func (j *Journal) Append(entry JournalEntry, commiter JournalCommitter)

Append inserts a new modification entry to the end of the change journal.

func (*Journal) ClearDirties

func (j *Journal) ClearDirties()

func (*Journal) Dirty

func (j *Journal) Dirty(key string)

Dirty explicitly sets an address to dirty, even if the change entries would otherwise suggest it as clean. This method is an ugly hack to handle the RIPEMD precompile consensus exception.

func (*Journal) Length

func (j *Journal) Length() int

Length returns the current number of entries in the journal.

func (*Journal) Revert

func (j *Journal) Revert(snapshot int)

Revert undoes a batch of journalled modifications along with any reverted dirty handling too.

type JournalCommitter

type JournalCommitter interface {
	FinaliseObject(string, bool)
	CommitObject(string, bool)
}

type JournalEntry

type JournalEntry interface {
	Revert()
	Dirtied() string
}

type Tree

type Tree interface {
	GetKey([]byte) []byte
	// TryGet returns the value for key stored in the trie. The value bytes must
	// not be modified by the caller. If a node was not found in the database, a
	// trie.MissingNodeError is returned.
	TryGet(key []byte) ([]byte, error)

	// TryUpdate associates key with value in the trie. If value has length zero, any
	// existing value is deleted from the trie. The value bytes must not be modified
	// by the caller while they are stored in the trie. If a node was not found in the
	// database, a trie.MissingNodeError is returned.
	TryUpdate(key, value []byte) error

	// TryDelete removes any existing value for key from the trie. If a node was not
	// found in the database, a trie.MissingNodeError is returned.
	TryDelete(key []byte) error

	// Hash returns the root hash of the trie. It does not write to the database and
	// can be used even if the trie doesn't have one.
	Hash() types.Hash

	// Commit writes all nodes to the trie's memory database, tracking the internal
	// and external (for account tries) references.
	Commit(onleaf tree.LeafCallback) (types.Hash, error)

	// NodeIterator returns an iterator that returns nodes of the trie. Iteration
	// starts at the key after the given start key.
	NodeIterator(startKey []byte) tree.NodeIterator

	// Prove constructs a Merkle proof for key. The result contains all encoded nodes
	// on the path to the value at key. The value itself is also included in the last
	// node and can be retrieved by verifying the proof.
	//
	// If the trie does not contain a value for key, the returned proof contains all
	// nodes of the longest existing prefix of the key (at least the root), ending
	// with the node that proves the absence of the key.
	Prove(key []byte, fromLevel uint, proofDb kvstore.KeyValueWriter) error
}

Jump to

Keyboard shortcuts

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