github.com/amazechain/amc@v0.1.3/internal/vm/interface.go (about) 1 // Copyright 2023 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 import ( 20 "github.com/amazechain/amc/internal/vm/evmtypes" 21 "github.com/amazechain/amc/params" 22 "math/big" 23 24 "github.com/holiman/uint256" 25 26 "github.com/amazechain/amc/common/types" 27 ) 28 29 // CallContext provides a basic interface for the EVM calling conventions. The EVM 30 // depends on this context being implemented for doing subcalls and initialising new EVM contracts. 31 type CallContext interface { 32 // Call another contract 33 Call(env *EVM, me ContractRef, addr types.Address, data []byte, gas, value *big.Int) ([]byte, error) 34 // Take another's contract code and execute within our own context 35 CallCode(env *EVM, me ContractRef, addr types.Address, data []byte, gas, value *big.Int) ([]byte, error) 36 // Same as CallCode except sender and value is propagated from parent to child scope 37 DelegateCall(env *EVM, me ContractRef, addr types.Address, data []byte, gas *big.Int) ([]byte, error) 38 // Create a new contract 39 Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, types.Address, error) 40 } 41 42 // VMInterface exposes the EVM interface for external callers. 43 type VMInterface interface { 44 Reset(txCtx evmtypes.TxContext, ibs evmtypes.IntraBlockState) 45 Create(caller ContractRef, code []byte, gas uint64, value *uint256.Int) (ret []byte, contractAddr types.Address, leftOverGas uint64, err error) 46 Call(caller ContractRef, addr types.Address, input []byte, gas uint64, value *uint256.Int, bailout bool) (ret []byte, leftOverGas uint64, err error) 47 Cancel() 48 Config() Config 49 ChainConfig() *params.ChainConfig 50 ChainRules() *params.Rules 51 Context() evmtypes.BlockContext 52 IntraBlockState() evmtypes.IntraBlockState 53 TxContext() evmtypes.TxContext 54 } 55 56 // VMInterpreter exposes additional EVM methods for use in the interpreter. 57 type VMInterpreter interface { 58 VMInterface 59 Cancelled() bool 60 SetCallGasTemp(gas uint64) 61 CallGasTemp() uint64 62 StaticCall(caller ContractRef, addr types.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) 63 DelegateCall(caller ContractRef, addr types.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) 64 CallCode(caller ContractRef, addr types.Address, input []byte, gas uint64, value *uint256.Int) (ret []byte, leftOverGas uint64, err error) 65 Create2(caller ContractRef, code []byte, gas uint64, endowment *uint256.Int, salt *uint256.Int) (ret []byte, contractAddr types.Address, leftOverGas uint64, err error) 66 }