state

package
v0.0.0-...-23afbe8 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Per transaction not creating a contract
	TxGas uint64 = 21000

	// Per transaction that creates a contract
	TxGasContractCreation uint64 = 53000
)
View Source
const HashLength = 32

Variables

View Source
var (
	EmptyCodeHash = bytesToHash(ethgo.Keccak256(nil))

	// EmptyRootHash is the root when there are no transactions
	EmptyRootHash = StringToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)

Functions

func StringToHash

func StringToHash(str string) evmc.Hash

func TransactionGasCost

func TransactionGasCost(msg *Message, isHomestead, isIstanbul bool) (uint64, error)

Types

type Account

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

Account is an object we can retrieve from the state

func (*Account) Copy

func (a *Account) Copy() *Account

type Cheatcode

type Cheatcode interface {
	CanRun(addr evmc.Address) bool
	Run(addr evmc.Address, input []byte)
}

type Config

type Config struct {
	GetHash    GetHashByNumber
	Ctx        TxContext
	Rev        evmc.Revision
	State      Snapshot
	Cheatcodes []Cheatcode
}

func DefaultConfig

func DefaultConfig() *Config

type ConfigOption

type ConfigOption func(*Config)

func WithCheatcode

func WithCheatcode(cheat Cheatcode) ConfigOption

func WithContext

func WithContext(ctx TxContext) ConfigOption

func WithGetHash

func WithGetHash(hash GetHashByNumber) ConfigOption

func WithRevision

func WithRevision(rev evmc.Revision) ConfigOption

func WithState

func WithState(state Snapshot) ConfigOption

type Contract

type Contract struct {
	Type        evmc.CallKind
	CodeAddress evmc.Address
	Address     evmc.Address
	Caller      evmc.Address
	Depth       int
	Value       *big.Int
	Input       []byte
	Gas         uint64
	Static      bool
	Salt        evmc.Hash
}

Contract is the instance being called

func NewContract

func NewContract(typ evmc.CallKind, depth int, from evmc.Address, to evmc.Address, value *big.Int, gas uint64, input []byte) *Contract

func NewContractCall

func NewContractCall(depth int, from evmc.Address, to evmc.Address, value *big.Int, gas uint64, input []byte) *Contract

func NewContractCreation

func NewContractCreation(depth int, from evmc.Address, to evmc.Address, value *big.Int, gas uint64, code []byte) *Contract

type EmptyState

type EmptyState struct {
}

func (*EmptyState) GetAccount

func (e *EmptyState) GetAccount(addr evmc.Address) (*Account, error)

func (*EmptyState) GetStorage

func (e *EmptyState) GetStorage(addr evmc.Address, root evmc.Hash, key evmc.Hash) evmc.Hash

type GetHashByNumber

type GetHashByNumber = func(i uint64) evmc.Hash

getHashByNumber returns the hash function of a block number

type Log

type Log struct {
	Address evmc.Address
	Topics  []evmc.Hash
	Data    []byte
}

type Message

type Message struct {
	Nonce    uint64
	GasPrice *big.Int
	Gas      uint64
	To       *evmc.Address
	Value    *big.Int
	Input    []byte
	From     evmc.Address
}

func (*Message) IsContractCreation

func (t *Message) IsContractCreation() bool

type Object

type Object struct {
	Address   evmc.Address
	CodeHash  evmc.Hash
	Balance   *big.Int
	Root      evmc.Hash
	Nonce     uint64
	Deleted   bool
	DirtyCode bool
	Code      []byte
	Storage   []*StorageObject
}

Object is the serialization of the radix object (can be merged to StateObject?).

type Output

type Output struct {
	Logs            []*Log
	Success         bool
	GasLeft         uint64
	ContractAddress evmc.Address
	ReturnValue     []byte
}

type Snapshot

type Snapshot interface {
	GetStorage(addr evmc.Address, root evmc.Hash, key evmc.Hash) evmc.Hash
	GetAccount(addr evmc.Address) (*Account, error)
}

type StorageObject

type StorageObject struct {
	Deleted bool
	Key     []byte
	Val     []byte
}

StorageObject is an entry in the storage

type Transition

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

func NewTransition

func NewTransition(opts ...ConfigOption) *Transition

NewExecutor creates a new executor

func (*Transition) AccessAccount

func (t *Transition) AccessAccount(addr evmc.Address) evmc.AccessStatus

func (*Transition) AccessStorage

func (t *Transition) AccessStorage(addr evmc.Address, key evmc.Hash) evmc.AccessStatus

func (*Transition) AccountExists

func (t *Transition) AccountExists(addr evmc.Address) bool

func (*Transition) Apply

func (t *Transition) Apply(msg *Message) *Output

func (*Transition) Call

func (t *Transition) Call(kind evmc.CallKind,
	recipient evmc.Address, sender evmc.Address, value evmc.Hash, input []byte, gas int64, depth int,
	static bool, salt evmc.Hash, codeAddress evmc.Address) ([]byte, int64, evmc.Address, error)

func (*Transition) Callx

func (t *Transition) Callx(c *Contract) ([]byte, int64, evmc.Address, error)

func (*Transition) Commit

func (e *Transition) Commit() []*Object

func (*Transition) EmitLog

func (t *Transition) EmitLog(addr evmc.Address, topics []evmc.Hash, data []byte)

func (*Transition) GetBalance

func (t *Transition) GetBalance(addr evmc.Address) evmc.Hash

func (*Transition) GetBlockHash

func (t *Transition) GetBlockHash(number int64) (res evmc.Hash)

