github.com/r8d8/go-ethereum@v5.5.2+incompatible/core/vm/environment.go (about) 1 // Copyright 2014 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/ethereumproject/go-ethereum/common" 23 ) 24 25 // RuleSet is an interface that defines the current rule set during the 26 // execution of the EVM instructions (e.g. whether it's homestead) 27 type RuleSet interface { 28 IsHomestead(*big.Int) bool 29 // GasTable returns the gas prices for this phase, which is based on 30 // block number passed in. 31 GasTable(*big.Int) *GasTable 32 } 33 34 // Environment is an EVM requirement and helper which allows access to outside 35 // information such as states. 36 type Environment interface { 37 // The current ruleset 38 RuleSet() RuleSet 39 // The state database 40 Db() Database 41 // Creates a restorable snapshot 42 SnapshotDatabase() int 43 // Set database to previous snapshot 44 RevertToSnapshot(int) 45 // Address of the original invoker (first occurrence of the VM invoker) 46 Origin() common.Address 47 // The block number this VM is invoked on 48 BlockNumber() *big.Int 49 // The n'th hash ago from this block number 50 GetHash(uint64) common.Hash 51 // The handler's address 52 Coinbase() common.Address 53 // The current time (block time) 54 Time() *big.Int 55 // Difficulty set on the current block 56 Difficulty() *big.Int 57 // The gas limit of the block 58 GasLimit() *big.Int 59 // Determines whether it's possible to transact 60 CanTransfer(from common.Address, balance *big.Int) bool 61 // Transfers amount from one account to the other 62 Transfer(from, to Account, amount *big.Int) 63 // Adds a LOG to the state 64 AddLog(*Log) 65 // Type of the VM 66 Vm() Vm 67 // Get the curret calling depth 68 Depth() int 69 // Set the current calling depth 70 SetDepth(i int) 71 // Call another contract 72 Call(me ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) 73 // Take another's contract code and execute within our own context 74 CallCode(me ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) 75 // Same as CallCode except sender and value is propagated from parent to child scope 76 DelegateCall(me ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error) 77 // Create a new contract 78 Create(me ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) 79 } 80 81 // Vm is the basic interface for an implementation of the EVM. 82 type Vm interface { 83 // Run should execute the given contract with the input given in in 84 // and return the contract execution return bytes or an error if it 85 // failed. 86 Run(c *Contract, in []byte) ([]byte, error) 87 } 88 89 // Database is a EVM database for full state querying. 90 type Database interface { 91 GetAccount(common.Address) Account 92 CreateAccount(common.Address) Account 93 94 AddBalance(common.Address, *big.Int) 95 GetBalance(common.Address) *big.Int 96 97 GetNonce(common.Address) uint64 98 SetNonce(common.Address, uint64) 99 100 GetCodeHash(common.Address) common.Hash 101 GetCodeSize(common.Address) int 102 GetCode(common.Address) []byte 103 SetCode(common.Address, []byte) 104 105 AddRefund(*big.Int) 106 GetRefund() *big.Int 107 108 GetState(common.Address, common.Hash) common.Hash 109 SetState(common.Address, common.Hash, common.Hash) 110 111 Suicide(common.Address) bool 112 HasSuicided(common.Address) bool 113 114 // Exist reports whether the given account exists in state. 115 // Notably this should also return true for suicided accounts. 116 Exist(common.Address) bool 117 } 118 119 // Account represents a contract or basic ethereum account. 120 type Account interface { 121 SubBalance(amount *big.Int) 122 AddBalance(amount *big.Int) 123 SetBalance(*big.Int) 124 SetNonce(uint64) 125 Balance() *big.Int 126 Address() common.Address 127 ReturnGas(*big.Int, *big.Int) 128 SetCode(common.Hash, []byte) 129 ForEachStorage(cb func(key, value common.Hash) bool) 130 Value() *big.Int 131 }