Skip to content

Commit

Permalink
fix: set invoice expiry on invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Sep 4, 2023
1 parent cf406fe commit b9b26f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
7 changes: 5 additions & 2 deletions crates/ln-dlc-node/src/node/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ where
pub fn create_interceptable_invoice(
&self,
amount_in_sats: Option<u64>,
invoice_expiry: u32,
invoice_expiry: Option<Duration>,
description: String,
final_route_hint_hop: RouteHintHop,
) -> Result<Invoice> {
let invoice_expiry = invoice_expiry
.unwrap_or_else(|| Duration::from_secs(lightning_invoice::DEFAULT_EXPIRY_TIME));
let amount_msat = amount_in_sats.map(|x| x * 1000);
let (payment_hash, payment_secret) = self
.channel_manager
.create_inbound_payment(amount_msat, invoice_expiry, None)
.create_inbound_payment(amount_msat, invoice_expiry.as_secs() as u32, None)
.map_err(|_| anyhow!("Failed to create inbound payment"))?;
let invoice_builder = InvoiceBuilder::new(self.get_currency())
.payee_pub_key(self.info.pubkey)
.description(description)
.expiry_time(invoice_expiry)
.payment_hash(sha256::Hash::from_slice(&payment_hash.0)?)
.payment_secret(payment_secret)
.timestamp(SystemTime::now())
Expand Down
7 changes: 3 additions & 4 deletions crates/ln-dlc-node/src/tests/just_in_time_channel/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn fail_to_open_jit_channel_with_fee_rate_over_max() {
let invoice = payee
.create_interceptable_invoice(
Some(payer_to_payee_invoice_amount),
0,
None,
"interceptable-invoice".to_string(),
final_route_hint_hop,
)
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn open_jit_channel_with_disconnected_payee() {
let invoice = payee
.create_interceptable_invoice(
Some(payer_to_payee_invoice_amount),
0,
None,
"interceptable-invoice".to_string(),
final_route_hint_hop,
)
Expand Down Expand Up @@ -238,10 +238,9 @@ pub(crate) async fn send_interceptable_payment(
let interceptable_route_hint_hop =
coordinator.prepare_interceptable_payment(payee.info.pubkey)?;

let invoice_expiry = 0; // an expiry of 0 means the invoice never expires
let invoice = payee.create_interceptable_invoice(
Some(invoice_amount_sat),
invoice_expiry,
None,
"interceptable-invoice".to_string(),
interceptable_route_hint_hop,
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn fail_intercepted_htlc_if_coordinator_cannot_reconnect_to_payee() {
let invoice = payee
.create_interceptable_invoice(
Some(invoice_amount),
0,
None,
"interceptable-invoice".to_string(),
interceptable_route_hint_hop,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ async fn fail_intercepted_htlc_if_connection_lost_after_funding_tx_generated() {
let invoice = payee
.create_interceptable_invoice(
Some(invoice_amount),
0,
None,
"interceptable-invoice".to_string(),
interceptable_route_hint_hop,
)
Expand Down Expand Up @@ -169,7 +169,7 @@ async fn fail_intercepted_htlc_if_coordinator_cannot_pay_to_open_jit_channel() {
let invoice = payee
.create_interceptable_invoice(
Some(invoice_amount),
0,
None,
"interceptable-invoice".to_string(),
interceptable_route_hint_hop,
)
Expand Down
2 changes: 1 addition & 1 deletion mobile/native/src/ln_dlc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ pub fn create_invoice(amount_sats: Option<u64>) -> Result<Invoice> {

node.inner.create_interceptable_invoice(
amount_sats,
0,
None,
"Fund your 10101 wallet".to_string(),
final_route_hint_hop,
)
Expand Down

0 comments on commit b9b26f9

Please sign in to comment.