Skip to content

Commit

Permalink
Merge pull request #4 from getAlby/bolt11-data
Browse files Browse the repository at this point in the history
Add string-serialized bolt11 invoice to PaymentDetails.
  • Loading branch information
rdmitr committed Mar 5, 2024
2 parents b18652c + cf26193 commit 5fffb52
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ dictionary PaymentDetails {
PaymentDirection direction;
PaymentStatus status;
LSPFeeLimits? lsp_fee_limits;
string? bolt11_invoice;
};

// [NonExhaustive]
Expand Down
1 change: 1 addition & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ where
direction: PaymentDirection::Inbound,
status: PaymentStatus::Succeeded,
lsp_fee_limits: None,
bolt11_invoice: None,
};

match self.payment_store.insert(payment) {
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Pending,
lsp_fee_limits: None,
bolt11_invoice: Some(invoice.to_string()),
};
self.payment_store.insert(payment)?;

Expand All @@ -1109,6 +1110,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Failed,
lsp_fee_limits: None,
bolt11_invoice: Some(invoice.to_string()),
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -1197,6 +1199,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Pending,
lsp_fee_limits: None,
bolt11_invoice: Some(invoice.to_string()),
};
self.payment_store.insert(payment)?;

Expand All @@ -1218,6 +1221,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Failed,
lsp_fee_limits: None,
bolt11_invoice: Some(invoice.to_string()),
};
self.payment_store.insert(payment)?;

Expand Down Expand Up @@ -1278,6 +1282,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
amount_msat: Some(amount_msat),
lsp_fee_limits: None,
bolt11_invoice: None,
};
self.payment_store.insert(payment)?;

Expand All @@ -1299,6 +1304,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Outbound,
amount_msat: Some(amount_msat),
lsp_fee_limits: None,
bolt11_invoice: None,
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -1473,6 +1479,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
lsp_fee_limits: None,
bolt11_invoice: Some(invoice.to_string()),
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -1600,6 +1607,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
lsp_fee_limits,
bolt11_invoice: Some(invoice.to_string()),
};

self.payment_store.insert(payment)?;
Expand Down
6 changes: 5 additions & 1 deletion src/payment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct PaymentDetails {
///
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
pub lsp_fee_limits: Option<LSPFeeLimits>,
/// The invoice that was paid.
pub bolt11_invoice: Option<String>,
}

impl_writeable_tlv_based!(PaymentDetails, {
Expand All @@ -48,7 +50,8 @@ impl_writeable_tlv_based!(PaymentDetails, {
(4, secret, required),
(6, amount_msat, required),
(8, direction, required),
(10, status, required)
(10, status, required),
(131072, bolt11_invoice, option),
});

/// Represents the direction of a payment.
Expand Down Expand Up @@ -284,6 +287,7 @@ mod tests {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
lsp_fee_limits: None,
bolt11_invoice: None,
};

assert_eq!(Ok(false), payment_store.insert(payment.clone()));
Expand Down

0 comments on commit 5fffb52

Please sign in to comment.