Execute executes the code using the input as call data during the execution. It returns the EVM's return value, the new state and an error if it failed. Executes sets up a in memory, temporarily, environment for the execution of the given code. It makes sure that it's restored to it's original stat
(code, input []byte, cfg *Config)
| 87 | // Executes sets up a in memory, temporarily, environment for the execution of |
| 88 | // the given code. It makes sure that it's restored to it's original state afterwards. |
| 89 | func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { |
| 90 | if cfg == nil { |
| 91 | cfg = new(Config) |
| 92 | } |
| 93 | setDefaults(cfg) |
| 94 | |
| 95 | if cfg.State == nil { |
| 96 | cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 97 | } |
| 98 | var ( |
| 99 | address = common.BytesToAddress([]byte("contract")) |
| 100 | vmenv = NewEnv(cfg) |
| 101 | sender = vm.AccountRef(cfg.Origin) |
| 102 | ) |
| 103 | cfg.State.CreateAccount(address) |
| 104 | // set the receiver's (the executing contract) code for execution. |
| 105 | cfg.State.SetCode(address, code) |
| 106 | // Call the code with the given configuration. |
| 107 | ret, _, err := vmenv.Call( |
| 108 | sender, |
| 109 | common.BytesToAddress([]byte("contract")), |
| 110 | input, |
| 111 | cfg.GasLimit, |
| 112 | cfg.Value, |
| 113 | ) |
| 114 | |
| 115 | return ret, cfg.State, err |
| 116 | } |
| 117 | |
| 118 | // Create executes the code using the EVM create method |
| 119 | func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { |