-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_wallets.py
More file actions
166 lines (135 loc) · 4.16 KB
/
Copy pathmatch_wallets.py
File metadata and controls
166 lines (135 loc) · 4.16 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
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
163
164
165
166
import os
from datetime import datetime, timedelta
import json
import re
import csv
class JSONMatch(object):
def __init__(self, f, t):
self.fr = f
self.matches = []
self.matches.append(t)
def unique(self):
return len(self.matches) == 1
class Match(object):
def __init__(self, tr_from, tr_to):
self.tr_from = tr_from
self.tr_to = tr_to
class Transaction(object):
def __init__(self, date, address, amount, trans):
super(Transaction, self).__init__()
self.date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
self.address = address
self.amount = float(amount)
self.trans = re.findall('[0-9a-f]{64}',trans)[0]
def __eq__(self, other):
return self.date == other.date and self.address == other.address and self.amount == other.amount and self.trans == other.trans
def __hash__(self):
return hash(('date', self.date, 'address', self.address, 'amount', self.amount, 'trans', self.trans))
inputs = []
print('opening inputs')
with open('sorted_input.csv', 'r') as inputfile:
reader = csv.DictReader(inputfile)
for line in reader:
if line['received_amount']:
inputs.append(Transaction(line['date'], line['address'], line['received_amount'], line['txid']))
#file_contents = inputfile.read().splitlines(True)
#content = file_contents[1:]
#for line in content:
# line_content = line.split(',')
# if line_content[2]:
# inputs.append(Transaction(line_content[0], line_content[2], line_content[1], line_content[3]))
outputs = []
print('opening outputs')
with open('sorted_output.csv', 'r') as outputfile:
reader = csv.DictReader(outputfile)
for line in reader:
if line['sent_amount']:
outputs.append(Transaction(line['date'], line['address'], line['sent_amount'], line['txid']))
# file_contents = outputfile.read().splitlines(True)
# content = file_contents[1:]
# for line in content:
# line_content = line.split(',')
# if line_content[2]:
# outputs.append(Transaction(line_content[0], line_content[1], line_content[2], line_content[3]))
print('running matches')
i = 0
count = 0
matches = []
max_matches = 0
for wallet in inputs:
walls = []
for out_wallet in outputs:
if out_wallet.date >= wallet.date:
if out_wallet.date <= wallet.date+timedelta(hours=7):
if out_wallet.amount/wallet.amount > 0.975 and out_wallet.amount/wallet.amount < 0.977:
walls.append(out_wallet)
else:
outputs.remove(out_wallet)
else:
break
if len(walls) == 0:
print("-------------------")
else:
for w in walls:
matches.append(Match(wallet, w))
if len(walls) > max_matches:
max_matches = len(walls)
count = count + 1
i = i + 1
print(i/len(inputs))
i = 0
json_matches = {}
unique = 0
for m in matches:
try:
a = json_matches[m.tr_from]
a.matches.append(m.tr_to)
unique = unique - 1
except Exception as e:
json_matches[m.tr_from] = JSONMatch(m.tr_from, m.tr_to)
unique = unique + 1
i = i + 1
print(i/len(matches))
json_matches = list(json_matches.values())
print('Cleaning unique repeats')
unique_tr = []
for jsonM in json_matches:
if jsonM.unique():
unique_tr.append(jsonM.matches[0])
while True:
i = 0
for jsonM in json_matches:
if not jsonM.unique():
jsonM.matches = [x for x in jsonM.matches if x not in unique_tr]
i = i + 1
print(str(i/len(json_matches)))
unique_temp = []
i = 0
for jsonM in json_matches:
if jsonM.unique():
unique_temp.append(jsonM.matches[0])
i = i + 1
print(str(i/len(json_matches)))
if set(unique_temp) == set(unique_tr):
break
else:
print(str(len(unique_tr))+" "+str(len(unique_temp)))
unique_tr = unique_temp
d = {"result":json_matches}
#dump = json.dumps(d)
#print(dump)
def handler(o):
if isinstance(o, datetime):
return o.isoformat()
else:
return o.__dict__
#with open("json_matches.json", "w") as file:
# file.write(json.dumps(d, indent=2, default=handler))
with open('matches.csv', 'w') as file:
file.write('"Time UTC","Helix address","Amount received","Destination address","Amount sent out"\n')
for jsonM in json_matches:
if jsonM.unique():
file.write(str(jsonM.fr.date.strftime('%Y-%m-%d %H:%M:%S'))+','+str(jsonM.fr.address)+','+str(jsonM.fr.amount)+','+str(jsonM.matches[0].address)+','+str(jsonM.matches[0].amount)+'\n')
print(unique)
print(max_matches)
print(count)