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