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

Function NewTx

protocol/bc/tx.go:124–141  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
124func 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
143func (tx *Tx) stackHook(vm *txvm.VM) {
144 switch vm.OpCode() {

Callers 8

EmptyTxFunction · 0.92
materializeTxMethod · 0.92
buildFunction · 0.92
mainFunction · 0.92
testBlockFunction · 0.85
FromBytesMethod · 0.85
TestNewTxFunction · 0.85
TestWitnessHashFunction · 0.85

Calls 5

OnFinalizeFunction · 0.92
BeforeStepFunction · 0.92
ValidateFunction · 0.92
WrapFunction · 0.92
NewHashFunction · 0.85

Tested by 3

testBlockFunction · 0.68
TestNewTxFunction · 0.68
TestWitnessHashFunction · 0.68