Created
December 31, 2023 20:52
-
-
Save LarryRuane/8347b5fc44c846f1de1a7955202ebdcc to your computer and use it in GitHub Desktop.
print heights of blocks with out-of-order timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# When two cosecutive blocks have out of order timestamps (the higher height's time | |
# is less than the lower height's time), print the height of the lower-height block. | |
# | |
# prerequisite; | |
# $ pip3 install python-bitcoinrpc | |
# or see https://github.com/jgarzik/python-bitcoinrpc | |
from bitcoinrpc.authproxy import AuthServiceProxy | |
api = AuthServiceProxy("http://lmr:[email protected]:8332") | |
info = api.getblockchaininfo() | |
tip_height = info['blocks'] | |
prev_time = 0 | |
for height in range(tip_height, 0, -1): | |
blockhash = api.getblockhash(height) | |
b = api.getblock(blockhash, 1) | |
block_time = b['time'] | |
if prev_time > 0 and block_time > prev_time: | |
print(b['height']) | |
prev_time = block_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment