Skip to content

Commit b7e2e95

Browse files
committed
tons of chnages
1 parent 6e9eef0 commit b7e2e95

File tree

8 files changed

+754
-21
lines changed

8 files changed

+754
-21
lines changed

bitsource.py

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def tx_lookup(txhash):
3232
c=connect('getrawtransaction',[txhash,1])
3333
return c
3434

35-
def tx_inputs(txhash, dest_address):
35+
def tx_inputs(txhash):
3636
txdata=tx_lookup(txhash)
3737

38-
global prevtxids
38+
global prevtxidsq
3939
automatic=False
4040
txins=txdata['vin']
4141
prevtxids=[]
@@ -86,6 +86,12 @@ def txs_in_block(n):
8686
print "This took: "+str(duration)+" seconds"
8787
return t
8888

89+
def color_address(publicaddress):
90+
a=requests.get('https://blockexplorer.com/q/addresstohash/')
91+
hashed=a.content #REPLACE THIS METHOD
92+
93+
94+
8995

9096
def read_tx(txhash):
9197
r=tx_lookup(txhash)
@@ -112,15 +118,142 @@ def op_return_in_block(n):
112118
return messages
113119

114120
def parse_colored_tx(metadata):
121+
global d,e,g, count,f, hexmetadata
115122
hexmetadata=metadata.encode('hex')
116123
opcode=metadata[0:2]
124+
results={}
117125
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+
120248

249+
results.append(r)
121250

251+
return results
122252

253+
def init():
254+
print oa_in_block(301271)
123255

256+
init()
124257

125258
t='fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4'
126259
tt='38bddbe81111a6209f87eb59d6a6ac019d07a4d90dcc2f361b6a81eb1bafdb89'

bitsource.pyc

2.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)