func (*Transition) GetCode

func (t *Transition) GetCode(addr evmc.Address) []byte

func (*Transition) GetCodeHash

func (t *Transition) GetCodeHash(addr evmc.Address) (res evmc.Hash)

func (*Transition) GetCodeSize

func (t *Transition) GetCodeSize(addr evmc.Address) int

func (*Transition) GetNonce

func (t *Transition) GetNonce(addr evmc.Address) uint64

func (*Transition) GetStorage

func (t *Transition) GetStorage(addr evmc.Address, key evmc.Hash) evmc.Hash

func (*Transition) GetTxContext

func (t *Transition) GetTxContext() evmc.TxContext

func (*Transition) Selfdestruct

func (t *Transition) Selfdestruct(addr evmc.Address, beneficiary evmc.Address)

func (*Transition) SetStorage

func (t *Transition) SetStorage(addr evmc.Address, key evmc.Hash, value evmc.Hash) evmc.StorageStatus

func (*Transition) Txn

func (t *Transition) Txn() *Txn

func (*Transition) Write

func (t *Transition) Write(msg *Message) (*Output, error)

Write writes another transaction to the executor

type TxContext

type TxContext struct {
	Hash       evmc.Hash
	GasPrice   evmc.Hash
	Origin     evmc.Address
	Coinbase   evmc.Address
	Number     int64
	Timestamp  int64
	GasLimit   int64
	ChainID    int64
	Difficulty evmc.Hash
}

TxContext is the context of the transaction

type Txn

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

Txn is a reference of the state

func NewTxn

func NewTxn(snapshot Snapshot) *Txn

func (*Txn) AccountExists

func (txn *Txn) AccountExists(addr evmc.Address) bool

func (*Txn) AddBalance

func (txn *Txn) AddBalance(addr evmc.Address, balance *big.Int)

AddBalance adds balance

func (*Txn) AddRefund

func (txn *Txn) AddRefund(gas uint64)

Refund

func (*Txn) AddSealingReward

func (txn *Txn) AddSealingReward(addr evmc.Address, balance *big.Int)

func (*Txn) CleanDeleteObjects

func (txn *Txn) CleanDeleteObjects(deleteEmptyObjects bool)

func (*Txn) Commit

func (txn *Txn) Commit() []*Object

func (*Txn) CreateAccount

func (txn *Txn) CreateAccount(addr evmc.Address)

func (*Txn) EmitLog

func (txn *Txn) EmitLog(addr evmc.Address, topics []evmc.Hash, data []byte)

func (*Txn) GetAccount

func (txn *Txn) GetAccount(addr evmc.Address) (*Account, bool)

GetAccount returns an account

func (*Txn) GetBalance

func (txn *Txn) GetBalance(addr evmc.Address) *big.Int

GetBalance returns the balance of an address

func (*Txn) GetCode

func (txn *Txn) GetCode(addr evmc.Address) []byte

func (*Txn) GetCodeHash

func (txn *Txn) GetCodeHash(addr evmc.Address) (res evmc.Hash)

func (*Txn) GetCodeSize

func (txn *Txn) GetCodeSize(addr evmc.Address) int

func (*Txn) GetCommittedState

func (txn *Txn) GetCommittedState(addr evmc.Address, key evmc.Hash) evmc.Hash

GetCommittedState returns the state of the address in the trie

func (*Txn) GetNonce

func (txn *Txn) GetNonce(addr evmc.Address) uint64

GetNonce returns the nonce of an addr

func (*Txn) GetRefund

func (txn *Txn) GetRefund() uint64

func (*Txn) GetState

func (txn *Txn) GetState(addr evmc.Address, key evmc.Hash) evmc.Hash

GetState returns the state of the address at a given key

func (*Txn) HasSuicided

func (txn *Txn) HasSuicided(addr evmc.Address) bool

HasSuicided returns true if the account suicided

func (*Txn) IncrNonce

func (txn *Txn) IncrNonce(addr evmc.Address)

IncrNonce increases the nonce of the address

func (*Txn) Logs

func (txn *Txn) Logs() []*Log

func (*Txn) RevertToSnapshot

func (txn *Txn) RevertToSnapshot(id int)

RevertToSnapshot reverts to a given snapshot

func (*Txn) SetBalance

func (txn *Txn) SetBalance(addr evmc.Address, balance *big.Int)

SetBalance sets the balance

func (*Txn) SetCode

func (txn *Txn) SetCode(addr evmc.Address, code []byte)

SetCode sets the code for an address

func (*Txn) SetNonce

func (txn *Txn) SetNonce(addr evmc.Address, nonce uint64)

SetNonce reduces the balance

func (*Txn) SetState

func (txn *Txn) SetState(addr evmc.Address, key, value evmc.Hash)

SetState change the state of an address

func (*Txn) SetStorage

func (txn *Txn) SetStorage(addr evmc.Address, key evmc.Hash, value evmc.Hash) (status evmc.StorageStatus)

func (*Txn) Snapshot

func (txn *Txn) Snapshot() int

Snapshot takes a snapshot at this point in time

func (*Txn) SubBalance

func (txn *Txn) SubBalance(addr evmc.Address, amount *big.Int) error

SubBalance reduces the balance at address addr by amount

func (*Txn) SubRefund

func (txn *Txn) SubRefund(gas uint64)

func (*Txn) Suicide

func (txn *Txn) Suicide(addr evmc.Address) bool

Suicide marks the given account as suicided

func (*Txn) TouchAccount

func (txn *Txn) TouchAccount(addr evmc.Address)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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