Skip to content

Commit 30908f6

Browse files
committed
Fix feerate estimation for nigiri
1 parent f238661 commit 30908f6

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/main.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ extern crate config as exconfig;
22

33
use std::collections::{BTreeMap, HashMap};
44
use std::fs::File;
5-
use std::io::Read;
5+
use std::io::{Read, Write};
66
use std::ops::{Add, Div, Mul};
77
use std::path::PathBuf;
88
use std::str::FromStr;
99
use std::sync::Arc;
1010
use std::time::Duration;
11-
use std::{env, thread};
11+
use std::{env, io, thread};
1212

13+
use bdk::bitcoin::consensus::ReadExt;
1314
use bdk::bitcoin::hashes::hex::ToHex;
1415
use bdk::bitcoin::secp256k1::{All, Scalar, Secp256k1};
1516
use bdk::bitcoin::{secp256k1, Address as BitcoinAddress, Txid as BitcoinTxid};
@@ -20,7 +21,9 @@ use bdk::miniscript::descriptor::TapTree;
2021
use bdk::miniscript::policy::Concrete;
2122
use bdk::miniscript::Descriptor;
2223
use bdk::wallet::AddressIndex;
23-
use bdk::{bitcoin, KeychainKind, SignOptions, SyncOptions, Wallet as BitcoinWallet, Wallet};
24+
use bdk::{
25+
bitcoin, FeeRate, KeychainKind, SignOptions, SyncOptions, Wallet as BitcoinWallet, Wallet,
26+
};
2427
use ethers::prelude::{LocalWallet, SignerMiddleware};
2528
use ethers::providers::{Middleware, Provider as EthereumClient, Provider, StreamExt, Ws};
2629
use ethers::signers::{LocalWallet as EthereumWallet, Signer};
@@ -499,10 +502,19 @@ impl SwapParticipant {
499502
self.bitcoin_wallet.network(),
500503
)?;
501504

502-
let feerate = self
503-
.bitcoin_client
504-
.estimate_fee(2)
505-
.wrap_err("failed to estimate fee")?;
505+
let feerate = self.bitcoin_client.estimate_fee(2).unwrap_or_else(|err| {
506+
println!("\nFailed to estimate Bitcoin feerate for withdraw: {}", err);
507+
print!("Input your feerate sat/vByte (e.g. '60'): ");
508+
509+
io::stdout().flush().unwrap();
510+
let mut input_feerate = String::new();
511+
io::stdin()
512+
.read_line(&mut input_feerate)
513+
.expect("Failed to read line");
514+
let feerate: u32 = input_feerate.trim().parse().expect("Input not an integer");
515+
516+
FeeRate::from_sat_per_vb(feerate as f32)
517+
});
506518

507519
builder
508520
.fee_rate(feerate)
@@ -596,10 +608,19 @@ impl SwapParticipant {
596608
let (mut psbt, _details) = {
597609
let mut tx_builder = self.bitcoin_wallet.build_tx();
598610

599-
let feerate = self
600-
.bitcoin_client
601-
.estimate_fee(2)
602-
.wrap_err("failed to estimate fee")?;
611+
let feerate = self.bitcoin_client.estimate_fee(2).unwrap_or_else(|err| {
612+
println!("| Failed to estimate Bitcoin feerate: {}", err);
613+
print!("| Input your feerate sat/vByte (e.g. '60'): ");
614+
615+
io::stdout().flush().unwrap();
616+
let mut input_feerate = String::new();
617+
io::stdin()
618+
.read_line(&mut input_feerate)
619+
.expect("Failed to read line");
620+
let feerate: u32 = input_feerate.trim().parse().expect("Input not an integer");
621+
622+
FeeRate::from_sat_per_vb(feerate as f32)
623+
});
603624

604625
tx_builder
605626
.fee_rate(feerate)

0 commit comments

Comments
 (0)