MCPcopy Create free account
hub / github.com/chain/Core / NewTxVMContext

Function NewTxVMContext

protocol/validation/vmcontext.go:25–124  ·  view source on GitHub ↗
(tx *bc.Tx, entry bc.Entry, prog *bc.Program, args [][]byte)

Source from the content-addressed store, hash-verified

23}
24
25func NewTxVMContext(tx *bc.Tx, entry bc.Entry, prog *bc.Program, args [][]byte) *vm.Context {
26 var (
27 numResults = uint64(len(tx.ResultIds))
28 txData = tx.Data.Bytes()
29 entryID = bc.EntryID(entry) // TODO(bobg): pass this in, don't recompute it
30
31 assetID *[]byte
32 amount *uint64
33 entryData *[]byte
34 destPos *uint64
35 anchorID *[]byte
36 spentOutputID *[]byte
37 )
38
39 switch e := entry.(type) {
40 case *bc.Nonce:
41 anchored := tx.Entries[*e.WitnessAnchoredId]
42 if iss, ok := anchored.(*bc.Issuance); ok {
43 a1 := iss.Value.AssetId.Bytes()
44 assetID = &a1
45 amount = &iss.Value.Amount
46 }
47
48 case *bc.Issuance:
49 a1 := e.Value.AssetId.Bytes()
50 assetID = &a1
51 amount = &e.Value.Amount
52 destPos = &e.WitnessDestination.Position
53 d := e.Data.Bytes()
54 entryData = &d
55 a2 := e.AnchorId.Bytes()
56 anchorID = &a2
57
58 case *bc.Spend:
59 spentOutput := tx.Entries[*e.SpentOutputId].(*bc.Output)
60 a1 := spentOutput.Source.Value.AssetId.Bytes()
61 assetID = &a1
62 amount = &spentOutput.Source.Value.Amount
63 destPos = &e.WitnessDestination.Position
64 d := e.Data.Bytes()
65 entryData = &d
66 s := e.SpentOutputId.Bytes()
67 spentOutputID = &s
68
69 case *bc.Output:
70 d := e.Data.Bytes()
71 entryData = &d
72
73 case *bc.Retirement:
74 d := e.Data.Bytes()
75 entryData = &d
76 }
77
78 var txSigHash *[]byte
79 txSigHashFn := func() []byte {
80 if txSigHash == nil {
81 hasher := sha3pool.Get256()
82 defer sha3pool.Put256(hasher)

Callers 1

checkValidFunction · 0.85

Calls 3

BytesMethod · 0.95
ReadFromMethod · 0.95
WriteToMethod · 0.45

Tested by

no test coverage detected