| |
| """Read-only: print D3 ledger control totals (debits/credits by currency + counts). |
| |
| Never mutates the database. Safe summaries only — no participant aliases, handles or notes. |
| |
| Example: |
| python scripts/d3_list_control_totals.py --db-path /tmp/amanpay-d2/amanpay.db --tenant event \ |
| --allow-unknown-fs --json |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import sys |
|
|
| from amanpay.finance.cli import add_common_args, build_runtime_for_cli, emit, resolve_tenant_id |
| from amanpay.finance.verification import journal_control_totals |
|
|
|
|
| def main(argv=None) -> int: |
| p = argparse.ArgumentParser(description="List D3 ledger control totals (read-only).") |
| add_common_args(p, tenant_required=False) |
| args = p.parse_args(argv) |
|
|
| rt = build_runtime_for_cli(args.db_path, allow_unknown_fs=args.allow_unknown_fs) |
| tid = resolve_tenant_id(rt, args.tenant) if args.tenant else None |
| totals = journal_control_totals(rt.store, tid) |
| emit({"all_balanced": totals["all_balanced"], "by_currency": totals["by_currency"], |
| "counts": totals["counts"], "last_journal_seq": totals["last_journal_seq"]}, |
| as_json=args.json) |
| rt.close() |
| return 0 if totals["all_balanced"] else 1 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|