-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminersIdentification.py
141 lines (99 loc) · 2.74 KB
/
minersIdentification.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
# author: Eugenio CORTESI
from __future__ import absolute_import, division
import json
import sys
import os
import gc
def openAdds():
miners = []
i = 0
vistedReceivers = {}
for a in receivers:
if a not in vistedReceivers:
vistedReceivers[a] = None
#percentage = (i * 100)/len(receivers)
#print(percentage)
if a in allSenders:
hashes = {}
visited = {}
for thisHash in allSenders[a]:
hashes[thisHash] = None
while (len(hashes) > 0):
#print('collecting hashes - visited %s, to visit %s' %(len(visited), len(hashes)))
hash = hashes.keys()[0]
if hash not in visited:
for s in transactions[hash]:
if s not in vistedReceivers:
if s in allSenders:
vistedReceivers[s] = None
for h in allSenders[s]:
if h not in hashes and h not in visited:
hashes[h] = None
visited[hash] = None
del hashes[hash]
homonyms = []
for transactionHash in visited:
for thisAdss in transactions[transactionHash]:
if thisAdss not in homonyms:
homonyms.append(thisAdss)
if (len(homonyms)>0):
miners.append(homonyms)
del homonyms
#else:
#homonyms = []
#homonyms.append(a)
#miners.append(homonyms)
return miners
firstBlock = input('first')
lastBlock = input('last')
listofDirectories = []
a = os.listdir('./')
interval = []
receivers = {}
for i in range(firstBlock, lastBlock+1):
dir = 'res_blk%05d.dat' %i
interval.append(dir)
for i in a:
for j in range(len(interval)):
if interval[j] == i:
listofDirectories.append(i)
listofDirectories.sort()
file1 = os.getcwd() + '/rewardingTransactions.txt'
with open(file1) as json_file1:
RWTs = json.load(json_file1)
json_file1.close()
for rwt in RWTs:
adds = rwt['receiver'].split('_')
del adds[0]
for el in adds:
if el not in receivers:
receivers[el] = None
for directory in listofDirectories:
print('NEW_DIRECTORY %s' %directory)
allTransactions = []
allSenders = {}
transactions = {}
abs_file_path1 = os.getcwd() + '/' + directory + '/allTransa.txt'
with open(abs_file_path1) as json_file1:
allTransactions = json.load(json_file1)
json_file1.close()
for tr in allTransactions['transactions']:
senders = tr['Sender'].split("_")
del senders[0]
transactions[tr['txHash']] = []
for add in senders:
if add not in transactions[tr['txHash']]:
transactions[tr['txHash']].append(add)
if add not in allSenders:
allSenders[add] = []
if tr['txHash'] not in allSenders[add]:
allSenders[add].append(tr['txHash'])
del allTransactions
m = openAdds()
abs_file_path = os.getcwd() + '/' + directory + '/miners.txt'
with open(abs_file_path, 'w') as outfile:
json.dump(m, outfile)
del m
del allSenders
del transactions
gc.collect()