Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here's the script:
- ```
- import requests
- import time
- def get_latest_block():
- response = requests.get("https://mempool.space/api/blocks/tip/hash")
- response.raise_for_status()
- return response.text
- def get_block_tx(block_hash):
- url = f"https://mempool.space/api/v1/block/{block_hash}/summary"
- response = requests.get(url)
- response.raise_for_status()
- return response.json()
- def get_block(block_hash):
- url = f"https://mempool.space/api/v1/block/{block_hash}"
- response = requests.get(url)
- response.raise_for_status()
- return [response.json().get("previousblockhash"), response.json().get("timestamp"), response.json().get("height")]
- def main(latest_block):
- latest_block = get_latest_block() if not latest_block else latest_block
- block_hash = latest_block
- max_delta = 0
- max_tx = None
- while block_hash:
- summary = get_block_tx(block_hash)
- prev_hash, block_time, height = get_block(block_hash)
- print(f"Checking block: {block_hash} - Height: {height}")
- for tx in summary:
- tx_time = tx.get("time")
- if tx_time:
- delta = block_time - tx_time
- if delta > max_delta:
- max_delta = delta
- max_tx = tx
- print(f"New greatest delta: {max_delta / 86400} days, TXID: {tx['txid']}")
- block_hash = prev_hash
- time.sleep(1) # Be polite to the API
- if max_tx:
- print(f"Largest time delta found: {max_delta / 86400} days")
- print(f"TXID: {max_tx['txid']}")
- else:
- print("No transactions found.")
- if __name__ == "__main__":
- main(None)
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement