-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_create_endowments.py
74 lines (58 loc) · 2.56 KB
/
analyze_create_endowments.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
from analyze import MessageCall, TransactionReader, AnalysisState
import glob
def main():
reused_addrs_creators = set()
reused_ephemeral_addrs_creators = set()
with open("analysis-results/london-to-present/creators-of-redeployed-addrs.csv","r") as f:
for line in f:
break
for line in f:
parts = line.split(",")
if parts[0] in reused_addrs_creators:
raise Exception("shouldn't happen")
reused_addrs_creators.add(parts[0])
with open("analysis-results/london-to-present/ephemeral-creators-which-reuse-addrs.csv","r") as f:
for line in f:
break
for line in f:
if line.strip('\n') in reused_ephemeral_addrs_creators:
raise Exception("shouldn't happen")
reused_ephemeral_addrs_creators.add(line.strip('\n'))
creator_value_endowed = {}
input_files = sorted(glob.glob("data-traces/*.csv"))
t = TransactionReader()
done = False
start_block=12965000
end_block=99999999999999999
for input_file in input_files:
source_data_file = open(input_file, 'r')
for line in source_data_file:
break
print("analyzing {}".format(input_file))
while True:
tx_calls = t.ReadNextTransaction(source_data_file)
if len(tx_calls) == 0:
break
if tx_calls[0].block_number > end_block:
done = True
break
if tx_calls[0].block_number < start_block:
continue
for call in tx_calls:
if call.status == 0:
continue
if call.type == 'create':
if call.sender in reused_addrs_creators or call.sender in reused_ephemeral_addrs_creators:
if not call.sender in creator_value_endowed:
creator_value_endowed[call.sender] = int(call.value)
else:
creator_value_endowed[call.sender] += int(call.value)
if done:
break
nonzero_endowments = [(item[0], item[1] / 10e17) for item in creator_value_endowed.items() if item[1] != 0]
with open("analysis-results/london-to-present/creation-amounts-endowed.csv","w") as f:
f.write("account which created a contract at an address that had been previously used, total ether amount endowed in all creations by account\n")
for addr, amt in nonzero_endowments:
f.write("{}, {}\n".format(addr, amt))
if __name__ == "__main__":
main()