evm

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0, BSD-2-Clause Imports: 25 Imported by: 0

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

View Source
const DefaultChainID = 1074 // IOTA -- get it?

Variables

View Source
var (
	ErrBlockDoesNotExist       = errors.New("block does not exist in blockchain")
	ErrTransactionDoesNotExist = errors.New("transaction does not exist")
)
View Source
var (
	TxGas           = uint64(21000) // gas cost of simple transfer (not contract creation / call)
	GasLimitDefault = uint64(15000000)
	GasPrice        = big.NewInt(0)
)

Functions

func InitGenesis

func InitGenesis(chainID int, db ethdb.Database, alloc core.GenesisAlloc, gasLimit, timestamp uint64)

func MakeConfig

func MakeConfig(chainID int) *params.ChainConfig

func Signer

func Signer(chainID *big.Int) types.Signer

Types

type EVMEmulator

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

func NewEVMEmulator

func NewEVMEmulator(db ethdb.Database, timestamp ...uint64) *EVMEmulator

func (*EVMEmulator) BalanceAt

func (e *EVMEmulator) BalanceAt(contract common.Address, blockNumber *big.Int) (*big.Int, error)

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

func (e *EVMEmulator) BlockByNumber(number *big.Int) (*types.Block, error)

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

func (e *EVMEmulator) CodeAt(contract common.Address, blockNumber *big.Int) ([]byte, error)

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

func (e *EVMEmulator) HeaderByHash(hash common.Hash) (*types.Header, error)

HeaderByHash returns a block header from the current canonical chain.

func (*EVMEmulator) HeaderByNumber

func (e *EVMEmulator) HeaderByNumber(block *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*EVMEmulator) NonceAt

func (e *EVMEmulator) NonceAt(contract common.Address, blockNumber *big.Int) (uint64, error)

NonceAt returns the nonce of a certain account in the blockchain.

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

func (e *EVMEmulator) TransactionReceipt(txHash common.Hash) (*types.Receipt, error)

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 NewKVAdapter(store kv.KVStore) *KVAdapter

func (*KVAdapter) Close

func (k *KVAdapter) Close() error

func (*KVAdapter) Compact

func (k *KVAdapter) Compact(start, limit []byte) error

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) Delete

func (k *KVAdapter) Delete(key []byte) error

Delete removes the key from the key-value data store.

func (*KVAdapter) Get

func (k *KVAdapter) Get(key []byte) ([]byte, error)

Get retrieves the given key if it's present in the key-value data store.

func (*KVAdapter) Has

func (k *KVAdapter) Has(key []byte) (bool, error)

Has retrieves if a key is present in the key-value data store.

func (*KVAdapter) NewBatch

func (k *KVAdapter) NewBatch() ethdb.Batch

NewBatch creates a write-only database that buffers changes to its host db until a final write is called.

func (*KVAdapter) NewIterator

func (k *KVAdapter) NewIterator(prefix, start []byte) ethdb.Iterator

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

func (*KVAdapter) Put

func (k *KVAdapter) Put(key, value []byte) error

Put inserts the given value into the key-value data store.

func (*KVAdapter) Stat

func (k *KVAdapter) Stat(property string) (string, error)

Stat returns a particular internal stat of the database.

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

Jump to

Keyboard shortcuts

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