github.com/MetalBlockchain/subnet-evm@v0.4.9/core/vm/interface.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc.
     2  //
     3  // This file is a derived work, based on the go-ethereum library whose original
     4  // notices appear below.
     5  //
     6  // It is distributed under a license compatible with the licensing terms of the
     7  // original code from which it is derived.
     8  //
     9  // Much love to the original authors for their work.
    10  // **********
    11  // Copyright 2016 The go-ethereum Authors
    12  // This file is part of the go-ethereum library.
    13  //
    14  // The go-ethereum library is free software: you can redistribute it and/or modify
    15  // it under the terms of the GNU Lesser General Public License as published by
    16  // the Free Software Foundation, either version 3 of the License, or
    17  // (at your option) any later version.
    18  //
    19  // The go-ethereum library is distributed in the hope that it will be useful,
    20  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    22  // GNU Lesser General Public License for more details.
    23  //
    24  // You should have received a copy of the GNU Lesser General Public License
    25  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    26  
    27  package vm
    28  
    29  import (
    30  	"math/big"
    31  
    32  	"github.com/MetalBlockchain/subnet-evm/core/types"
    33  	"github.com/ethereum/go-ethereum/common"
    34  )
    35  
    36  // StateDB is an EVM database for full state querying.
    37  type StateDB interface {
    38  	CreateAccount(common.Address)
    39  
    40  	SubBalance(common.Address, *big.Int)
    41  	AddBalance(common.Address, *big.Int)
    42  	GetBalance(common.Address) *big.Int
    43  
    44  	GetNonce(common.Address) uint64
    45  	SetNonce(common.Address, uint64)
    46  
    47  	GetCodeHash(common.Address) common.Hash
    48  	GetCode(common.Address) []byte
    49  	SetCode(common.Address, []byte)
    50  	GetCodeSize(common.Address) int
    51  
    52  	AddRefund(uint64)
    53  	SubRefund(uint64)
    54  	GetRefund() uint64
    55  
    56  	GetCommittedState(common.Address, common.Hash) common.Hash
    57  	GetState(common.Address, common.Hash) common.Hash
    58  	SetState(common.Address, common.Hash, common.Hash)
    59  
    60  	Suicide(common.Address) bool
    61  	HasSuicided(common.Address) bool
    62  	Finalise(deleteEmptyObjects bool)
    63  
    64  	// Exist reports whether the given account exists in state.
    65  	// Notably this should also return true for suicided accounts.
    66  	Exist(common.Address) bool
    67  	// Empty returns whether the given account is empty. Empty
    68  	// is defined according to EIP161 (balance = nonce = code = 0).
    69  	Empty(common.Address) bool
    70  
    71  	PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
    72  	AddressInAccessList(addr common.Address) bool
    73  	SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
    74  	// AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
    75  	// even if the feature/fork is not active yet
    76  	AddAddressToAccessList(addr common.Address)
    77  	// AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
    78  	// even if the feature/fork is not active yet
    79  	AddSlotToAccessList(addr common.Address, slot common.Hash)
    80  
    81  	RevertToSnapshot(int)
    82  	Snapshot() int
    83  
    84  	AddLog(addr common.Address, topics []common.Hash, data []byte, blockNumber uint64)
    85  	AddPreimage(common.Hash, []byte)
    86  
    87  	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
    88  }
    89  
    90  // CallContext provides a basic interface for the EVM calling conventions. The EVM
    91  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
    92  type CallContext interface {
    93  	// Call another contract
    94  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    95  	// Take another's contract code and execute within our own context
    96  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    97  	// Same as CallCode except sender and value is propagated from parent to child scope
    98  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
    99  	// Create a new contract
   100  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
   101  }