state

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyContractCode = "c"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Nonce    uint64      `json:"nonce"`
	Balance  *big.Int    `json:"balance"`
	Root     common.Hash `json:"root"`
	CodeHash common.Hash `json:"code_hash"`
}

func (*Account) Deserialize

func (s *Account) Deserialize(data []byte) error

func (*Account) Serialize

func (s *Account) Serialize() ([]byte, error)

type BucketTree

type BucketTree interface {
	Hash() common.Hash
	Init(root []byte) error
	Prepare(dirty bmt.WriteSet) error
	Process() (common.Hash, error)
	Commit(batch tdb.Batch) error
	Get(key []byte) ([]byte, error)
	Copy() *bmt.BucketTree
	Purge()
}

Bucket tree

type StateDB

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

func New

func New(db tdb.Database, root []byte) (*StateDB, error)

func (*StateDB) AddBalance

func (sdb *StateDB) AddBalance(addr common.Address, amount *big.Int)

func (*StateDB) AddLog

func (sdb *StateDB) AddLog(log *types.Log)

func (*StateDB) ChargeGas

func (sdb *StateDB) ChargeGas(addr common.Address, amount uint64)

ChargeGas charge a given address as gas during the transaction execution, but will give back at the state commit process. This mechanism is make free transactions possible and defend sending huge amount of transactions from the same address viciously.

func (*StateDB) Commit

func (sdb *StateDB) Commit(batch tdb.Batch) (common.Hash, error)

func (*StateDB) CreateAccount

func (sdb *StateDB) 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.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. 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

func (sdb *StateDB) Empty(addr common.Address) bool

func (*StateDB) Exist

func (sdb *StateDB) Exist(addr common.Address) bool

func (*StateDB) GetBalance

func (sdb *StateDB) GetBalance(addr common.Address) *big.Int

func (*StateDB) GetCode

func (sdb *StateDB) GetCode(addr common.Address) []byte

func (*StateDB) GetCodeHash

func (sdb *StateDB) GetCodeHash(addr common.Address) common.Hash

func (*StateDB) GetCodeSize

func (sdb *StateDB) GetCodeSize(address common.Address) int

func (*StateDB) GetLogs

func (sdb *StateDB) GetLogs(txHash common.Hash) types.Logs

func (*StateDB) GetNonce

func (sdb *StateDB) GetNonce(addr common.Address) uint64

func (*StateDB) GetOrNewStateObj

func (sdb *StateDB) GetOrNewStateObj(addr common.Address) *stateObject

Get or create a state object

func (*StateDB) GetState

func (sdb *StateDB) GetState(addr common.Address, key common.Hash) []byte

Get state of an account with address

func (*StateDB) GetStateObj

func (sdb *StateDB) GetStateObj(addr common.Address) *stateObject

Get state object from cache and bucket tree If error, return nil

func (*StateDB) HasSuicided

func (sdb *StateDB) HasSuicided(addr common.Address) bool

func (*StateDB) IntermediateRoot

func (sdb *StateDB) IntermediateRoot() (common.Hash, error)

Process dirty state object to state tree and get intermediate root

func (*StateDB) Prepare

func (sdb *StateDB) Prepare(txHash, blockHash common.Hash, txIndex uint32)

Prepare will be called when execute a new tx in state processor

func (*StateDB) RevertToSnapshot

func (sdb *StateDB) RevertToSnapshot(revid int)

func (*StateDB) SetBalance

func (sdb *StateDB) SetBalance(addr common.Address, target *big.Int)

func (*StateDB) SetCode

func (sdb *StateDB) SetCode(addr common.Address, code []byte)

func (*StateDB) SetNonce

func (sdb *StateDB) SetNonce(addr common.Address, nonce uint64)

func (*StateDB) SetState

func (sdb *StateDB) SetState(addr common.Address, key common.Hash, value []byte)

Set state of an account

func (*StateDB) Snapshot

func (sdb *StateDB) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*StateDB) StateBmt

func (sdb *StateDB) StateBmt(addr common.Address) BucketTree

Get state bucket merkel tree of state object

func (*StateDB) SubBalance

func (sdb *StateDB) SubBalance(addr common.Address, amount *big.Int)

func (*StateDB) Suicide

func (sdb *StateDB) Suicide(addr common.Address) bool

func (*StateDB) UpdateCurrHeight

func (sdb *StateDB) UpdateCurrHeight(height uint64)

type Storage

type Storage map[common.Hash][]byte

Value is not actually hash, but just a 32 bytes array

Jump to

Keyboard shortcuts

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