github.com/onflow/flow-go@v0.33.17/fvm/evm/types/handler.go (about)

     1  package types
     2  
     3  import (
     4  	gethCommon "github.com/ethereum/go-ethereum/common"
     5  	"github.com/onflow/cadence/runtime/common"
     6  
     7  	"github.com/onflow/flow-go/fvm/environment"
     8  )
     9  
    10  // EVM is an account inside FVM with special access to the underlying infrastructure
    11  // which allows to run a virtual EVM-based blockchain inside FVM.
    12  //
    13  // There are two ways to interact with this environment:
    14  //
    15  // First, passing a signed transaction (EOA account) to the `EVM.run` Cadence function
    16  // creates a new block, updates the internal merkle tree, and emits a new root hash.
    17  //
    18  // The Second way is through a new form of account called bridged accounts,
    19  // which is represented and controlled through a resource, owned by a Flow account.
    20  // The owner of the bridged account resource can interact with the evm environment on behalf of the address stored on the resource.
    21  //
    22  // The evm environment shares the same native token as Flow, there are no new tokens minted.
    23  // Other ERC-20 fungible tokens can be bridged between bridged account resources and Flow accounts.
    24  
    25  // ContractHandler handles operations on the evm environment
    26  type ContractHandler interface {
    27  	// AllocateAddress allocates an address to be used by a bridged account resource
    28  	AllocateAddress() Address
    29  
    30  	// AccountByAddress returns an account by address
    31  	// if isAuthorized is set, it allows for functionality like `call`, `deploy`
    32  	// should only be set for bridged accounts only.
    33  	AccountByAddress(address Address, isAuthorized bool) Account
    34  
    35  	// LastExecutedBlock returns information about the last executed block
    36  	LastExecutedBlock() *Block
    37  
    38  	// Run runs a transaction in the evm environment,
    39  	// collects the gas fees, and transfers the gas fees to the given coinbase account.
    40  	Run(tx []byte, coinbase Address)
    41  
    42  	FlowTokenAddress() common.Address
    43  }
    44  
    45  // Backend passes the FVM functionality needed inside the handler
    46  type Backend interface {
    47  	environment.ValueStore
    48  	environment.Meter
    49  	environment.EventEmitter
    50  }
    51  
    52  // AddressAllocator allocates addresses, used by the handler
    53  type AddressAllocator interface {
    54  	// AllocateAddress allocates an address to be used by a bridged account resource
    55  	AllocateAddress() (Address, error)
    56  }
    57  
    58  // BlockStore stores the chain of blocks
    59  type BlockStore interface {
    60  	// LatestBlock returns the latest appended block
    61  	LatestBlock() (*Block, error)
    62  
    63  	// BlockHash returns the hash of the block at the given height
    64  	BlockHash(height int) (gethCommon.Hash, error)
    65  
    66  	// BlockProposal returns the block proposal
    67  	BlockProposal() (*Block, error)
    68  
    69  	// CommitBlockProposal commits the block proposal and update the chain of blocks
    70  	CommitBlockProposal() error
    71  
    72  	// ResetBlockProposal resets the block proposal
    73  	ResetBlockProposal() error
    74  }