#!/usr/bin/env python3 """Drive the local regtest node (ADR-58, roadmap B3): `status`, `mine [N]`, `fund ADDRESS PLM`. The node is started separately (`docker compose up -d` in plm-regtest); see plm_engine/regtest.py for where it is looked for. It refuses to act on any chain that is not regtest. """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from plm_engine.regtest import RegtestError, RegtestNode, electrum_address, electrum_reachable # noqa: E402 def main(argv: list[str]) -> int: command, args = (argv[1] if len(argv) > 1 else "status"), argv[2:] try: node = RegtestNode.from_environment() if command == "status": info = node.info() host, port = electrum_address() print(f"chain {info['chain']}, height {info['blocks']}, wallet balance {node.balance()} PLM") print(f"electrum {host}:{port}: {'reachable' if electrum_reachable() else 'NOT reachable'}") elif command == "mine": hashes = node.mine(int(args[0]) if args else 1) print(f"mined {len(hashes)} block(s), height now {node.height()}") elif command == "fund" and len(args) == 2: print(f"sent {args[1]} PLM, txid {node.fund(args[0], float(args[1]))}") else: print(__doc__) return 2 except RegtestError as error: print(f"error: {error}", file=sys.stderr) return 1 return 0 if __name__ == "__main__": sys.exit(main(sys.argv))