@@ -32,10 +32,10 @@ def tx_lookup(txhash):
32
32
c = connect ('getrawtransaction' ,[txhash ,1 ])
33
33
return c
34
34
35
- def tx_inputs (txhash , dest_address ):
35
+ def tx_inputs (txhash ):
36
36
txdata = tx_lookup (txhash )
37
37
38
- global prevtxids
38
+ global prevtxidsq
39
39
automatic = False
40
40
txins = txdata ['vin' ]
41
41
prevtxids = []
@@ -86,6 +86,12 @@ def txs_in_block(n):
86
86
print "This took: " + str (duration )+ " seconds"
87
87
return t
88
88
89
+ def color_address (publicaddress ):
90
+ a = requests .get ('https://blockexplorer.com/q/addresstohash/' )
91
+ hashed = a .content #REPLACE THIS METHOD
92
+
93
+
94
+
89
95
90
96
def read_tx (txhash ):
91
97
r = tx_lookup (txhash )
@@ -112,15 +118,142 @@ def op_return_in_block(n):
112
118
return messages
113
119
114
120
def parse_colored_tx (metadata ):
121
+ global d ,e ,g , count ,f , hexmetadata
115
122
hexmetadata = metadata .encode ('hex' )
116
123
opcode = metadata [0 :2 ]
124
+ results = {}
117
125
if opcode == 'OA' : #then OA
118
- version_number = metadata [2 :4 ].encode ('hex' )
119
- quantity_count = metadata [4 :5 ].encode ('hex' )
126
+ results ['type' ]= 'OA'
127
+ results ['version' ]= metadata [2 :4 ].encode ('hex' )
128
+ results ['asset_count' ]= int (metadata [4 :5 ].encode ('hex' ))
129
+
130
+ count = 0
131
+ d = []
132
+ for x in metadata [5 :len (metadata )]:
133
+ r = leb128 .hexpiecetobinary (x .encode ('hex' ))
134
+ d .append (r )
135
+ e = []
136
+ r = []
137
+ for x in d :
138
+ r .append (x )
139
+ if x [0 ]== '0' :
140
+ e .append (r )
141
+ r = []
142
+ f = []
143
+
144
+ n = 0
145
+ for x in e :
146
+ if n < int (results ['asset_count' ])+ 1 :
147
+ f .append (leb128 .decode (x ))
148
+ count = count + len (x )
149
+ n = n + 1
150
+
151
+ results ['asset_quantities' ]= f [0 :len (f )- 1 ]
152
+ results ['metadata_length' ]= f [len (f )- 1 ]
153
+ results ['metadata' ]= metadata [5 + count :len (metadata )]
154
+
155
+ return results
156
+
157
+ def oa_tx (txid , inputcolors ):
158
+ txdata = tx_lookup (txid )
159
+ message = read_tx (txid )
160
+ isOA = False
161
+ markerposition = - 1
162
+ result = {}
163
+
164
+ #find marker position and ascertain whether OA
165
+ for x in txdata ['vout' ]:
166
+ if x ['scriptPubKey' ]['hex' ][0 :2 ]== '6a' and isOA == False and x ['scriptPubKey' ]['hex' ][4 :8 ]== '4f41' :
167
+ isOA = True
168
+ markerposition = x ['n' ]
169
+
170
+ #INPUT COLORS IS ARRAY OF DICTIONARIES [ {'color_address':'', 'amount':''}]
171
+ #Tabulate sums of inputs of different colors
172
+ inputsums = {}
173
+ for x in inputcolors :
174
+ inputsums [x ['color_address' ]]= inputsums [x ['color_address' ]]+ x ['amount' ]
175
+
176
+ #If it is OA
177
+ if isOA :
178
+ #get meta data
179
+ result ['meta' ]= parse_colored_tx (message )
180
+ result ['txid' ]= txdata ['txid' ]
181
+
182
+ #Describe Issuing Outputs
183
+ result ['issued' ]= []
184
+ for i in range (0 ,markerposition ):
185
+ k = {}
186
+ amt = result ['meta' ]['asset_quantities' ][i ]
187
+ k ['amount' ]= amt
188
+ k ['color_address' ]= '' #FIGURE THIS PART OUT
189
+ k ['destination_address' ]= txdata ['vout' ][i ]['scriptPubKey' ]['addresses' ][0 ] #ONLY EVER ONE ADDRESS PER OUTPUT
190
+ k ['output_n' ]= i
191
+ result ['issued' ].append (k )
192
+
193
+ #Describe Transfer Outputs
194
+ result ['transferred' ]= []
195
+ for i in range (markerposition ,len (txdata ['vout' ])):
196
+ k = {}
197
+ supposedamt = result ['meta' ]['assetquantities' ][i ] #MIGHT BE WRONG i
198
+ k ['color_address' ]= ''
199
+
200
+ if supposedamt <= inputsums [k ['color_address' ]]: #THERE IS ENOUGH TO TRANSFER
201
+ amt = supposedamt
202
+
203
+ k ['amount' ]= amt
204
+
205
+ k ['destination_address' ]= txdata ['vout' ][i ]['scriptPubKey' ]['addresses' ][0 ]
206
+ k ['output_n' ]= i
207
+ result ['transferred' ].append (k )
208
+
209
+ return result
210
+
211
+
212
+ def oa_in_block (n ):
213
+ messages = op_return_in_block (n )
214
+ results = []
215
+ for x in messages :
216
+ metadata = x [1 ]
217
+ r = {}
218
+
219
+ isOA = False
220
+
221
+ txdata = tx_lookup (x [0 ]) #REDUNDANT CALL
222
+ #POSITION OF MARKER OUTPUT IN ALL OUTPUTS
223
+ markerposition = - 1
224
+ for x in txdata ['vout' ]:
225
+ #MIGHT BE ISSUE HERE WITH OP_PUSHDATA
226
+ if x ['scriptPubKey' ]['hex' ][0 :2 ]== '6a' and isOA == False and x ['scriptPubKey' ]['hex' ][4 :8 ]== '4f41' :
227
+ #IS OPRETURN and is OA
228
+ isOA = True
229
+ markerposition = x ['n' ]
230
+
231
+ if isOA :
232
+ r ['meta' ]= parse_colored_tx (metadata )
233
+ r ['txid' ]= txdata ['txid' ]
234
+
235
+ r ['issued' ]= []
236
+ for i in range (0 ,markerposition ):
237
+ k = {}
238
+ amt = r ['meta' ]['asset_quantities' ][i ]
239
+ k ['amount' ]= amt
240
+ k ['color_address' ]= '' #FIGURE THIS PART OUT
241
+ k ['destination_address' ]= txdata ['vout' ][i ]['scriptPubKey' ]['addresses' ][0 ] #ONLY EVER ONE ADDRESS PER OUTPUT
242
+ r ['issued' ].append (k )
243
+
244
+ r ['transferred' ]= []
245
+
246
+
247
+
120
248
249
+ results .append (r )
121
250
251
+ return results
122
252
253
+ def init ():
254
+ print oa_in_block (301271 )
123
255
256
+ init ()
124
257
125
258
t = 'fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4'
126
259
tt = '38bddbe81111a6209f87eb59d6a6ac019d07a4d90dcc2f361b6a81eb1bafdb89'
0 commit comments