MCPcopy Create free account
hub / github.com/chain/txvm / Validate

Function Validate

protocol/txvm/vm.go:100–120  ·  view source on GitHub ↗

Validate is the main entrypoint to txvm. It runs the given program, producing its transaction ID if it gets as far as a "finalize" instruction. Other runtime information can be inspected via callbacks, which are supplied via the Option arguments.

(prog []byte, txVersion, runlimit int64, o ...Option)

Source from the content-addressed store, hash-verified

98// instruction. Other runtime information can be inspected via
99// callbacks, which are supplied via the Option arguments.
100func Validate(prog []byte, txVersion, runlimit int64, o ...Option) (*VM, error) {
101 if txVersion < 3 {
102 return nil, ErrVersion
103 }
104
105 con := &contract{seed: emptySeed, program: prog, typecode: ContractCode}
106 vm := &VM{
107 txVersion: txVersion,
108 runlimit: runlimit,
109 contract: con,
110 caller: emptySeed,
111 }
112
113 for _, o := range o {
114 o.apply(vm)
115 }
116
117 err := vm.validate(prog)
118 vm.runHooks(vm.onExit)
119 return vm, err
120}
121
122func (vm *VM) validate(txprog []byte) (err error) {
123 defer vm.recoverError(&err)

Callers 11

TestVMFuzzFunction · 0.92
TestNoValidateFunction · 0.92
TestValidateFunction · 0.92
TestOptionsFunction · 0.92
TestRunlimitsFunction · 0.92
measureProgramFunction · 0.92
addSigFunction · 0.92
addPayToSigFunction · 0.92
NewTxFunction · 0.92
mainFunction · 0.92
BenchmarkExampleTxFunction · 0.85

Calls 2

validateMethod · 0.95
runHooksMethod · 0.95

Tested by 7

TestVMFuzzFunction · 0.74
TestNoValidateFunction · 0.74
TestValidateFunction · 0.74
TestOptionsFunction · 0.74
TestRunlimitsFunction · 0.74
measureProgramFunction · 0.74
BenchmarkExampleTxFunction · 0.68