forked from holgern/beem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next_witness_block_coundown.py
54 lines (45 loc) · 1.87 KB
/
next_witness_block_coundown.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
#!/usr/bin/python
import sys
from beem import Steem
from beem.witness import Witness, WitnessesRankedByVote
from time import sleep
def convert_block_diff_to_time_string(block_diff_est):
next_block_s = int(block_diff_est) * 3
next_block_min = next_block_s / 60
next_block_h = next_block_min / 60
next_block_d = next_block_h / 24
time_diff_est = ""
if next_block_d > 1:
time_diff_est = "%.2f days" % next_block_d
elif next_block_h > 1:
time_diff_est = "%.2f hours" % next_block_h
elif next_block_min > 1:
time_diff_est = "%.2f minutes" % next_block_min
else:
time_diff_est = "%.2f seconds" % next_block_s
return time_diff_est
if __name__ == "__main__":
if len(sys.argv) != 2:
witness = "holger80"
else:
witness = sys.argv[1]
stm = Steem()
witness = Witness(witness, steem_instance=stm)
witness_schedule = stm.get_witness_schedule()
config = stm.get_config()
if "VIRTUAL_SCHEDULE_LAP_LENGTH2" in config:
lap_length = int(config["VIRTUAL_SCHEDULE_LAP_LENGTH2"])
else:
lap_length = int(config["STEEM_VIRTUAL_SCHEDULE_LAP_LENGTH2"])
witnesses = WitnessesRankedByVote(limit=250, steem_instance=stm)
vote_sum = witnesses.get_votes_sum()
virtual_time_to_block_num = int(witness_schedule["num_scheduled_witnesses"]) / (lap_length / (vote_sum + 1))
while True:
witness.refresh()
witness_schedule = stm.get_witness_schedule(use_stored_data=False)
witness_json = witness.json()
virtual_diff = int(witness_json["virtual_scheduled_time"]) - int(witness_schedule['current_virtual_time'])
block_diff_est = virtual_diff * virtual_time_to_block_num
time_diff_est = convert_block_diff_to_time_string(block_diff_est)
sys.stdout.write("\r Next block for %s in %s" % (witness["owner"], time_diff_est))
sleep(30)