Cleanup: remove internal references and scaffolding

This commit is contained in:
Sulkta 2026-05-27 11:15:03 -07:00
parent b4a81e0ab8
commit 812393d030
10 changed files with 72 additions and 141 deletions

View file

@ -13,17 +13,12 @@ Koios endpoint used::
POST https://api.koios.rest/api/v1/address_utxos
Body: {"_addresses": ["addr1..."]}
Status transitions applied here::
Status transitions::
PENDING CONFIRMED (received >= expected * CONFIRM_TOLERANCE)
PENDING UNDERPAID (received > 0 but below tolerance)
PENDING OVERPAID (received >= expected * OVERPAY_THRESHOLD)
PENDING EXPIRED (after reprice_count exhausts see reprice_expired_invoices)
Behavioral shape is identical to the original the host app ``services/cardano_monitor.py``:
same polling intervals, same Koios URL, same 2% confirm / overpay tolerances.
The only change is that persistence is now delegated to the store Protocol
instead of being welded to SQLAlchemy + the ``CardanoPayment`` model.
"""
from __future__ import annotations
@ -41,10 +36,6 @@ from cardano_checkout.store import InvoiceStore
# returns the current-market lovelace equivalent as int. Invoked by
# :func:`reprice_expired_invoices` to generate fresh quotes when an
# invoice's quote window lapses without payment.
#
# SDK intentionally does NOT ship an oracle. Consumers wire whatever
# price source they trust (CoinGecko, Koios ticker, their own DEX feed,
# or a constant for tests).
PriceFn = Callable[[float], Awaitable[int]]
logger = logging.getLogger(__name__)
@ -52,11 +43,11 @@ logger = logging.getLogger(__name__)
KOIOS_URL = "https://api.koios.rest/api/v1/address_utxos"
KOIOS_TIMEOUT = 15 # seconds
# Tolerance for confirming payment (2%) — unchanged from v0.1 / the host app.
# Tolerance for confirming payment (2%).
CONFIRM_TOLERANCE = 0.98
OVERPAY_THRESHOLD = 1.02
# Default reprice cap + window (matches the host app defaults).
# Default reprice cap + window.
DEFAULT_MAX_REPRICINGS = 3
DEFAULT_PAYMENT_WINDOW_MINUTES = 15
@ -108,8 +99,7 @@ async def check_address_utxos(
return []
# Backwards-compatible alias — monitor.py in the host app imports the private name.
# Keeping a leading-underscore alias so the the host app shim can still reach it.
# Leading-underscore alias kept for callers that imported the private name.
_check_address_utxos = check_address_utxos
@ -133,7 +123,7 @@ async def evaluate_utxos(
- ``received_assets`` ``{policy_id.asset_name_hex: quantity}``.
- ``latest_tx_hash`` most recent observed tx hash, or None if no UTXOs.
Status rules mirror the host app exactly:
Status rules:
- No UTXOs ``PENDING`` (no change)
- ``total_value >= expected * OVERPAY_THRESHOLD`` ``OVERPAID`` (treated as confirmed)
@ -168,11 +158,10 @@ async def evaluate_utxos(
if qty > 0:
received_assets[asset_id] = received_assets.get(asset_id, 0) + qty
# ADA-only matching. Any native tokens landed in the same UTxOs are
# recorded in received_assets for visibility but do NOT contribute to
# the payment-matched total. Consumers who want to accept stablecoins
# or other native tokens wrap this function with their own asset-to-
# lovelace converter before comparing against expected_lovelace.
# ADA-only matching. Native tokens in the same UTxOs are recorded in
# received_assets for visibility but do NOT contribute to the
# payment-matched total. Wrap this function with your own
# asset-to-lovelace converter to accept native tokens.
total_value = raw_lovelace
if expected_lovelace == 0:
@ -190,7 +179,7 @@ async def evaluate_utxos(
return new_status, raw_lovelace, total_value, received_assets, latest_tx_hash
# Backwards-compatible alias.
# Leading-underscore alias for callers that imported the private name.
_evaluate_utxos = evaluate_utxos
@ -313,18 +302,17 @@ async def reprice_expired_invoices(
Args:
store: Persistence backend.
price_fn: Async callable that takes a USD amount and returns the
current lovelace equivalent. Consumer-supplied the SDK does
not ship an oracle. A simple wiring looks like::
current lovelace equivalent. Example::
from cardano_checkout.monitor import reprice_expired_invoices
async def my_price_fn(usd: float) -> int:
rate = await coingecko_fetch_ada_usd() # your code
rate = await coingecko_fetch_ada_usd()
return int(round(usd / rate * 1_000_000))
await reprice_expired_invoices(store, price_fn=my_price_fn)
window_minutes: New expiry window per reprice. the host app default 15.
max_repricings: Give-up threshold. the host app default 3.
window_minutes: New expiry window per reprice. Default 15.
max_repricings: Give-up threshold. Default 3.
limit: Max pending invoices to process per call.
Returns: