From 882db96fbeaa4efed1a2f48ea20d1ee4204722d7 Mon Sep 17 00:00:00 2001 From: Greg Martin Date: Tue, 18 Apr 2023 16:39:00 +0000 Subject: [PATCH] Rework the bitcoin connection logic while waiting for commit to confirm. --- src/subcommand/wallet/inscribe.rs | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index b52e8dfdb2..60ef705672 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -238,46 +238,48 @@ impl Inscribe { .context("Failed to send commit transaction")?; if self.wait_after_commit { + let mut failed = false; drop(index); eprint!("[waiting for commit transaction {} to confirm] ", commit); io::stdout().flush()?; + drop(client); loop { - match client.get_transaction(&commit, Some(false)) { - Ok(tx) => { - if tx.info.confirmations > 0 { - eprintln!(); - eprintln!("[confirmed]"); - break; + thread::sleep(time::Duration::from_secs(60)); + match options.bitcoin_rpc_client_for_wallet_command(false) { + Ok(client) => { + if failed == true { + eprintln!("[reconnected]"); + failed = false; } - eprint!("."); - } - Err(error) => { - eprintln!(); - eprintln!("[error: {:?}]", error); - eprintln!("[trying to reconnect to bitcoin client]"); - loop { - match options.bitcoin_rpc_client_for_wallet_command(false) { - Ok(c) => { - client = c; - eprintln!("[reconnected to bitcoin client]"); - eprintln!("[continuing to wait for commit transaction {} to confirm]", commit); + + match client.get_transaction(&commit, Some(false)) { + Ok(tx) => { + if tx.info.confirmations > 0 { + eprintln!(); + eprintln!("[confirmed]"); break; } - Err(error) => { - eprintln!("[failed to connect to bitcoin client: {:?}]", error); - thread::sleep(time::Duration::from_secs(60)); - } + eprint!("."); + } + Err(error) => { + eprintln!(); + eprintln!("[error: {:?}]", error); + eprintln!("[trying to reconnect to bitcoin client]"); + failed = true; } } } + Err(error) => { + eprintln!(); + eprintln!("[failed to connect to bitcoin client: {:?}]", error); + failed = true; + thread::sleep(time::Duration::from_secs(60)); + } } - io::stdout().flush()?; - drop(client); - thread::sleep(time::Duration::from_secs(60)); - client = options.bitcoin_rpc_client_for_wallet_command(false)?; } } + client = options.bitcoin_rpc_client_for_wallet_command(false)?; let mut reveals = Vec::new(); for reveal_tx in reveal_txs { reveals.push(