Documentation ¶
Index ¶
- type Account
- type Chain
- func (c *Chain) AddBalance(addr *seth.Address, v *big.Int)
- func (c *Chain) AtBlock(n int64) *Chain
- func (c *Chain) BalanceOf(addr *seth.Address) *big.Int
- func (c *Chain) Call(sender, dst *seth.Address, sig string, args ...seth.EtherType) ([]byte, error)
- func (c *Chain) Client() *seth.Client
- func (c *Chain) Copy() *Chain
- func (c *Chain) Create(sender *seth.Address, code []byte) (seth.Address, error)
- func (c *Chain) CreateAt(addr, sender *seth.Address, code []byte) error
- func (c *Chain) EstimateGas(sender, dst *seth.Address, sig string, args ...seth.EtherType) (uint64, error)
- func (c *Chain) Execute(req *seth.RPCRequest, res *seth.RPCResponse) error
- func (c *Chain) Logs() []seth.Log
- func (c *Chain) MarshalJSON() ([]byte, error)
- func (c *Chain) Mine(tx *seth.Transaction) (ret []byte, h seth.Hash, err error)
- func (c *Chain) NewAccount(ether int) seth.Address
- func (c *Chain) Seal()
- func (c *Chain) Send(sender, dst *seth.Address, value *big.Int) error
- func (c *Chain) Sender(from *seth.Address) *seth.Sender
- func (s *Chain) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Chain) StaticCall(sender, dst *seth.Address, sig string, args ...seth.EtherType) ([]byte, error)
- func (c *Chain) SubBalance(addr *seth.Address, v *big.Int)
- func (c *Chain) UnmarshalJSON(b []byte) error
- type State
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account [32 + 8 + 1]byte
an account is a tuple of (balance, nonce, suicided)
func (*Account) SetBalance ¶
func (*Account) SetSuicided ¶
type Chain ¶
type Chain struct { // Debugf, if non-nil, is used to log debugging information // about transactions being executed, mined, etc. Debugf func(format string, args ...interface{}) State State // contains filtered or unexported fields }
A Chain is a model of the state of the blockchain. The fields in this type are not threadsafe and must not be accessed concurrently. The methods on this type are threadsafe.
func NewChain ¶
func NewChain() *Chain
NewChain creates a new fake blockchain. In its initial state, the chain has no accounts with non-zero balances, and no deployed contracts.
func NewFork ¶
NewFork creates a new fake blockchain that operates like a fork of the chain backing the given client at the given block number.
tevm "forks" work by overlaying state updates on top of the existing chain state, and chain state is fetched lazily as calls are made. Consequently, it costs basically nothing to make a "fork," because no data is actually copied.
func (*Chain) AddBalance ¶
AddBalance adds to the balance of an account.
func (*Chain) AtBlock ¶
AtBlock returns the chain state at a given block number. As a special case, -1 is interpreted as the pending block (i.e. the current chain state), and -2 is interpreted as the latest block (i.e. the chain state just before the pending block).
func (*Chain) Call ¶
Call executes a transaction that represents a call initiated by 'sender' to the destination address.
'sig' must be in the canonical method signature encoding.
func (*Chain) Client ¶
Client creates a seth.Client that talks to the fake chain. The client can be used to test unmodified code using the seth library against the mock chain.
func (*Chain) Copy ¶
Copy returns a new logical copy of the chain. Copy avoids making a deep copy of the state.
func (*Chain) Create ¶
Create executes a transation that deploys the given code to a new contract address, and returns the address of the newly created contract.
func (*Chain) CreateAt ¶
CreateAt creates a new contract at the given address. This does not do bookkeeping in the same way that Create does. In particular, it does not increment the sender nonce or enforce callstack limits.
func (*Chain) EstimateGas ¶
func (c *Chain) EstimateGas(sender, dst *seth.Address, sig string, args ...seth.EtherType) (uint64, error)
EstimateGas estimates the amount of gas that the given transaction will use.
func (*Chain) Execute ¶
func (c *Chain) Execute(req *seth.RPCRequest, res *seth.RPCResponse) error
Execute implements seth.Transport.
func (*Chain) Logs ¶
Logs returns all of the logs emitted by transactions in this chain.
NOTE: if the chain is using a fallback chain, the returned log values do not include logs from that fallback chain.
func (*Chain) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Chain) Mine ¶
Mine executes a transaction and returns the return value of the transaction (if any) and the transaction hash. Unlike the other methods of executing a transaction on a Chain, this method updates the pending block and saves the transaction and its receipt in the state tree so that they can be retrieved later. Additionally, this method respects the amount of gas sent in the transaction, rather than offering all of the gas in the block to the transaction, which more faithfully mimics the behavior of an actual ethereum node.
func (*Chain) NewAccount ¶
NewAccount creates a new account with some ether in it. The balance of the new account will be 'ether' * 10**18
func (*Chain) Seal ¶
func (c *Chain) Seal()
Seal seals the current block (c.Pending) and replaces it with a new pending block with the same parameters (but with an update block number and hash, and zeroed gas used).
func (*Chain) Sender ¶
Sender creates a Sender from a sending address. This can be used to test unmodified Go code using the seth library against a synthetic blockchain.
func (*Chain) ServeHTTP ¶
func (s *Chain) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*Chain) StaticCall ¶
func (c *Chain) StaticCall(sender, dst *seth.Address, sig string, args ...seth.EtherType) ([]byte, error)
StaticCall yields the result of the given transaction in the pending block without comitting the state changes to the chain.
func (*Chain) SubBalance ¶
SubBalance subtracts from the balance of an account.
func (*Chain) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type State ¶
type State struct { // Fallback is used when a lookup for data on an account // fails for in-memory state. Fallback always reads state // from a specific block number, and local modifications // always take precedence over fallback state. Fallback struct { *seth.Client Block int64 } Refund seth.Uint64 Trace func(fn string, args ...interface{}) `json:"-"` Pending *seth.Block Accounts Tree Code Tree Storage Tree // key = hash(address, pointer) Preimage Tree Transactions Tree // key = txhash, value = serialized tx Receipts Tree // key = txhash, value = serialized rx Blocks Tree // key = n2h(blocknum) = hash, value = serialized block Logs []*types.Log // contains filtered or unexported fields }
State database for the EVM.
type Tree ¶
type Tree tree
Tree is a tree that stores byte-based key-value pairs using a copy-on-write binary tree so that its state can be snapshotted in constant time.
The zero value of a Tree is the empty set.
func (*Tree) CopyAt ¶
CopyAt returns a logical copy of thre tree at a given snapshot. (As an optimization, the data itself is not copied.) Updates to the returned Tree will not be reflected in t.
A safe copy of the current state of the tree can be obtained through code like
t.CopyAt(t.Snapshot())