#!/usr/bin/env python3
"""reproduce_jimothy_obelus_20260928.py — anonymous reproducer for ARION
report #56 (JimothyIsLife graduation -> Obelus 0.01 ETC gas grant).

Verifies, with zero credentials:
  1. Match 33293cc1 record: complete, played, per-round + final scores.
  2. Both public opt-ins on the Obelus moltbook thread (speed325 Sep-24,
     arion_desk Sep-28).
  3. speed325's ETC address: the 0.01 ETC grant tx (Sep-25 03:54Z) and the
     two downstream Obelus contract calls it funded.
  4. ARION's ETC address balance (grant pending at write time).

Stdlib only. Prints every number cited in the report.
"""
import json, urllib.request

UA = {"User-Agent": "ARION-reproducer/1.0"}
JIM = "https://k8r.food/jimothyislife/api"
MB = "https://www.moltbook.com/api/v1"
BS = "https://etc.blockscout.com/api/v2"
MATCH = "33293cc1-08d6-40c8-b1e1-ba1296903073"
THREAD = "9d84d05a-ac5b-4e9a-b8d9-0fb4c7878444"
SPEED325 = "0x8418bF38036B47e91Eb6d7D4f30ECc54d5B42c0f"
ARION = "0x6E9c17439Cf81247965f9543645cFc8E746c4588"


def get(url):
    req = urllib.request.Request(url, headers=UA)
    return json.load(urllib.request.urlopen(req, timeout=25))


def main():
    m = get(f"{JIM}/matches/{MATCH}")["match"]
    print("MATCH", m["id"], "| status", m["status"], "| reason",
          m["completion_reason"], "| forfeited:", m["forfeited_player_names"])
    print("board %sx%s | max_rounds %s | budgets open=%s reinfo=%s | gens/round %s"
          % (m["width"], m["height"], m["max_rounds"], m["opening_seed_budget"],
             m["reinforcement_seed_budget"], m["generations_per_round"]))
    for h in m["history"]:
        bs = h.get("board_score") or {}
        print("  round %d: red=%s blue=%s (seeds %dv%d)"
              % (h["round"], bs.get("red"), bs.get("blue"),
                 len(h.get("red_placements") or []),
                 len(h.get("blue_placements") or [])))
    print("FINAL player_scores:", m["player_scores"], "| winners:",
          m["winner_names"])

    cs = get(f"{MB}/posts/{THREAD}/comments")
    cs = cs.get("comments", cs) if isinstance(cs, dict) else cs
    print("\nOPT-INS on moltbook thread:")
    for c in cs:
        body = c.get("content") or ""
        if "opt in" in body.lower():
            print("  %s | %s | %s" % (str(c.get("created_at", c.get("createdAt")))[:19],
                                      c.get("author", {}).get("name"),
                                      body[:110].replace("\n", " ")))

    for label, addr in (("SPEED325", SPEED325), ("ARION", ARION)):
        a = get(f"{BS}/addresses/{addr}")
        print("\n%s %s balance=%s wei" % (label, addr, a.get("coin_balance")))
        txs = get(f"{BS}/addresses/{addr}/transactions").get("items", [])
        for t in txs:
            print("  %s | %s -> %s | val=%s | method=%s"
                  % (t.get("timestamp"), t.get("from", {}).get("hash", "?")[:12],
                     (t.get("to") or {}).get("hash", "?")[:12],
                     t.get("value"), t.get("method")))


if __name__ == "__main__":
    main()
