NewTx runs the given txvm program through an instance of the txvm virtual machine, populating a new Tx object with its side effects.
(prog []byte, version, runlimit int64, option ...txvm.Option)
| 122 | // NewTx runs the given txvm program through an instance of the txvm |
| 123 | // virtual machine, populating a new Tx object with its side effects. |
| 124 | func NewTx(prog []byte, version, runlimit int64, option ...txvm.Option) (*Tx, error) { |
| 125 | tx := &Tx{ |
| 126 | RawTx: RawTx{ |
| 127 | Program: prog, |
| 128 | Version: version, |
| 129 | Runlimit: runlimit, |
| 130 | }, |
| 131 | } |
| 132 | option = append(option, txvm.OnFinalize(tx.entryHook), txvm.BeforeStep(tx.stackHook)) |
| 133 | vm, err := txvm.Validate(prog, version, runlimit, option...) |
| 134 | if vm != nil { |
| 135 | tx.Finalized = vm.Finalized |
| 136 | if vm.Finalized { |
| 137 | tx.ID = NewHash(vm.TxID) |
| 138 | } |
| 139 | } |
| 140 | return tx, errors.Wrap(err) |
| 141 | } |
| 142 | |
| 143 | func (tx *Tx) stackHook(vm *txvm.VM) { |
| 144 | switch vm.OpCode() { |