Skip to content

Commit eb9a0b0

Browse files
committed
Update fee threshold snippet to avoid rust-only fn
1 parent 0ab6370 commit eb9a0b0

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

snippets/rust/src/communicating_fees.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ use log::info;
66

77
async fn get_fee_info_before_receiving_payment(sdk: Arc<BreezServices>) -> Result<()> {
88
// ANCHOR: get-fee-info-before-receiving-payment
9-
// Unless chosen otherwise by the app or the user, the SDK defaults to the cheapest fees
10-
let opening_fees = sdk
11-
.lsp_info()
12-
.await?
13-
.opening_fee_params_list
14-
.get_cheapest_opening_fee_params()?;
15-
16-
let fee_percentage = opening_fees.proportional * 100_f64 / 1_000_000_f64;
17-
let min_fee_sat = opening_fees.min_msat / 1_000;
18-
let inbound_liquidity_sat = sdk.node_info()?.inbound_liquidity_msats / 1000;
19-
20-
if inbound_liquidity_sat == 0 {
21-
info!("A setup fee of {fee_percentage}% with a minimum of {min_fee_sat} sats will be applied.");
22-
} else {
23-
info!("A setup fee of {fee_percentage}% with a minimum of {min_fee_sat} sats will be applied for receiving more than {inbound_liquidity_sat} sats.");
9+
let inbound_liquidity_msat = sdk.node_info()?.inbound_liquidity_msats;
10+
let inbound_liquidity_sat = inbound_liquidity_msat / 1000;
11+
12+
let opening_fee_response = sdk
13+
.open_channel_fee(OpenChannelFeeRequest {
14+
amount_msat: inbound_liquidity_msat + 1,
15+
expiry: None,
16+
})
17+
.await?;
18+
19+
if let Some(opening_fees) = opening_fee_response.used_fee_params {
20+
let fee_percentage = opening_fees.proportional * 100_f64 / 1_000_000_f64;
21+
let min_fee_sat = opening_fees.min_msat / 1_000;
22+
23+
if inbound_liquidity_sat == 0 {
24+
info!("A setup fee of {fee_percentage}% with a minimum of {min_fee_sat} sats will be applied.");
25+
} else {
26+
info!("A setup fee of {fee_percentage}% with a minimum of {min_fee_sat} sats will be applied for receiving more than {inbound_liquidity_sat} sats.");
27+
}
2428
}
2529
// ANCHOR_END: get-fee-info-before-receiving-payment
2630

0 commit comments

Comments
 (0)