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