github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/core/vm/interface.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package vm 13 14 import ( 15 "math/big" 16 17 "github.com/Sberex/go-sberex/common" 18 "github.com/Sberex/go-sberex/core/types" 19 ) 20 21 // StateDB is an EVM database for full state querying. 22 type StateDB interface { 23 CreateAccount(common.Address) 24 25 SubBalance(common.Address, *big.Int) 26 AddBalance(common.Address, *big.Int) 27 GetBalance(common.Address) *big.Int 28 29 GetNonce(common.Address) uint64 30 SetNonce(common.Address, uint64) 31 32 GetCodeHash(common.Address) common.Hash 33 GetCode(common.Address) []byte 34 SetCode(common.Address, []byte) 35 GetCodeSize(common.Address) int 36 37 AddRefund(uint64) 38 GetRefund() uint64 39 40 GetState(common.Address, common.Hash) common.Hash 41 SetState(common.Address, common.Hash, common.Hash) 42 43 Suicide(common.Address) bool 44 HasSuicided(common.Address) bool 45 46 // Exist reports whether the given account exists in state. 47 // Notably this should also return true for suicided accounts. 48 Exist(common.Address) bool 49 // Empty returns whether the given account is empty. Empty 50 // is defined according to EIP161 (balance = nonce = code = 0). 51 Empty(common.Address) bool 52 53 RevertToSnapshot(int) 54 Snapshot() int 55 56 AddLog(*types.Log) 57 AddPreimage(common.Hash, []byte) 58 59 ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) 60 } 61 62 // CallContext provides a basic interface for the EVM calling conventions. The EVM 63 // depends on this context being implemented for doing subcalls and initialising new EVM contracts. 64 type CallContext interface { 65 // Call another contract 66 Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 67 // Take another's contract code and execute within our own context 68 CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) 69 // Same as CallCode except sender and value is propagated from parent to child scope 70 DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) 71 // Create a new contract 72 Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) 73 }