@@ -2,14 +2,15 @@ extern crate config as exconfig;
22
33use std:: collections:: { BTreeMap , HashMap } ;
44use std:: fs:: File ;
5- use std:: io:: Read ;
5+ use std:: io:: { Read , Write } ;
66use std:: ops:: { Add , Div , Mul } ;
77use std:: path:: PathBuf ;
88use std:: str:: FromStr ;
99use std:: sync:: Arc ;
1010use std:: time:: Duration ;
11- use std:: { env, thread} ;
11+ use std:: { env, io , thread} ;
1212
13+ use bdk:: bitcoin:: consensus:: ReadExt ;
1314use bdk:: bitcoin:: hashes:: hex:: ToHex ;
1415use bdk:: bitcoin:: secp256k1:: { All , Scalar , Secp256k1 } ;
1516use bdk:: bitcoin:: { secp256k1, Address as BitcoinAddress , Txid as BitcoinTxid } ;
@@ -20,7 +21,9 @@ use bdk::miniscript::descriptor::TapTree;
2021use bdk:: miniscript:: policy:: Concrete ;
2122use bdk:: miniscript:: Descriptor ;
2223use 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+ } ;
2427use ethers:: prelude:: { LocalWallet , SignerMiddleware } ;
2528use ethers:: providers:: { Middleware , Provider as EthereumClient , Provider , StreamExt , Ws } ;
2629use 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 ! ( "\n Failed 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