Debian Codegraph @

contrib/generate-restore-heights/heights.py

raw
1 import requests
2 import argparse
3
4 parser = argparse.ArgumentParser(description='Generate restore height list.')
5 parser.add_argument('-P', '--port',
6 default='18081',
7 dest='port',
8 help='Daemon port',
9 type=int)
10
11 args = parser.parse_args()
12
13 DAEMON_ADDRESS = f"http://127.0.0.1:{args.port}"
14
15 def get_block_timestamp(height: int):
16 data = {
17 "jsonrpc": "2.0",
18 "id": "0",
19 "method": "get_block_header_by_height",
20 "params": {
21 "height": height
22 }
23 }
24 res = requests.get(DAEMON_ADDRESS+"/json_rpc", json=data)
25 return res.json()['result']['block_header']['timestamp']
26
27
28 def get_height():
29 data = {
30 "jsonrpc": "2.0",
31 "id": "0",
32 "method": "get_block_count"
33 }
34 res = requests.get(DAEMON_ADDRESS+"/json_rpc", json=data)
35 return res.json()['result']['count']
36
37
38 timestamps = {}
39 current_height = get_height()
40
41 timestamps[1] = get_block_timestamp(1)
42 for height in range(1500, current_height, 1500):
43 timestamps[height] = get_block_timestamp(height)
44
45 for val in timestamps:
46 print(f"{timestamps[val]}:{val}")