"""Read evidence.json and print the two UTC and local times. Python 3.9+ and IANA time zone data.""" from datetime import datetime, timezone from hashlib import sha256 import json from pathlib import Path from zoneinfo import ZoneInfo def replay(record): screen = record["screen"] rows = screen["scanned_headers"] assert [r["height"] for r in rows] == list(range(screen["first_height"], screen["last_height"] + 1)) start = int(datetime.fromisoformat(screen["utc_start"].replace("Z", "+00:00")).timestamp()) end = int(datetime.fromisoformat(screen["utc_end_exclusive"].replace("Z", "+00:00")).timestamp()) mid = start + 3600 first = [r for r in rows if start <= r["timestamp"] < mid and r["non_coinbase_available"]] second = [r for r in rows if mid <= r["timestamp"] < end and r["non_coinbase_available"]] pairs = [(a, b) for a in first for b in second if a["timestamp"] // 60 % 60 == b["timestamp"] // 60 % 60] assert len(pairs) == screen["matching_pairs"] chosen = min(pairs, key=lambda p: (abs(p[1]["timestamp"] - p[0]["timestamp"] - 3600), p[0]["height"], p[1]["height"])) result = [] for header, tx in zip(chosen, record["transactions"]): raw = bytes.fromhex(tx["header_hex"]) stamp = int.from_bytes(raw[68:72], "little") assert len(raw) == 80 and stamp == tx["unix_seconds"] == header["timestamp"] assert tx["block_height"] == header["height"] assert sha256(sha256(raw).digest()).digest()[::-1].hex() == tx["block_hash"] utc = datetime.fromtimestamp(stamp, timezone.utc) row = {"txid": tx["txid"], "block_height": tx["block_height"], "utc": utc.isoformat().replace("+00:00","Z")} for label, city in [("new_york", "America/New_York"), ("warsaw", "Europe/Warsaw"), ("los_angeles", "America/Los_Angeles")]: row[label] = utc.astimezone(ZoneInfo(city)).isoformat() assert row["utc"] == tx["block_time_utc"] and row["new_york"] == tx["new_york"] and row["warsaw"] == tx["warsaw"] result.append(row) assert len(result) == 2 and result[0]["txid"] != result[1]["txid"] return {"transactions": result, "header_gap_seconds": chosen[1]["timestamp"] - chosen[0]["timestamp"], "matching_pairs":len(pairs), "headers_in_first_hour":len(first),"headers_in_second_hour":len(second)} if __name__ == "__main__": archive = Path(__file__).resolve().with_name("evidence.json") print(json.dumps(replay(json.loads(archive.read_text(encoding="utf-8"))), indent=2))