forked from xuperchain/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (46 loc) · 1.41 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package execution
import (
"fmt"
"github.com/hyperledger/burrow/execution/evm"
)
type VMOption string
const (
DebugOpcodes VMOption = "DebugOpcodes"
DumpTokens VMOption = "DumpTokens"
)
type ExecutionConfig struct {
CallStackMaxDepth uint64
DataStackInitialCapacity uint64
DataStackMaxDepth uint64
VMOptions []VMOption `json:",omitempty" toml:",omitempty"`
}
func DefaultExecutionConfig() *ExecutionConfig {
return &ExecutionConfig{
CallStackMaxDepth: 0, // Unlimited by default
DataStackInitialCapacity: evm.DataStackInitialCapacity,
DataStackMaxDepth: 0, // Unlimited by default
}
}
type ExecutionOption func(*executor)
func VMOptions(vmOptions ...func(*evm.VM)) func(*executor) {
return func(exe *executor) {
exe.vmOptions = vmOptions
}
}
func (ec *ExecutionConfig) ExecutionOptions() ([]ExecutionOption, error) {
var exeOptions []ExecutionOption
var vmOptions []func(*evm.VM)
for _, option := range ec.VMOptions {
switch option {
case DebugOpcodes:
vmOptions = append(vmOptions, evm.DebugOpcodes)
case DumpTokens:
vmOptions = append(vmOptions, evm.DumpTokens)
default:
return nil, fmt.Errorf("VM option '%s' not recognised", option)
}
}
vmOptions = append(vmOptions, evm.StackOptions(ec.CallStackMaxDepth, ec.DataStackInitialCapacity, ec.DataStackMaxDepth))
exeOptions = append(exeOptions, VMOptions(vmOptions...))
return exeOptions, nil
}