Documentation ¶
Index ¶
- Constants
- Variables
- func PublicKeyToAccountAddress(pub ed25519.PublicKey) types.Address
- type Account
- type AccountState
- type Database
- type Dump
- type DumpAccount
- type GlobalStateDB
- type Projector
- type StateDB
- func (self *StateDB) AddBalance(addr types.Address, amount *big.Int)
- func (s *StateDB) Commit(deleteEmptyObjects bool) (root types.Hash32, err error)
- func (self *StateDB) Copy() *StateDB
- func (self *StateDB) CreateAccount(addr types.Address)
- func (self *StateDB) Dump() []byte
- func (self *StateDB) Empty(addr types.Address) bool
- func (self *StateDB) Error() error
- func (self *StateDB) Exist(addr types.Address) bool
- func (s *StateDB) Finalise(deleteEmptyObjects bool)
- func (self *StateDB) GetBalance(addr types.Address) uint64
- func (self *StateDB) GetNonce(addr types.Address) uint64
- func (self *StateDB) GetOrNewStateObj(addr types.Address) *StateObj
- func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) types.Hash32
- func (self *StateDB) RawDump() Dump
- func (self *StateDB) SetBalance(addr types.Address, amount *big.Int)
- func (self *StateDB) SetNonce(addr types.Address, nonce uint64)
- func (self *StateDB) SubBalance(addr types.Address, amount *big.Int)
- func (s *StateDB) TrieDB() *trie.Database
- type StateObj
- func (c *StateObj) AddBalance(amount *big.Int)
- func (c *StateObj) Address() types.Address
- func (self *StateObj) Balance() *big.Int
- func (c *StateObj) EncodeRLP(w io.Writer) error
- func (self *StateObj) Nonce() uint64
- func (c *StateObj) ReturnGas(gas *big.Int)
- func (self *StateObj) SetBalance(amount *big.Int)
- func (self *StateObj) SetNonce(nonce uint64)
- func (c *StateObj) SubBalance(amount *big.Int)
- func (self *StateObj) Value() *big.Int
- type StatePreImages
- type TransactionProcessor
- func (tp *TransactionProcessor) AddressExists(addr types.Address) bool
- func (tp *TransactionProcessor) ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)
- func (tp *TransactionProcessor) ApplyTransaction(trans *types.Transaction, layerId types.LayerID) error
- func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)
- func (tp *TransactionProcessor) GetLayerApplied(txId types.TransactionId) *types.LayerID
- func (tp *TransactionProcessor) GetStateRoot() types.Hash32
- func (tp *TransactionProcessor) LoadState(layer types.LayerID) error
- func (tp *TransactionProcessor) Process(txs []*types.Transaction, layerId types.LayerID) (remaining []*types.Transaction)
- func (tp *TransactionProcessor) ValidateNonceAndBalance(tx *types.Transaction) error
- func (tp *TransactionProcessor) ValidateSignature(s types.Signed) (types.Address, error)
- type Trie
Constants ¶
const NewRootKey = "root"
Variables ¶
var ( ErrOrigin = "origin account doesnt exist" ErrFunds = "insufficient funds" ErrNonce = "incorrect nonce" )
var MaxTrieCacheGen = uint16(120)
Trie cache generation limit after which to evict trie nodes from memory.
Functions ¶
Types ¶
type AccountState ¶
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root types.Hash32) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root types.Hash32) (Trie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie // TrieDB retrieves the low level trie database used for data storage. TrieDB() *trie.Database }
Database wraps access to tries and contract code.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.
type Dump ¶
type Dump struct { Root string `json:"root"` Accounts map[string]DumpAccount `json:"accounts"` }
type DumpAccount ¶
type GlobalStateDB ¶
type GlobalStateDB interface { Exist(addr types.Address) bool Empty(addr types.Address) bool GetBalance(addr types.Address) uint64 GetNonce(addr types.Address) uint64 AddBalance(addr types.Address, amount *big.Int) SubBalance(addr types.Address, amount *big.Int) SetNonce(addr types.Address, nonce uint64) GetOrNewStateObj(addr types.Address) *StateObj CreateAccount(addr types.Address) Commit(deleteEmptyObjects bool) (root types.Hash32, err error) //Copy() *GlobalStateDB IntermediateRoot(deleteEmptyObjects bool) types.Hash32 TrieDB() *trie.Database }
type StateDB ¶
type StateDB struct {
// contains filtered or unexported fields
}
func (*StateDB) AddBalance ¶
AddBalance adds amount to the account associated with addr.
func (*StateDB) Copy ¶
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*StateDB) CreateAccount ¶
CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.
CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:
- sends funds to sha(account ++ (nonce + 1))
- tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
Carrying over the balance ensures that Ether doesn't disappear.
func (*StateDB) Empty ¶
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*StateDB) Exist ¶
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*StateDB) Finalise ¶
Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.
func (*StateDB) GetBalance ¶
Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetOrNewStateObj ¶
Retrieve a state object or create a new state object if nil.
func (*StateDB) IntermediateRoot ¶
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 (*StateDB) SubBalance ¶
SubBalance subtracts amount from the account associated with addr.
type StateObj ¶
type StateObj struct {
// contains filtered or unexported fields
}
func (*StateObj) AddBalance ¶
AddBalance removes amount from c's balance. It is used to add funds to the destination account of a transfer.
func (*StateObj) ReturnGas ¶
Return the gas back to the origin. Used by the Virtual machine or Closures
func (*StateObj) SetBalance ¶
func (*StateObj) SubBalance ¶
SubBalance removes amount from c's balance. It is used to remove funds from the origin account of a transfer.
type StatePreImages ¶
type StatePreImages struct {
// contains filtered or unexported fields
}
type TransactionProcessor ¶
func NewTransactionProcessor ¶
func (*TransactionProcessor) AddressExists ¶
func (tp *TransactionProcessor) AddressExists(addr types.Address) bool
AddressExists checks if an account address exists in this node's global state
func (*TransactionProcessor) ApplyRewards ¶
func (*TransactionProcessor) ApplyTransaction ¶
func (tp *TransactionProcessor) ApplyTransaction(trans *types.Transaction, layerId types.LayerID) error
func (*TransactionProcessor) ApplyTransactions ¶
func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)
ApplyTransaction receives a batch of transaction to apply on state. Returns the number of transaction that failed to apply.
func (*TransactionProcessor) GetLayerApplied ¶
func (tp *TransactionProcessor) GetLayerApplied(txId types.TransactionId) *types.LayerID
func (*TransactionProcessor) GetStateRoot ¶
func (tp *TransactionProcessor) GetStateRoot() types.Hash32
func (*TransactionProcessor) LoadState ¶
func (tp *TransactionProcessor) LoadState(layer types.LayerID) error
func (*TransactionProcessor) Process ¶
func (tp *TransactionProcessor) Process(txs []*types.Transaction, layerId types.LayerID) (remaining []*types.Transaction)
func (*TransactionProcessor) ValidateNonceAndBalance ¶
func (tp *TransactionProcessor) ValidateNonceAndBalance(tx *types.Transaction) error
func (*TransactionProcessor) ValidateSignature ¶
Validate the signature by extracting the source account and validating its existence. Return the src acount address and error in case of failure
type Trie ¶
type Trie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error Commit(onleaf trie.LeafCallback) (types.Hash32, error) Hash() types.Hash32 NodeIterator(startKey []byte) trie.NodeIterator GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed Prove(key []byte, fromLevel uint, proofDb database.Putter) error }
Trie is a Ethereum Merkle Trie.