-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.py
More file actions
executable file
·84 lines (58 loc) · 1.98 KB
/
input.py
File metadata and controls
executable file
·84 lines (58 loc) · 1.98 KB
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
#!/usr/bin/env python3
import urllib3
import certifi
import sys
import json
import os
def insert_address(string):
global addresses
if string not in addresses:
addresses.append(string)
#downloads a block
def get_block(blockhash):
#donwloads the block
URL = "https://blockchain.info/rawblock/"+blockhash
http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',ca_certs=certifi.where())
content = http.request('GET',URL)
assert content.status == 200
Decoder = json.JSONDecoder()
js_data = Decoder.decode(content.data.decode('utf-8'))
#roams through the transaction and collects the addresses
for transaction in js_data['tx']:
for senders in transaction['inputs']:
try:
insert_address(senders['prev_out']['addr'])
except:
pass
for receivers in transaction['out']:
try:
insert_address(receivers['addr'])
except:
pass
print('Collected '+str(len(addresses))+' addresses from Block: '+str(blockhash))
FILE = open('prev_block.txt','w')
FILE.write(js_data['prev_block'])
FILE.close()
def store(addresses):
content = str(len(addresses))+'\n'
content += '\n'.join(addresses)
FILE = open('new_block.csv','w')
content = FILE.write(content)
FILE.close()
if __name__ == '__main__':
addresses = []
if len(sys.argv)> 1:
get_block(sys.argv[1])
store(addresses)
else:
if os.path.isfile('prev_block.txt'):
FILE = open('prev_block.txt','r')
content = FILE.readlines()
FILE.close()
get_block(content[0])
store(addresses)
else:
print('requires Adress of requested Block')
print('either through terminal argument or prev_block.txt')
print('usage: '+str(sys.argv[0])+' *Adress*')
sys.exit(2)