github.com/amazechain/amc@v0.1.3/internal/vm/evmtypes/evmtypes.go (about) 1 package evmtypes 2 3 import ( 4 "github.com/amazechain/amc/common/block" 5 "github.com/amazechain/amc/common/transaction" 6 "math/big" 7 8 libcommon "github.com/amazechain/amc/common/types" 9 "github.com/holiman/uint256" 10 ) 11 12 // BlockContext provides the EVM with auxiliary information. Once provided 13 // it shouldn't be modified. 14 type BlockContext struct { 15 // CanTransfer returns whether the account contains 16 // sufficient ether to transfer the value 17 CanTransfer CanTransferFunc 18 // Transfer transfers ether from one account to the other 19 Transfer TransferFunc 20 // GetHash returns the hash corresponding to n 21 GetHash GetHashFunc 22 23 // Block information 24 Coinbase libcommon.Address // Provides information for COINBASE 25 GasLimit uint64 // Provides information for GASLIMIT 26 MaxGasLimit bool // Use GasLimit override for 2^256-1 (to be compatible with OpenEthereum's trace_call) 27 BlockNumber uint64 // Provides information for NUMBER 28 Time uint64 // Provides information for TIME 29 Difficulty *big.Int // Provides information for DIFFICULTY 30 BaseFee *uint256.Int // Provides information for BASEFEE 31 PrevRanDao *libcommon.Hash // Provides information for PREVRANDAO 32 } 33 34 // TxContext provides the EVM with information about a transaction. 35 // All fields can change between transactions. 36 type TxContext struct { 37 // Message information 38 TxHash libcommon.Hash 39 Origin libcommon.Address // Provides information for ORIGIN 40 GasPrice *uint256.Int // Provides information for GASPRICE 41 } 42 43 type ( 44 // CanTransferFunc is the signature of a transfer guard function 45 CanTransferFunc func(IntraBlockState, libcommon.Address, *uint256.Int) bool 46 // TransferFunc is the signature of a transfer function 47 TransferFunc func(IntraBlockState, libcommon.Address, libcommon.Address, *uint256.Int, bool) 48 // GetHashFunc returns the nth block hash in the blockchain 49 // and is used by the BLOCKHASH EVM op code. 50 GetHashFunc func(uint64) libcommon.Hash 51 ) 52 53 // IntraBlockState is an EVM database for full state querying. 54 type IntraBlockState interface { 55 CreateAccount(libcommon.Address, bool) 56 57 SubBalance(libcommon.Address, *uint256.Int) 58 AddBalance(libcommon.Address, *uint256.Int) 59 GetBalance(libcommon.Address) *uint256.Int 60 61 GetNonce(libcommon.Address) uint64 62 SetNonce(libcommon.Address, uint64) 63 64 GetCodeHash(libcommon.Address) libcommon.Hash 65 GetCode(libcommon.Address) []byte 66 SetCode(libcommon.Address, []byte) 67 GetCodeSize(libcommon.Address) int 68 69 AddRefund(uint64) 70 SubRefund(uint64) 71 GetRefund() uint64 72 73 GetCommittedState(libcommon.Address, *libcommon.Hash, *uint256.Int) 74 GetState(address libcommon.Address, slot *libcommon.Hash, outValue *uint256.Int) 75 SetState(libcommon.Address, *libcommon.Hash, uint256.Int) 76 77 Selfdestruct(libcommon.Address) bool 78 HasSelfdestructed(libcommon.Address) bool 79 80 // Exist reports whether the given account exists in state. 81 // Notably this should also return true for suicided accounts. 82 Exist(libcommon.Address) bool 83 // Empty returns whether the given account is empty. Empty 84 // is defined according to EIP161 (balance = nonce = code = 0). 85 Empty(libcommon.Address) bool 86 87 PrepareAccessList(sender libcommon.Address, dest *libcommon.Address, precompiles []libcommon.Address, txAccesses transaction.AccessList) 88 AddressInAccessList(addr libcommon.Address) bool 89 SlotInAccessList(addr libcommon.Address, slot libcommon.Hash) (addressOk bool, slotOk bool) 90 // AddAddressToAccessList adds the given address to the access list. This operation is safe to perform 91 // even if the feature/fork is not active yet 92 AddAddressToAccessList(addr libcommon.Address) 93 // AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform 94 // even if the feature/fork is not active yet 95 AddSlotToAccessList(addr libcommon.Address, slot libcommon.Hash) 96 97 RevertToSnapshot(int) 98 Snapshot() int 99 100 AddLog(*block.Log) 101 }