/
remote_script_runner.go
59 lines (51 loc) · 1.37 KB
/
remote_script_runner.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
56
57
58
59
package main
import (
"github.com/rs/zerolog"
"math"
"github.com/onflow/cadence"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/state"
"github.com/onflow/flow-go/model/flow"
)
type RemoteDebugger struct {
vm *fvm.VirtualMachine
ctx fvm.Context
view state.View
}
func NewRemoteDebugger(
view *RemoteView,
chain flow.Chain,
logger zerolog.Logger) *RemoteDebugger {
vm := fvm.NewVirtualMachine()
ctx := fvm.NewContext(
fvm.WithLogger(logger),
fvm.WithChain(chain),
fvm.WithComputationLimit(math.MaxUint64),
fvm.WithMemoryLimit(math.MaxUint64),
fvm.WithMaxStateInteractionSize(math.MaxUint64),
fvm.WithContractRemovalRestricted(false),
fvm.WithAuthorizationChecksEnabled(false),
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
)
return &RemoteDebugger{
ctx: ctx,
vm: vm,
view: view,
}
}
func (d *RemoteDebugger) RunScript(script *fvm.ScriptProcedure) (value cadence.Value, scriptError, processError error) {
scriptCtx := fvm.NewContextFromParent(d.ctx)
err := d.vm.Run(scriptCtx, script, d.view)
if err != nil {
return nil, nil, err
}
return script.Value, script.Err, nil
}
func (d *RemoteDebugger) RunTransaction(tx *fvm.TransactionProcedure) (txError, processError error) {
scriptCtx := fvm.NewContextFromParent(d.ctx)
err := d.vm.Run(scriptCtx, tx, d.view)
if err != nil {
return nil, err
}
return tx.Err, nil
}