Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2. Here's the script:
  3.  
  4. ```
  5. import requests
  6. import time
  7.  
  8.  
  9. def get_latest_block():
  10. response = requests.get("https://mempool.space/api/blocks/tip/hash")
  11. response.raise_for_status()
  12. return response.text
  13.  
  14.  
  15. def get_block_tx(block_hash):
  16. url = f"https://mempool.space/api/v1/block/{block_hash}/summary"
  17. response = requests.get(url)
  18. response.raise_for_status()
  19. return response.json()
  20.  
  21.  
  22. def get_block(block_hash):
  23. url = f"https://mempool.space/api/v1/block/{block_hash}"
  24. response = requests.get(url)
  25. response.raise_for_status()
  26. return [response.json().get("previousblockhash"), response.json().get("timestamp"), response.json().get("height")]
  27.  
  28.  
  29. def main(latest_block):
  30. latest_block = get_latest_block() if not latest_block else latest_block
  31. block_hash = latest_block
  32. max_delta = 0
  33. max_tx = None
  34.  
  35. while block_hash:
  36.  
  37. summary = get_block_tx(block_hash)
  38. prev_hash, block_time, height = get_block(block_hash)
  39. print(f"Checking block: {block_hash} - Height: {height}")
  40. for tx in summary:
  41. tx_time = tx.get("time")
  42. if tx_time:
  43. delta = block_time - tx_time
  44. if delta > max_delta:
  45. max_delta = delta
  46. max_tx = tx
  47. print(f"New greatest delta: {max_delta / 86400} days, TXID: {tx['txid']}")
  48.  
  49. block_hash = prev_hash
  50. time.sleep(1) # Be polite to the API
  51.  
  52. if max_tx:
  53. print(f"Largest time delta found: {max_delta / 86400} days")
  54. print(f"TXID: {max_tx['txid']}")
  55. else:
  56. print("No transactions found.")
  57.  
  58.  
  59. if __name__ == "__main__":
  60. main(None)
  61. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement