Skip to content

Commit

Permalink
chore: Expire the hodl invoice after 5 minutes
Browse files Browse the repository at this point in the history
That should be enough to pay the lightning invoice and reduces the risk of price movements.
  • Loading branch information
holzeis committed May 24, 2024
1 parent 7acd209 commit aa62dc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions coordinator/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ async fn create_invoice(

let invoice_params = invoice_params.value;
let invoice_amount = invoice_params.amt_sats;
let hash = invoice_params.r_hash.clone();
let r_hash = invoice_params.r_hash.clone();

let mut connection = state
.pool
Expand All @@ -635,15 +635,15 @@ async fn create_invoice(
.create_invoice(InvoiceParams {
value: invoice_amount,
memo: "Fund your 10101 position".to_string(),
expiry: 10 * 60, // 10 minutes
hash: hash.clone(),
expiry: 5 * 60, // 5 minutes
hash: r_hash.clone(),
})
.await
.map_err(|e| AppError::InternalServerError(format!("{e:#}")))?;

db::hodl_invoice::create_hodl_invoice(
&mut connection,
hash.as_str(),
r_hash.as_str(),
public_key,
invoice_amount,
)
Expand All @@ -660,7 +660,7 @@ async fn create_invoice(

tracing::info!(
trader_pubkey = public_key.to_string(),
hash,
r_hash,
amount_sats = invoice_amount,
"Started watching for hodl invoice"
);
Expand Down
5 changes: 3 additions & 2 deletions mobile/native/src/hodl_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct HodlInvoice {
pub payment_request: String,
pub pre_image: String,
pub r_hash: String,
pub amt_sats: Amount,
pub amount: Amount,
}

pub async fn get_hodl_invoice_from_coordinator(amount: Amount) -> Result<HodlInvoice> {
Expand Down Expand Up @@ -42,7 +42,8 @@ pub async fn get_hodl_invoice_from_coordinator(amount: Amount) -> Result<HodlInv
payment_request,
pre_image: pre_image.get_base64_encoded_pre_image(),
r_hash: pre_image.hash,
amt_sats: Default::default(),
amount,
};

Ok(hodl_invoice)
}

0 comments on commit aa62dc0

Please sign in to comment.