-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchainstats.py
41 lines (33 loc) · 1.35 KB
/
chainstats.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
from database.ObjectHandler import ObjectHandler
from json_keys import *
# Just some stats for the chain / known blocks
ObjectHandler.load_objects()
chaintip = ObjectHandler.get_chaintip()
print(f"Chaintip: {chaintip}")
current_block = ObjectHandler.get_object(chaintip)
print(f"Current block: {current_block}")
chaintip_coinbase_txid = current_block[txids_key][0]
chaintip_coinbase = ObjectHandler.get_object(chaintip_coinbase_txid)
chaintip_height = chaintip_coinbase[height_key]
print(f"Chaintip: {chaintip}")
# get average block time
diff_sum = 0
while current_block[previd_key] is not None:
next_block = ObjectHandler.get_object(current_block[previd_key])
time_diff = current_block[created_key] - next_block[created_key]
diff_sum += time_diff
current_block = next_block
print(f"Difference sum: {diff_sum}")
print(f"Average block time: {diff_sum / chaintip_height} seconds")
current_block = ObjectHandler.get_object(chaintip)
# get average block time of latest 50 blocks
diff_sum = 0
for i in range(50):
next_block = ObjectHandler.get_object(current_block[previd_key])
time_diff = current_block[created_key] - next_block[created_key]
diff_sum += time_diff
current_block = next_block
if current_block[previd_key] is not None:
break
print(f"Difference sum: {diff_sum}")
print(f"Average block time: {diff_sum / 50} seconds")