Computes the opening fee in millisatoshis as described in LSPS2. Returns None if an arithmetic overflow occurs during calculation. # Arguments `payment_size_msat` - The size of the payment for which the channel is being opened. `opening_fee_min_fee_msat` - The minimum fee to be paid by the client to the LSP `opening_fee_proportional` - The proportional fee charged by the LSP
(
payment_size_msat: u64,
opening_fee_min_fee_msat: u64,
opening_fee_proportional: u64,
)
| 354 | /// the LSP |
| 355 | /// * `opening_fee_proportional` - The proportional fee charged by the LSP |
| 356 | pub fn compute_opening_fee( |
| 357 | payment_size_msat: u64, |
| 358 | opening_fee_min_fee_msat: u64, |
| 359 | opening_fee_proportional: u64, |
| 360 | ) -> Option<u64> { |
| 361 | payment_size_msat |
| 362 | .checked_mul(opening_fee_proportional) |
| 363 | .and_then(|f| f.checked_add(999999)) |
| 364 | .and_then(|f| f.checked_div(1000000)) |
| 365 | .map(|f| std::cmp::max(f, opening_fee_min_fee_msat)) |
| 366 | } |
| 367 | |
| 368 | #[cfg(test)] |
| 369 | mod tests { |
no test coverage detected