account

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package account is used to do accounts or contract operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccAccesser

type AccAccesser interface {
	GetData(db AccountDatabase, key []byte) []byte
	GetRootHash() common.Hash
	GetAddr() common.Address
}

type Account

type Account struct {
	Nonce    uint64
	Balance  *big.Int
	Root     common.Hash
	CodeHash []byte
}

Account is the consensus representation of accounts. These objects are stored in the main account trie.

type AccountDB

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

AccountDB are used to store anything within the merkle trie. AccountDB take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts

func NewAccountDB

func NewAccountDB(root common.Hash, db AccountDatabase) (*AccountDB, error)

Create a new account from a given trie.

func (*AccountDB) AddBalance

func (adb *AccountDB) AddBalance(addr common.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*AccountDB) AddRefund

func (adb *AccountDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*AccountDB) CanTransfer

func (adb *AccountDB) CanTransfer(addr common.Address, amount *big.Int) bool

func (*AccountDB) Commit

func (adb *AccountDB) Commit(deleteEmptyObjects bool) (root common.Hash, err error)

Commit writes the state to the underlying in-memory trie database.

func (*AccountDB) CreateAccount

func (adb *AccountDB) CreateAccount(addr common.Address)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

func (*AccountDB) DataIterator

func (adb *AccountDB) DataIterator(addr common.Address, prefix []byte) *trie.Iterator

DataIterator returns a new key-value iterator from a node iterator

func (*AccountDB) Database

func (adb *AccountDB) Database() AccountDatabase

Database retrieves the low level database supporting the lower level trie ops.

func (*AccountDB) Empty

func (adb *AccountDB) Empty(addr common.Address) bool

Empty returns whether the state object is either non-existent or (balance = nonce = code = 0)

func (*AccountDB) Error

func (adb *AccountDB) Error() error

Error get the first non-nil error it is called with.

func (*AccountDB) Exist

func (adb *AccountDB) Exist(addr common.Address) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*AccountDB) Finalise

func (adb *AccountDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*AccountDB) GetBalance

func (adb *AccountDB) GetBalance(addr common.Address) *big.Int

GetBalance Retrieve the balance from the given address or 0 if object not found

func (*AccountDB) GetCode

func (adb *AccountDB) GetCode(addr common.Address) []byte

GetCode returns the contract code associated with this object, if any.

func (*AccountDB) GetCodeHash

func (adb *AccountDB) GetCodeHash(addr common.Address) common.Hash

GetCodeHash returns code's hash

func (*AccountDB) GetCodeSize

func (adb *AccountDB) GetCodeSize(addr common.Address) int

GetCodeSize retrieves a particular contracts code's size.

func (*AccountDB) GetData

func (adb *AccountDB) GetData(a common.Address, key []byte) []byte

GetData retrieves a value from the account storage trie.

func (*AccountDB) GetNonce

func (adb *AccountDB) GetNonce(addr common.Address) uint64

GetBalance Retrieve the nonce from the given address or 0 if object not found

func (*AccountDB) GetRefund

func (adb *AccountDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*AccountDB) GetStateObject

func (adb *AccountDB) GetStateObject(a common.Address) AccAccesser

GetStateObject returns stateobject's interface.

func (*AccountDB) HasSuicided

func (adb *AccountDB) HasSuicided(addr common.Address) bool

HasSuicided returns this account is suicided

func (*AccountDB) IntermediateRoot

