emulator

package
v0.35.15-crescendo-pre... Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 14 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBlockLevelGasLimit = uint64(math.MaxUint64)
	DefaultBaseFee            = big.NewInt(0)
)
View Source
var DefaultChainConfig = &gethParams.ChainConfig{
	ChainID: types.FlowEVMPreviewNetChainID,

	HomesteadBlock:      bigZero,
	DAOForkBlock:        bigZero,
	DAOForkSupport:      false,
	EIP150Block:         bigZero,
	EIP155Block:         bigZero,
	EIP158Block:         bigZero,
	ByzantiumBlock:      bigZero,
	ConstantinopleBlock: bigZero,
	PetersburgBlock:     bigZero,
	IstanbulBlock:       bigZero,
	BerlinBlock:         bigZero,
	LondonBlock:         bigZero,
	MuirGlacierBlock:    bigZero,

	ShanghaiTime: &zero,
	CancunTime:   &zero,
	PragueTime:   &zero,
}

DefaultChainConfig is the default chain config which considers majority of EVM upgrades (e.g. Shanghai update) already been applied this has done through setting the height of these changes to zero nad setting the time for some other changes to zero For the future changes of EVM, we need to update the EVM go mod version and set a proper height for the specific release based on the Flow EVM heights so it could gets activated at a desired time.

Functions

func GetDefaultSigner

func GetDefaultSigner() types.Signer

GetDefaultSigner returns a signer which is compatible with the default config

func GetSigner

func GetSigner(cfg *Config) types.Signer

GetSigner returns a evm signer object that is compatible with the given config

Despite its misleading name, signer encapsulates transaction signature validation functionality and does not provide actual signing functionality. we kept the same name to be consistent with EVM naming.

Types

type BlockView

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

BlockView allows mutation of the evm state as part of a block

TODO: allow multiple calls per block view TODO: add block level commit (separation of trie commit to storage)

func (*BlockView) BatchRunTransactions added in v0.33.30

func (bl *BlockView) BatchRunTransactions(txs []*gethTypes.Transaction) ([]*types.Result, error)

func (*BlockView) DirectCall

func (bl *BlockView) DirectCall(call *types.DirectCall) (*types.Result, error)

DirectCall executes a direct call

func (*BlockView) DryRunTransaction added in v0.33.30

func (bl *BlockView) DryRunTransaction(
	tx *gethTypes.Transaction,
	from gethCommon.Address,
) (*types.Result, error)

DryRunTransaction run unsigned transaction without persisting the state

func (*BlockView) RunTransaction

func (bl *BlockView) RunTransaction(
	tx *gethTypes.Transaction,
) (*types.Result, error)

RunTransaction runs an evm transaction

type Config

type Config struct {
	// Chain Config
	ChainConfig *gethParams.ChainConfig
	// EVM config
	EVMConfig gethVM.Config
	// block context
	BlockContext *gethVM.BlockContext
	// transaction context
	TxContext *gethVM.TxContext
	// base unit of gas for direct calls
	DirectCallBaseGasUsage uint64
}

Config sets the required parameters

func NewConfig

func NewConfig(opts ...Option) *Config

NewConfig initializes a new config

func (*Config) ChainRules added in v0.33.30

func (c *Config) ChainRules() gethParams.Rules

type Emulator

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

Emulator handles operations against evm runtime

func NewEmulator

func NewEmulator(
	ledger atree.Ledger,
	rootAddr flow.Address,
) *Emulator

NewEmulator constructs a new EVM Emulator

func (*Emulator) NewBlockView

func (em *Emulator) NewBlockView(ctx types.BlockContext) (types.BlockView, error)

NewBlockView constructs a new block view (mutable)

func (*Emulator) NewReadOnlyBlockView

func (em *Emulator) NewReadOnlyBlockView(ctx types.BlockContext) (types.ReadOnlyBlockView, error)

NewReadOnlyBlockView constructs a new readonly block view

type Option

type Option func(*Config) *Config

func WithBlockNumber

func WithBlockNumber(blockNumber *big.Int) Option

WithBlockNumber sets the block height in the block context

func WithBlockTime

func WithBlockTime(time uint64) Option

WithBlockTime sets the block time in the block context

func WithChainID added in v0.33.30

func WithChainID(chainID *big.Int) Option

WithChainID sets the evm chain ID

func WithCoinbase

func WithCoinbase(coinbase gethCommon.Address) Option

WithCoinbase sets the coinbase of the block where the fees are collected in

func WithDirectCallBaseGasUsage

func WithDirectCallBaseGasUsage(gas uint64) Option

WithDirectCallBaseGasUsage sets the base direct call gas usage

func WithExtraPrecompiles added in v0.33.30

func WithExtraPrecompiles(precompiles []types.Precompile) Option

WithExtraPrecompiles appends precompile list with extra precompiles

func WithGasLimit

func WithGasLimit(gasLimit uint64) Option

WithGasLimit sets the gas limit of the transaction

func WithGasPrice

func WithGasPrice(gasPrice *big.Int) Option

WithGasPrice sets the gas price for the transaction (usually the one sets by the sender)

func WithGetBlockHashFunction

func WithGetBlockHashFunction(getHash gethVM.GetHashFunc) Option

WithGetBlockHashFunction sets the functionality to look up block hash by height

func WithOrigin

func WithOrigin(origin gethCommon.Address) Option

WithOrigin sets the origin of the transaction (signer)

func WithRandom added in v0.33.30

func WithRandom(rand *gethCommon.Hash) Option

WithRandom sets the block context random field

func WithTransactionTracer added in v0.33.30

func WithTransactionTracer(tracer tracers.Tracer) Option

WithTransactionTracer sets a transaction tracer

type ReadOnlyBlockView

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

ReadOnlyBlockView provides a read only view of a block could be used multiple times for queries

func (*ReadOnlyBlockView) BalanceOf

func (bv *ReadOnlyBlockView) BalanceOf(address types.Address) (*big.Int, error)

BalanceOf returns the balance of the given address

func (*ReadOnlyBlockView) CodeHashOf added in v0.33.30

func (bv *ReadOnlyBlockView) CodeHashOf(address types.Address) ([]byte, error)

CodeHashOf returns the code hash of the given address

func (*ReadOnlyBlockView) CodeOf

func (bv *ReadOnlyBlockView) CodeOf(address types.Address) (types.Code, error)

CodeOf returns the code of the given address

func (*ReadOnlyBlockView) NonceOf

func (bv *ReadOnlyBlockView) NonceOf(address types.Address) (uint64, error)

NonceOf returns the nonce of the given address

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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