nostr: tolerate missing and null amounts in NIP-47 responses - #1450
Merged
yukibtc merged 1 commit intoAug 18, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
LookupInvoiceResponse declares `amount` and `fees_paid` as required with no serde default, so a response that omits `amount` or sends `fees_paid: null` fails to deserialize and the whole object is lost — including `state`, which is what callers poll a payment for. Alby does both while a payment is in flight, which makes a working wallet look like one that answers nothing. This is the same class of problem as the empty-string handling added earlier for the optional string fields; the numeric fields never got equivalent treatment. Relaxed on inbound types only — LookupInvoiceResponse, MakeHoldInvoiceResponse, PaymentNotification and HoldInvoiceAcceptedNotification. The request types keep `amount` required on purpose: those describe what the caller sends, where a defaulted amount would silently mean zero. `created_at` is left alone: it would need Option or a sentinel, which is a separate decision. Closes nostrdevkit#1449 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc
force-pushed
the
nip47-tolerate-missing-numeric-fields
branch
from
August 18, 2026 05:32
13f1744 to
efe044f
Compare
yukibtc
approved these changes
Aug 18, 2026
Member
I've updated the changelog at efe044f |
Member
|
@grunch, this has been included in nostr v0.45.3 |
Contributor
Author
|
awesome thanks @yukibtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1449.
LookupInvoiceResponsedeclaresamountandfees_paidas required with no serdedefault, so a response that omits
amountor sendsfees_paid: nullfails todeserialize and the whole object is lost — including
state, which is what callerspoll a payment for. Alby does both while a payment is in flight, so
nwc'slookup_invoicereturnsErrand a perfectly healthy wallet looks like one thatanswers nothing. It breaks hold-invoice flows in particular, where polling
lookup_invoiceuntil settlement is the only way to observe the invoice resolving.Same class of problem as the empty-string handling already present on the optional
string fields of these structs; the numeric fields never got equivalent treatment.
What changed
A
deserialize_null_as_defaulthelper, alongside the existingdeserialize_empty_string_as_none, applied to theamount/fees_paidfields ofinbound types only:
LookupInvoiceResponseMakeHoldInvoiceResponsePaymentNotificationHoldInvoiceAcceptedNotificationThe request types deliberately keep
amountrequired — those describe what thecaller sends, where a defaulted amount would silently mean "zero-amount".
created_atis left as-is: relaxing it needsOption<Timestamp>or a sentinel,which felt like a separate decision for you to make. Happy to include it either way.
Serialization is unchanged, so round-trips keep emitting both fields.
Testing
Added
test_lookup_invoice_response_tolerates_missing_and_null_amounts, which usesthe exact response shape observed from Alby.
cargo test -p nostr --lib --features nip47 nip47passes (15 tests), and clippy is clean on the crate.Note: I could not complete a full
just precommit— it exhausted the disk on mymachine while building the whole workspace, unrelated to this change. Targeted tests
and clippy on
nostrare green.Found while debugging a Mostro protocol test harness, where this presented for days
as "the wallet is dead server-side".