func (adb *AccountDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash

IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.

func (*AccountDB) MarkAccountObjectDirty

func (adb *AccountDB) MarkAccountObjectDirty(addr common.Address)

MarkAccountObjectDirty Record the modified accounts

func (*AccountDB) RemoveData

func (adb *AccountDB) RemoveData(addr common.Address, key []byte)

RemoveData set data nil

func (*AccountDB) Reset

func (adb *AccountDB) Reset(root common.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.

func (*AccountDB) RevertToSnapshot

func (adb *AccountDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*AccountDB) SetBalance

func (adb *AccountDB) SetBalance(addr common.Address, amount *big.Int)

func (*AccountDB) SetCode

func (adb *AccountDB) SetCode(addr common.Address, code []byte)

func (*AccountDB) SetData

func (adb *AccountDB) SetData(addr common.Address, key []byte, value []byte)

func (*AccountDB) SetNonce

func (adb *AccountDB) SetNonce(addr common.Address, nonce uint64)

func (*AccountDB) Snapshot

func (adb *AccountDB) Snapshot() int

// Snapshot returns an identifier for the current revision of the account.

func (*AccountDB) StorageTrie

func (adb *AccountDB) StorageTrie(a common.Address) Trie

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*AccountDB) SubBalance

func (adb *AccountDB) SubBalance(addr common.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*AccountDB) Suicide

func (adb *AccountDB) Suicide(addr common.Address) bool

Suicide marks the given account as suicided. This clears the account balance.

The account's account object is still available until the account is committed, getAccountObject will return a non-nil account after Suicide.

func (*AccountDB) Transfer

func (adb *AccountDB) Transfer(sender, recipient common.Address, amount *big.Int)

func (*AccountDB) Traverse

func (adb *AccountDB) Traverse(config *TraverseConfig) (bool, error)

type AccountDatabase

type AccountDatabase interface {
	// OpenTrie opens the main account trie.
	OpenTrie(root common.Hash) (Trie, error)

	// OpenStorageTrie opens the storage trie of an account.
	OpenStorageTrie(addrHash, root common.Hash) (Trie, error)

	// CopyTrie returns an independent copy of the given trie.
	CopyTrie(Trie) Trie

	// ContractCode retrieves a particular contract's code.
	ContractCode(addrHash, codeHash common.Hash) ([]byte, error)

	// ContractCodeSize retrieves a particular contracts code's size.
	ContractCodeSize(addrHash, codeHash common.Hash) (int, error)

	// TrieDB retrieves the low level trie database used for data storage.
	TrieDB() *trie.NodeDatabase
}

func NewDatabase

func NewDatabase(db tasdb.Database, gcEnable bool) AccountDatabase

NewDatabase 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.

func NewDatabaseWithCache

func NewDatabaseWithCache(db tasdb.Database, gcEnable bool, cacheSize int, cacheDir string) AccountDatabase

type Code

type Code []byte

func (Code) String

func (c Code) String() string

type DataIterator

type DataIterator struct {
	*trie.Iterator
	// contains filtered or unexported fields
}

func (*DataIterator) GetValue

func (di *DataIterator) GetValue() []byte

func (*DataIterator) Next

func (di *DataIterator) Next() bool

type NodeIterator

type NodeIterator struct {
	Hash   common.Hash // Hash of the current entry being iterated (nil if not standalone)
	Parent common.Hash // Hash of the first full ancestor node (nil if current is the root)

	Error error // Failure set in case of an internal error in the iterator
	// contains filtered or unexported fields
}

NodeIterator is an iterator to traverse the entire state trie post-order, including all of the contract code and contract state tries.

func NewNodeIterator

func NewNodeIterator(state *AccountDB) *NodeIterator

NewNodeIterator creates an post-order state node iterator.

func (*NodeIterator) Next

func (it *NodeIterator) Next() bool

Next moves the iterator to the next node, returning whether there are any further nodes. In case of an internal error this method returns false and sets the Error field to the encountered failure.

type Storage

type Storage map[string][]byte

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

func (s Storage) String() (str string)

type SubTreeKeyProvider

type SubTreeKeyProvider func(address common.Address) [][]byte

type TraverseConfig

type TraverseConfig struct {
	VisitAccountCb      VisitAccountCallback
	ResolveNodeCb       trie.ResolveNodeCallback
	CheckHash           bool
	SubTreeKeysProvider SubTreeKeyProvider       // Provides concerned keys for the specified address, and only traverse the given keys for the address
	VisitedRoots        map[common.Hash]struct{} // Store visited roots, no more revisit for duplicate roots
	// contains filtered or unexported fields
}

func (*TraverseConfig) OnResolve

func (cfg *TraverseConfig) OnResolve(hash common.Hash, data []byte)

func (*TraverseConfig) OnVisitAccount

func (cfg *TraverseConfig) OnVisitAccount(stat *TraverseStat)

type TraverseStat

type TraverseStat struct {
	Addr      common.Address
	Account   Account
	DataCount uint64
	DataSize  uint64
	NodeSize  uint64
	NodeCount uint64
	KeySize   uint64
	CodeSize  uint64
	Cost      time.Duration
}

func (*TraverseStat) String

func (vs *TraverseStat) String() string

type Trie

type Trie interface {
	// 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

	// Commit writes all nodes to the trie's memory database, tracking the internal
	// and external (for account tries) references.
	Commit(onleaf trie.LeafCallback) (common.Hash, 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() common.Hash

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

	// Traverse is a debug method to iterate over the entire trie stored in
	// the disk and check whether every node is reachable from the meta root. The goal
	// is to find any errors that might cause trie nodes missing during prune
	//
	// This method is extremely CPU and disk intensive, and time consuming, only use when must.
	Traverse(onleaf trie.ExtLeafCallback, resolve trie.ResolveNodeCallback, checkHash bool) (bool, error)
}

type VisitAccountCallback

type VisitAccountCallback func(stat *TraverseStat)

Jump to

Keyboard shortcuts

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