Documentation ¶
Overview ¶
package evm provides tools to emulate Ethereum chains and contracts.
Code adapted from go-ethereum/accounts/abi/bind/backends/simulated.go
Index ¶
- Constants
- Variables
- func InitGenesis(chainID int, db ethdb.Database, alloc core.GenesisAlloc, ...)
- func MakeConfig(chainID int) *params.ChainConfig
- func Signer(chainID *big.Int) types.Signer
- type EVMEmulator
- func (e *EVMEmulator) BalanceAt(contract common.Address, blockNumber *big.Int) (*big.Int, error)
- func (e *EVMEmulator) BlockByHash(hash common.Hash) *types.Block
- func (e *EVMEmulator) BlockByNumber(number *big.Int) (*types.Block, error)
- func (e *EVMEmulator) Blockchain() *core.BlockChain
- func (e *EVMEmulator) CallContract(call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (e *EVMEmulator) Close() error
- func (e *EVMEmulator) CodeAt(contract common.Address, blockNumber *big.Int) ([]byte, error)
- func (e *EVMEmulator) Commit()
- func (e *EVMEmulator) EstimateGas(call ethereum.CallMsg) (uint64, error)
- func (e *EVMEmulator) FilterLogs(query *ethereum.FilterQuery) ([]*types.Log, error)
- func (e *EVMEmulator) HeaderByHash(hash common.Hash) (*types.Header, error)
- func (e *EVMEmulator) HeaderByNumber(block *big.Int) (*types.Header, error)
- func (e *EVMEmulator) NonceAt(contract common.Address, blockNumber *big.Int) (uint64, error)
- func (e *EVMEmulator) PendingNonceAt(account common.Address) (uint64, error)
- func (e *EVMEmulator) Rollback(timestamp uint64)
- func (e *EVMEmulator) SendTransaction(tx *types.Transaction) (*types.Receipt, error)
- func (e *EVMEmulator) Signer() types.Signer
- func (e *EVMEmulator) StorageAt(contract common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
- func (e *EVMEmulator) SuggestGasPrice() (*big.Int, error)
- func (e *EVMEmulator) TransactionByHash(txHash common.Hash) *types.Transaction
- func (e *EVMEmulator) TransactionCount(blockHash common.Hash) (uint, error)
- func (e *EVMEmulator) TransactionInBlock(blockHash common.Hash, index uint) (*types.Transaction, error)
- func (e *EVMEmulator) TransactionReceipt(txHash common.Hash) (*types.Receipt, error)
- type KVAdapter
- func (k *KVAdapter) Close() error
- func (k *KVAdapter) Compact(start, limit []byte) error
- func (k *KVAdapter) Delete(key []byte) error
- func (k *KVAdapter) Get(key []byte) ([]byte, error)
- func (k *KVAdapter) Has(key []byte) (bool, error)
- func (k *KVAdapter) NewBatch() ethdb.Batch
- func (k *KVAdapter) NewIterator(prefix, start []byte) ethdb.Iterator
- func (k *KVAdapter) Put(key, value []byte) error
- func (k *KVAdapter) Stat(property string) (string, error)
Constants ¶
const DefaultChainID = 1074 // IOTA -- get it?
Variables ¶
var ( ErrBlockDoesNotExist = errors.New("block does not exist in blockchain") ErrTransactionDoesNotExist = errors.New("transaction does not exist") )
var ( TxGas = uint64(21000) // gas cost of simple transfer (not contract creation / call) GasLimitDefault = uint64(15000000) GasPrice = big.NewInt(0) )
Functions ¶
func InitGenesis ¶
func MakeConfig ¶
func MakeConfig(chainID int) *params.ChainConfig
Types ¶
type EVMEmulator ¶
type EVMEmulator struct {
// contains filtered or unexported fields
}
func NewEVMEmulator ¶
func NewEVMEmulator(db ethdb.Database, timestamp ...uint64) *EVMEmulator
func (*EVMEmulator) BalanceAt ¶
BalanceAt returns the wei balance of a certain account in the blockchain.
func (*EVMEmulator) BlockByHash ¶
func (e *EVMEmulator) BlockByHash(hash common.Hash) *types.Block
BlockByHash retrieves a block based on the block hash.
func (*EVMEmulator) BlockByNumber ¶
BlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.
func (*EVMEmulator) Blockchain ¶
func (e *EVMEmulator) Blockchain() *core.BlockChain
Blockchain returns the underlying blockchain.
func (*EVMEmulator) CallContract ¶
func (e *EVMEmulator) CallContract(call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContract executes a contract call.
func (*EVMEmulator) Close ¶
func (e *EVMEmulator) Close() error
Close terminates the underlying blockchain's update loop.
func (*EVMEmulator) CodeAt ¶
CodeAt returns the code associated with a certain account in the blockchain.
func (*EVMEmulator) Commit ¶
func (e *EVMEmulator) Commit()
Commit imports all the pending transactions as a single block and starts a fresh new state.
func (*EVMEmulator) EstimateGas ¶
func (e *EVMEmulator) EstimateGas(call ethereum.CallMsg) (uint64, error)
EstimateGas executes the requested code against the currently pending block/state and returns the used amount of gas.
func (*EVMEmulator) FilterLogs ¶
func (e *EVMEmulator) FilterLogs(query *ethereum.FilterQuery) ([]*types.Log, error)
FilterLogs executes a log filter operation, blocking during execution and returning all the results in one batch.
func (*EVMEmulator) HeaderByHash ¶
HeaderByHash returns a block header from the current canonical chain.
func (*EVMEmulator) HeaderByNumber ¶
HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.
func (*EVMEmulator) PendingNonceAt ¶
func (e *EVMEmulator) PendingNonceAt(account common.Address) (uint64, error)
PendingNonceAt implements PendingStateReader.PendingNonceAt, retrieving the nonce currently pending for the account.
func (*EVMEmulator) Rollback ¶
func (e *EVMEmulator) Rollback(timestamp uint64)
Rollback aborts all pending transactions, reverting to the last committed state.
func (*EVMEmulator) SendTransaction ¶
func (e *EVMEmulator) SendTransaction(tx *types.Transaction) (*types.Receipt, error)
SendTransaction updates the pending block to include the given transaction. It returns an error if the transaction is invalid.
func (*EVMEmulator) Signer ¶
func (e *EVMEmulator) Signer() types.Signer
func (*EVMEmulator) StorageAt ¶
func (e *EVMEmulator) StorageAt(contract common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
StorageAt returns the value of key in the storage of an account in the blockchain.
func (*EVMEmulator) SuggestGasPrice ¶
func (e *EVMEmulator) SuggestGasPrice() (*big.Int, error)
SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated chain doesn't have miners, we just return a gas price of 1 for any call.
func (*EVMEmulator) TransactionByHash ¶
func (e *EVMEmulator) TransactionByHash(txHash common.Hash) *types.Transaction
func (*EVMEmulator) TransactionCount ¶
func (e *EVMEmulator) TransactionCount(blockHash common.Hash) (uint, error)
TransactionCount returns the number of transactions in a given block.
func (*EVMEmulator) TransactionInBlock ¶
func (e *EVMEmulator) TransactionInBlock(blockHash common.Hash, index uint) (*types.Transaction, error)
TransactionInBlock returns the transaction for a specific block at a specific index.
func (*EVMEmulator) TransactionReceipt ¶
TransactionReceipt returns the receipt of a transaction.
type KVAdapter ¶
type KVAdapter struct {
// contains filtered or unexported fields
}
KVAdapter implements ethdb.KeyValueStore with a kv.KVStore as backend
func NewKVAdapter ¶
func (*KVAdapter) Compact ¶
Compact flattens the underlying data store for the given key range. In essence, deleted and overwritten versions are discarded, and the data is rearranged to reduce the cost of operations needed to access them.
A nil start is treated as a key before all keys in the data store; a nil limit is treated as a key after all keys in the data store. If both is nil then it will compact entire data store.
func (*KVAdapter) NewBatch ¶
NewBatch creates a write-only database that buffers changes to its host db until a final write is called.
func (*KVAdapter) NewIterator ¶
NewIterator creates a binary-alphabetical iterator over a subset of database content with a particular key prefix, starting at a particular initial key (or after, if it does not exist).
Note: This method assumes that the prefix is NOT part of the start, so there's no need for the caller to prepend the prefix to the start
Directories ¶
Path | Synopsis |
---|---|
package jsonrpc implements JSON-RPC endpoints according to https://eth.wiki/json-rpc/API
|
package jsonrpc implements JSON-RPC endpoints according to https://eth.wiki/json-rpc/API |