forked from breadwallet/breadwallet-core
-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_checkpoint.py
executable file
·65 lines (44 loc) · 1.36 KB
/
get_checkpoint.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
#!/usr/bin/env python
"""
Given a block height, return the checkpoint hash information data that consist of:
- block hash
- timestamp
- bits
Usage (default network is mainnet):
get_checkpoint.py <height> [network]
Example:
get_checkpoint.py 624960
{ 624960, uint256("00000000000000000010a34de0c20440b6804f61549e1c1b18d0b80afb\
589d6e"), 1586336046, 0x171320bc }
"""
from sys import argv
import httpx
def main():
network = "mainnet"
if len(argv) <= 1:
print(__doc__)
exit(1)
if len(argv) > 2:
network = argv[2]
else:
network = "mainnet"
height: str = argv[1]
url: str = "https://blockstream.info"
if network == "mainnet":
url += f"/api/block-height/{height}"
else:
url += f"/{network}/api/block-height/{height}"
hash: str = httpx.get(url).read().decode("utf-8")
url = "https://blockstream.info"
if network == "mainnet":
url += f"/api/block/{hash}"
else:
url += f"/{network}/api/block/{hash}"
data: dict = httpx.get(url).json()
timestamp = data["timestamp"]
bits = data["bits"]
print(checkpoint_str(int(height), hash, timestamp, bits))
def checkpoint_str(height: int, hash: str, timestamp: int, bits: int) -> str:
return f'{{ {height}, uint256("{hash}"), {timestamp}, 0x{bits:2x} }}'
if __name__ == "__main__":
main()