OSDN Git Service

Remove transaction reference data (#416)
[bytom/bytom.git] / protocol / vm / introspection.go
1 package vm
2
3 func opCheckOutput(vm *virtualMachine) error {
4         err := vm.applyCost(16)
5         if err != nil {
6                 return err
7         }
8
9         code, err := vm.pop(true)
10         if err != nil {
11                 return err
12         }
13         vmVersion, err := vm.popInt64(true)
14         if err != nil {
15                 return err
16         }
17         if vmVersion < 0 {
18                 return ErrBadValue
19         }
20         assetID, err := vm.pop(true)
21         if err != nil {
22                 return err
23         }
24         amount, err := vm.popInt64(true)
25         if err != nil {
26                 return err
27         }
28         if amount < 0 {
29                 return ErrBadValue
30         }
31         data, err := vm.pop(true)
32         if err != nil {
33                 return err
34         }
35         index, err := vm.popInt64(true)
36         if err != nil {
37                 return err
38         }
39         if index < 0 {
40                 return ErrBadValue
41         }
42
43         if vm.context.CheckOutput == nil {
44                 return ErrContext
45         }
46
47         ok, err := vm.context.CheckOutput(uint64(index), data, uint64(amount), assetID, uint64(vmVersion), code, vm.expansionReserved)
48         if err != nil {
49                 return err
50         }
51         return vm.pushBool(ok, true)
52 }
53
54 func opAsset(vm *virtualMachine) error {
55         err := vm.applyCost(1)
56         if err != nil {
57                 return err
58         }
59
60         if vm.context.AssetID == nil {
61                 return ErrContext
62         }
63         return vm.push(*vm.context.AssetID, true)
64 }
65
66 func opAmount(vm *virtualMachine) error {
67         err := vm.applyCost(1)
68         if err != nil {
69                 return err
70         }
71
72         if vm.context.Amount == nil {
73                 return ErrContext
74         }
75         return vm.pushInt64(int64(*vm.context.Amount), true)
76 }
77
78 func opProgram(vm *virtualMachine) error {
79         err := vm.applyCost(1)
80         if err != nil {
81                 return err
82         }
83
84         return vm.push(vm.context.Code, true)
85 }
86
87 func opEntryData(vm *virtualMachine) error {
88         err := vm.applyCost(1)
89         if err != nil {
90                 return err
91         }
92
93         if vm.context.EntryData == nil {
94                 return ErrContext
95         }
96
97         return vm.push(*vm.context.EntryData, true)
98 }
99
100 func opIndex(vm *virtualMachine) error {
101         err := vm.applyCost(1)
102         if err != nil {
103                 return err
104         }
105
106         if vm.context.DestPos == nil {
107                 return ErrContext
108         }
109         return vm.pushInt64(int64(*vm.context.DestPos), true)
110 }
111
112 func opEntryID(vm *virtualMachine) error {
113         err := vm.applyCost(1)
114         if err != nil {
115                 return err
116         }
117         return vm.push(vm.context.EntryID, true)
118 }
119
120 func opOutputID(vm *virtualMachine) error {
121         err := vm.applyCost(1)
122         if err != nil {
123                 return err
124         }
125
126         if vm.context.SpentOutputID == nil {
127                 return ErrContext
128         }
129         return vm.push(*vm.context.SpentOutputID, true)
130 }
131
132 func opNonce(vm *virtualMachine) error {
133         err := vm.applyCost(1)
134         if err != nil {
135                 return err
136         }
137
138         if vm.context.AnchorID == nil {
139                 return ErrContext
140         }
141         return vm.push(*vm.context.AnchorID, true)
142 }
143
144 func opBlockHeight(vm *virtualMachine) error {
145         err := vm.applyCost(1)
146         if err != nil {
147                 return err
148         }
149
150         if vm.context.BlockHeight == nil {
151                 return ErrContext
152         }
153         return vm.pushInt64(int64(*vm.context.BlockHeight), true)
154 }