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)
| 98 | // instruction. Other runtime information can be inspected via |
| 99 | // callbacks, which are supplied via the Option arguments. |
| 100 | func 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 | |
| 122 | func (vm *VM) validate(txprog []byte) (err error) { |
| 123 | defer vm.recoverError(&err) |