-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.py
64 lines (58 loc) · 2.5 KB
/
validator.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
from client import client
from config import END_BLOCK, SNAPSHOT_CSV
def load_snapshot():
accounts = {}
f = open(SNAPSHOT_CSV)
for line in f.readlines():
line = line.strip().replace('"', '').split(',')
accounts[line[0]] = float(line[2])
f.close()
return accounts
def validate_unreg():
accounts = load_snapshot()
f = open('onchain_snapshot_unregistered.csv', 'w')
all_actions = []
total_value_1 = total_value_2 = 0
total_accounts = 0
for i in range(0, END_BLOCK):
block = client.get_block(i+1)
txs = block['transactions']
print('%d fetching blocks, be patient' % (i+1))
if len(txs):
for tx in txs:
actions = tx['trx']['transaction']['actions']
all_actions.extend(actions)
if total_accounts > 0:
print('%d account(s) verified!' % total_accounts)
key = ''
for action in actions:
if action['name'] == 'add' and action['account'] == 'eosio.unregd':
data = action['data']
key = data['ethereum_address']
balance = float(data['balance'].replace(' EOS', ''))
assert accounts[key] == balance
line = ",".join([key, str(balance)]) + '\n';
total_value_1 += balance
f.write(line)
total_accounts += 1
elif action['name'] == 'transfer' and action['data']['to'] == 'eosio.unregd':
data = action['data']
balance = float(data['quantity'].replace('EOS', ''))
total_value_2 += balance
assert accounts[key] == balance
f.close()
assert sum(accounts.values()) == total_value_1
assert sum(accounts.values()) == total_value_1
assert len(accounts.keys()) == total_accounts
print("=======================================")
print("validation of total value SUCCESS!!!")
print("total value on chain", total_value_1)
print("total value in snapshot", sum(accounts.values()))
print("\n")
print("=======================================")
print("validation of total accounts SUCCESS!!!")
print("total accounts on chain", total_accounts)
print("total accounts in snapshot", len(accounts.keys()))
print("onchain_snapshot_unregistered.csv generated!")
if __name__ == "__main__":
validate_unreg()