prometheus/service
Local Dev 34efb319cc prometheus: BCH payments — invoices, price oracle, admin reconcile
Payment flow for the paid wave (the free wave is still the default):

  1. Publisher POSTs /api/listing. If PAYMENT_REQUIRED=1 is set, the
     listing lands with payment_status='pending' and is hidden from
     browse. If not set, the listing goes straight to 'free' and is
     visible immediately (today's behaviour, unchanged).
  2. Anyone (publisher, their script, their wallet) POSTs
     /api/invoice {listing_id} and gets back a one-shot invoice:
     operator receive address, exact sat amount (USD-pegged + random
     1..256 sat jitter so no two in-flight invoices collide),
     bitcoincash: URI for a wallet, 20-min expiry.
  3. Reader pays. The amount matches exactly one pending invoice, and
     when the mempool watcher reports (address, amount, txid) to
     tryMatchPayment, both the invoice and the listing flip to paid.
     Browse starts showing the listing.

The mempool watcher that would do (3) automatically is deliberately NOT
in this commit — it needs an electrum-cash subscription or a block
explorer webhook, and that's a next milestone. In the meantime, admins
reconcile by hand from /admin/payments, which shows every invoice with
a Mark paid form (optional txid field). Same effect on the DB, same
audit log entry, different `paid_by` string.

Design decisions worth recording:
- One receive address + amount matching, NOT an HD wallet per invoice.
  BitPay used this for years; it is simple, auditable, and doesn't
  require a seed on the server to spend from later.
- Random few-sat jitter per invoice guarantees uniqueness of the
  (address, amount) pair across all in-flight invoices.
- Price oracle is CoinGecko (public, no key, 60s cache, 15-min stale
  fallback). If both the fresh fetch and the stale fallback fail,
  /api/invoice refuses — issuing invoices on a stale price is worse
  than refusing to quote until the oracle recovers.
- Quote is locked at issue time; the 20-min deadline is the lock.
- Lazy expiry: GET /api/invoice/<id> flips an expired pending invoice
  to 'expired' as a side effect, so there's no sweeper to run.

Admin UI /admin/payments shows every invoice (pending/paid/expired),
plus a dashboard-ish header with the configured mode + receive address.
The gating config appears in the UI even when payments are disabled, so
an operator spinning up a new instance can see at a glance what's set.

Config:
  PAYMENT_REQUIRED=1              — turn paid mode on
  PROMETHEUS_PAYMENT_ADDRESS=…    — the operator's receive address
  PROMETHEUS_LISTING_FEE_USD=1    — the fee (default 1 USD)
  PROMETHEUS_PRICE_SOURCE=…       — override the CoinGecko URL

End-to-end verified:
  PAYMENT_REQUIRED=1 → new listing hidden from browse → /api/invoice
  returns correct sats at live BCH price → admin login + mark-paid →
  listing becomes visible → /api/invoice/<id> returns status 'paid'
  with paid_by='manual:admin.x'.
2026-10-08 21:52:01 +02:00
..
lib prometheus: signed listings — BIP-137 publisher sign, SQLite index 2026-10-08 01:48:12 +02:00
admin-pages.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
admin-session.js prometheus: admin panel — login, listings, 3-mode toggle, audit log 2026-10-08 21:35:48 +02:00
admin.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
audit.js prometheus: admin panel — login, listings, 3-mode toggle, audit log 2026-10-08 21:35:48 +02:00
bns.js prometheus: signed listings — BIP-137 publisher sign, SQLite index 2026-10-08 01:48:12 +02:00
clamd.js prometheus: VirusTotal enrichment, gated on VIRUSTOTAL_API_KEY 2026-10-08 21:44:34 +02:00
db.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
invoice-api.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
layout.js prometheus: SEO polish and the apps.silentmode.st mirror vhost 2026-10-08 21:45:59 +02:00
listings.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
modes.js prometheus: admin panel — login, listings, 3-mode toggle, audit log 2026-10-08 21:35:48 +02:00
pages-browse.js prometheus: SEO polish and the apps.silentmode.st mirror vhost 2026-10-08 21:45:59 +02:00
pages.js prometheus: browse pages — categories and per-listing detail 2026-10-08 01:56:52 +02:00
payments.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
price.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
seo.js prometheus: weekly s3 snapshot of the browse surface to bns/prometheus 2026-10-08 21:42:54 +02:00
server.js prometheus: BCH payments — invoices, price oracle, admin reconcile 2026-10-08 21:52:01 +02:00
signing.js prometheus: upload + ClamAV scan + signed scan reports 2026-10-05 22:41:55 +02:00
uploads.js prometheus: VirusTotal enrichment, gated on VIRUSTOTAL_API_KEY 2026-10-08 21:44:34 +02:00
virustotal.js prometheus: VirusTotal enrichment, gated on VIRUSTOTAL_API_KEY 2026-10-08 21:44:34 +02:00