Skip to content

Commit

Permalink
Don't mock channel opening on lnurlw initiation
Browse files Browse the repository at this point in the history
  • Loading branch information
gcomte committed Dec 23, 2024
1 parent 827a701 commit 1fd8edf
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions mock/breez-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ impl BreezServices {
&self,
req: LnUrlWithdrawRequest,
) -> Result<LnUrlWithdrawResult, LnUrlWithdrawError> {
let lsp_fee_msat = receive_payment_mock_channels(req.amount_msat)
.await
.map_err(|e| LnUrlWithdrawError::InvalidAmount { err: e.to_string() })?;
let lsp_fee_msat = calculate_lsp_opening_fee(req.amount_msat).await;

let (invoice, preimage, payment_hash) =
self.create_invoice(req.amount_msat, &req.description.unwrap_or_default());
Expand Down Expand Up @@ -1454,11 +1452,8 @@ async fn receive_payment_mock_channels(amount_msat: u64) -> Result<u64> {
}
Ok(0)
} else {
let lsp_fee = calculate_lsp_opening_fee(amount_msat).await;
let mut channels = CHANNELS.lock().unwrap();
let lsp_fee = max(
OPENING_FEE_PARAMS_MIN_MSAT,
amount_msat * OPENING_FEE_PARAMS_PROPORTIONAL as u64 / 10_000,
);
if amount_msat < lsp_fee {
return Err(anyhow!(
"Invalid amount_msat ({amount_msat}) - not enough to cover channel opening fees ({lsp_fee})"
Expand All @@ -1472,6 +1467,19 @@ async fn receive_payment_mock_channels(amount_msat: u64) -> Result<u64> {
}
}

async fn calculate_lsp_opening_fee(amount_msat: u64) -> u64 {
if amount_msat <= get_inbound_liquidity_msat() {
0
} else {
let lsp_fee = max(
OPENING_FEE_PARAMS_MIN_MSAT,
amount_msat * OPENING_FEE_PARAMS_PROPORTIONAL as u64 / 10_000,
);

lsp_fee
}
}

async fn send_payment_mock_channels(amount_with_fees_msat: u64) {
if amount_with_fees_msat > get_balance_msat() {
panic!("Not enough balance");
Expand Down

0 comments on commit 1fd8edf

Please sign in to comment.