fix: accept null optional params in make_invoice and list_transactions
Some checks failed
Tests / test (push) Has been cancelled

Clients may send optional params as an explicit JSON null rather than
omitting them; Amethyst does for description, description_hash and
expiry. dict.get only applies its default for a missing key, so
description arrived as None and make_invoice failed with
"'NoneType' object has no attribute 'encode'".

Coerce with `or` instead, pass no unhashed_description when the
description is blank, and apply the same to list_transactions' paging
params, which had the same exposure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Tbyw6FwjhEJg3gHfPHxWt
This commit is contained in:
Patrick Mulligan 2026-09-14 22:22:07 +02:00
commit bf55b46f76
2 changed files with 86 additions and 10 deletions

View file

@ -264,9 +264,11 @@ async def _on_make_invoice(
# Ensures amount is provided
if not amount_msats:
raise Exception("Missing amount")
description = params.get("description", "")
description_hash = params.get("description_hash", None)
expiry = params.get("expiry", None)
# Optional params may arrive as explicit JSON null, which dict.get does
# not default, so coerce here rather than trusting the fallback.
description = params.get("description") or ""
description_hash = params.get("description_hash") or None
expiry = params.get("expiry") or None
# hardening #
assert_valid_msats(amount_msats)
@ -284,7 +286,7 @@ async def _on_make_invoice(
currency="sat",
memo=description,
description_hash=bytes.fromhex(description_hash) if description_hash else None,
unhashed_description=description.encode("utf-8"),
unhashed_description=description.encode("utf-8") if description else None,
expiry=expiry,
)
payment_hash = payment.payment_hash
@ -394,12 +396,12 @@ async def _on_list_transactions(
if not nwc:
raise Exception("Pubkey has no associated wallet")
params = payload.get("params", 0)
tfrom = params.get("from", 0)
tuntil = params.get("until", int(time.time()))
limit = params.get("limit", 10)
offset = params.get("offset", 0)
unpaid = params.get("unpaid", False)
tx_type = params.get("type", "")
tfrom = params.get("from") or 0
tuntil = params.get("until") or int(time.time())
limit = params.get("limit") or 10
offset = params.get("offset") or 0
unpaid = params.get("unpaid") or False
tx_type = params.get("type") or ""
# hardening #
assert_valid_positive_int(tfrom)