-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_transactions.py
162 lines (132 loc) · 5.41 KB
/
parse_transactions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/python3
import json, requests, pprint, pickle, logging, sys, os
def get_block(blockhash):
response = os.popen(veild_path+' getblock '+blockhash).read()
return(response)
def get_tx(tx_id):
response = os.popen(veild_path+' getrawtransaction '+tx_id+' true').read()
return(response)
def parse_transaction(transaction):
denoms = []
outputs = []
if 'coinbase' in transaction['vin'][0]:
#print(str(tx)+' is a coinbase transaction')
pass
elif 'type' not in transaction['vin'][0]:
#print(str(tx)+' is a basecoin or stealth spend')
pass
elif transaction['vin'][0]['type'] == 'anon':
#print(str(tx)+' is a RingCT spend')
pass
elif transaction['vin'][0]['type'] == 'zerocoinspend':
#print(str(tx)+' is a Zerocoin spend of some kind')
if len(transaction['vout']) > 1:
if transaction['vout'][1]['scriptPubKey']['type'] == 'zerocoinmint':
#print(str(tx)+' is a Zerocoin stake, ignoring')
pass
return([], [])
if transaction['vout'][0]['type'] == 'standard':
#print(str(tx)+' is a Zerocoin spend to basecoin')
for vinput in transaction['vin']:
if 'denomination' in vinput:
denoms.append(vinput['denomination'])
for output in transaction['vout']:
if 'scriptPubKey' in output:
if len(output['scriptPubKey']['addresses']) > 1:
logging.error(str(tx)+' has more than 1 output per vout')
outputs.append(output['scriptPubKey']['addresses'][0])
elif transaction['vout'][0]['type'] == 'data':
#print(str(tx)+' is a Zerocoin spend to stealth')
for vinput in transaction['vin']:
if 'denomination' in vinput:
denoms.append(vinput['denomination'])
for output in transaction['vout']:
if 'scriptPubKey' in output:
if len(output['scriptPubKey']['addresses']) > 1:
logging.error(str(tx)+' has more than 1 output per vout')
outputs.append(output['scriptPubKey']['addresses'][0])
else:
logging.error(str(tx)+' is an unknown Zerocoin spend type')
else:
logging.error(str(tx)+' is a an unknown spend type')
#print(outputs)
return(denoms, outputs)
veild_path = '~/Downloads/veil-1.0.3.1/bin/veil-cli'
current_hash = ''
next_hash = ''
blockchain = []
transaction_list = []
outputs = []
zcspends = []
pp = pprint.PrettyPrinter(indent=4)
#print logging output to file
logging.basicConfig(level=logging.INFO,
filename='/home/max/logs/maxbot/parse_blocks.log',
format='%(asctime)s - %(levelname)s - %(message)s')
#print logging output to console
root = logging.getLogger()
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
logging.info('Start')
#Get first block
#response = get_block('a4063911700f37629bef105f66c088002bca439a2a2f009eadd9988aa9361a7f') # Block 100,000
response = get_block('2fbff4d1d89649c1949c90b894a9187cb64250a6c0b5cf3dc4c432c2d668a62c') # Block custom
#response = get_block('5ce8fa0eb598022b0c4f70969c28845df1261a9c3c1e984781985825656ffdbe') # Block custom
#response = get_block('76402912b3c88deb9493413d3195309a48c116ea37bfabe47deb306fff4eef84') # Block 318,224
#block = json.loads(response.text)
block = json.loads(response)
blockchain.append(block)
pp.pprint(block)
logging.info(block['height'])
print('block has this many transactions: '+str(len(block['tx'])))
for tx in block['tx']:
print(tx)
denoms = []
outputs = []
try:
response = get_tx(tx)
transaction = json.loads(response)
#pp.pprint(transaction)
denoms, outputs = parse_transaction(transaction)
if len(outputs) > 0:
print(str(block['height'])+'|'+str(tx)+'|'+str(denoms)+'|'+str(outputs))
zcspends.append(str(block['height'])+'|'+str(tx)+'|'+str(denoms)+'|'+str(outputs))
except Exception as e:
print(e)
#Get subsequent blocks
try:
while 'nextblockhash' in block:
#break
#while block['height'] > 318860:
denoms = []
outputs = []
response = get_block(block['nextblockhash'])
block = json.loads(response)
#logging.info(block['height'])
for tx in block['tx']:
#print(tx)
try:
response = get_tx(tx)
transaction = json.loads(response)
#pp.pprint(transaction)
denoms, outputs = parse_transaction(transaction)
if (len(denoms) > 0) or (len(outputs) > 0):
print(str(block['height'])+'|'+str(tx)+'|'+str(denoms)+'|'+str(outputs))
zcspends.append(str(block['height'])+'|'+str(tx)+'|'+str(denoms)+'|'+str(outputs))
except Exception as e:
print(e)
except Exception as e:
print(e)
logging.info('end')
##try:
## with open('zcspends.obj', "wb") as f:
## pickle.dump(zcspends, f)
##except Exception as e:
## print(e)
with open('zcspends.txt', 'w') as f:
for item in zcspends:
f.write("%s\n" % item)