Skip to content

Commit

Permalink
fix: do not panic if electrum server does not support fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed Nov 11, 2024
1 parent 44fafc7 commit a2cc359
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions swap/src/bitcoin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ where
) -> Result<bitcoin::Amount> {
let client = self.client.lock().await;
let fee_rate = client.estimate_feerate(self.target_block)?;

let min_relay_fee = client.min_relay_fee()?;

estimate_fee(weight, transfer_amount, fee_rate, min_relay_fee)
Expand Down Expand Up @@ -871,6 +872,11 @@ impl EstimateFeeRate for Client {
// https://github.com/romanz/electrs/blob/f9cf5386d1b5de6769ee271df5eef324aa9491bc/src/rpc.rs#L213
// Returned estimated fees are per BTC/kb.
let fee_per_byte = self.electrum.estimate_fee(target_block)?;

if fee_per_byte < 0.0 {
bail!("Fee per byte returned by electrum server is negative: {}. This may indicate that fee estimation is not supported by this server", fee_per_byte);
}

// we do not expect fees being that high.
#[allow(clippy::cast_possible_truncation)]
Ok(FeeRate::from_btc_per_kvb(fee_per_byte as f32))
Expand Down

0 comments on commit a2cc359

Please sign in to comment.