Skip to content

Commit c4a64ad

Browse files
lnbc1QWFyb24yukibtc
authored andcommitted
nostr: fix NIP-47 list_transactions response deserialization when null expires_at
Closes #469 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 915b61c commit c4a64ad

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
### Fixed
4444

45-
* nostr: fix NIP-47 `list_transactions` response deserialization ([Yuki Kishimoto])
45+
* nostr: fix NIP-47 `list_transactions` response deserialization ([Yuki Kishimoto] and [lnbc1QWFyb24])
4646

4747
### Removed
4848

@@ -291,6 +291,7 @@ added `nostrdb` storage backend, added NIP32 and completed NIP51 support and mor
291291
[benthecarman]: https://github.com/benthecarman
292292
[Xiao Yu]: https://github.com/kasugamirai
293293
[RydalWater]: https://github.com/RydalWater
294+
[lnbc1QWFyb24]: https://github.com/lnbc1QWFyb24
294295

295296
<!-- Tags -->
296297
[Unreleased]: https://github.com/rust-nostr/nostr/compare/v0.32.0...HEAD

bindings/nostr-ffi/src/nips/nip47.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pub struct LookupInvoiceResponseResult {
653653
/// Creation timestamp in seconds since epoch
654654
pub created_at: Arc<Timestamp>,
655655
/// Expiration timestamp in seconds since epoch
656-
pub expires_at: Arc<Timestamp>,
656+
pub expires_at: Option<Arc<Timestamp>>,
657657
/// Settled timestamp in seconds since epoch
658658
pub settled_at: Option<Arc<Timestamp>>,
659659
/// Optional metadata about the payment
@@ -672,7 +672,7 @@ impl From<nip47::LookupInvoiceResponseResult> for LookupInvoiceResponseResult {
672672
amount: value.amount,
673673
fees_paid: value.fees_paid,
674674
created_at: Arc::new(value.created_at.into()),
675-
expires_at: Arc::new(value.expires_at.into()),
675+
expires_at: value.expires_at.map(|t| Arc::new(t.into())),
676676
settled_at: value.settled_at.map(|t| Arc::new(t.into())),
677677
metadata: value.metadata.and_then(|m| m.try_into().ok()),
678678
}
@@ -691,7 +691,7 @@ impl From<LookupInvoiceResponseResult> for nip47::LookupInvoiceResponseResult {
691691
amount: value.amount,
692692
fees_paid: value.fees_paid,
693693
created_at: **value.created_at,
694-
expires_at: **value.expires_at,
694+
expires_at: value.expires_at.map(|t| **t),
695695
settled_at: value.settled_at.map(|t| **t),
696696
metadata: value.metadata.and_then(|m| m.try_into().ok()),
697697
}

bindings/nostr-js/src/nips/nip47.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub struct JsLookupInvoiceResponseResult {
467467
/// Creation timestamp in seconds since epoch
468468
pub created_at: JsTimestamp,
469469
/// Expiration timestamp in seconds since epoch
470-
pub expires_at: JsTimestamp,
470+
pub expires_at: Option<JsTimestamp>,
471471
/// Settled timestamp in seconds since epoch
472472
pub settled_at: Option<JsTimestamp>,
473473
// /// Optional metadata about the payment
@@ -487,7 +487,7 @@ impl From<LookupInvoiceResponseResult> for JsLookupInvoiceResponseResult {
487487
amount: value.amount,
488488
fees_paid: value.fees_paid,
489489
created_at: value.created_at.into(),
490-
expires_at: value.expires_at.into(),
490+
expires_at: value.expires_at.map(|t| t.into()),
491491
settled_at: value.settled_at.map(|t| t.into()),
492492
// metadata: value.metadata.to_string(),
493493
}
@@ -506,7 +506,7 @@ impl From<JsLookupInvoiceResponseResult> for LookupInvoiceResponseResult {
506506
amount: value.amount,
507507
fees_paid: value.fees_paid,
508508
created_at: *value.created_at,
509-
expires_at: *value.expires_at,
509+
expires_at: value.expires_at.map(|t| *t),
510510
settled_at: value.settled_at.map(|t| *t),
511511
metadata: None,
512512
}

crates/nostr/src/nips/nip47.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ pub struct LookupInvoiceResponseResult {
586586
/// Creation timestamp in seconds since epoch
587587
pub created_at: Timestamp,
588588
/// Expiration timestamp in seconds since epoch
589-
pub expires_at: Timestamp,
589+
#[serde(skip_serializing_if = "Option::is_none")]
590+
pub expires_at: Option<Timestamp>,
590591
/// Settled timestamp in seconds since epoch
591592
#[serde(skip_serializing_if = "Option::is_none")]
592593
pub settled_at: Option<Timestamp>,
@@ -1101,7 +1102,7 @@ mod tests {
11011102
amount: 123,
11021103
fees_paid: 1,
11031104
created_at: Timestamp::from(123456),
1104-
expires_at: Timestamp::from(1234567),
1105+
expires_at: Some(Timestamp::from(1234567)),
11051106
description_hash: None,
11061107
payment_hash: String::new(),
11071108
metadata: None,

0 commit comments

Comments
 (0)