github.com/dim4egster/coreth@v0.10.2/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/dim4egster/coreth/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  	SubBalanceMultiCoin(common.Address, common.Hash, *big.Int)
    45  	AddBalanceMultiCoin(common.Address, common.Hash, *big.Int)
    46  	GetBalanceMultiCoin(common.Address, common.Hash) *big.Int
    47  
    48  	GetNonce(common.Address) uint64
    49  	SetNonce(common.Address, uint64)
    50  
    51  	GetCodeHash(common.Address) common.Hash
    52  	GetCode(common.Address) []byte
    53  	SetCode(common.Address, []byte)
    54  	GetCodeSize(common.Address) int
    55  
    56  	AddRefund(uint64)
    57  	SubRefund(uint64)
    58  	GetRefund() uint64
    59  
    60  	GetCommittedState(common.Address, common.Hash) common.Hash
    61  	GetCommittedStateAP1(common.Address, common.Hash) common.Hash
    62  	GetState(common.Address, common.Hash) common.Hash
    63  	SetState(common.Address, common.Hash, common.Hash)
    64  
    65  	Suicide(common.Address) bool
    66  	HasSuicided(common.Address) bool
    67  
    68  	// Exist reports whether the given account exists in state.
    69  	// Notably this should also return true for suicided accounts.
    70  	Exist(common.Address) bool
    71  	// Empty returns whether the given account is empty. Empty
    72  	// is defined according to EIP161 (balance = nonce = code = 0).
    73  	Empty(common.Address) bool
    74  
    75  	PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
    76  	AddressInAccessList(addr common.Address) bool
    77  	SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
    78  	// AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
    79  	// even if the feature/fork is not active yet
    80  	AddAddressToAccessList(addr common.Address)
    81  	// AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
    82  	// even if the feature/fork is not active yet
    83  	AddSlotToAccessList(addr common.Address, slot common.Hash)
    84  
    85  	RevertToSnapshot(int)
    86  	Snapshot() int
    87  
    88  	AddLog(*types.Log)
    89  	AddPreimage(common.Hash, []byte)
    90  
    91  	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
    92  }
    93  
    94  // CallContext provides a basic interface for the EVM calling conventions. The EVM
    95  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
    96  type CallContext interface {
    97  	// Call another contract
    98  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    99  	CallExpert(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int, coinID *common.Hash, value2 *big.Int) ([]byte, error)
   100  	// Take another's contract code and execute within our own context
   101  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
   102  	// Same as CallCode except sender and value is propagated from parent to child scope
   103  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
   104  	// Create a new contract
   105  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
   106  }