MCPcopy Create free account
hub / github.com/CPChain/chain / Execute

Function Execute

core/vm/runtime/runtime.go:89–116  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
89func 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
119func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {

Callers 4

FuzzFunction · 0.85
TestEVMFunction · 0.85
TestExecuteFunction · 0.85
BenchmarkCallFunction · 0.85

Calls 5

setDefaultsFunction · 0.85
NewEnvFunction · 0.85
CreateAccountMethod · 0.65
SetCodeMethod · 0.65
CallMethod · 0.65

Tested by 3

TestEVMFunction · 0.68
TestExecuteFunction · 0.68
BenchmarkCallFunction · 0.68