From 3a503bf95fb84f32ade27aff48eed82f6b925343 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 2 Mar 2021 12:25:47 +1100 Subject: [PATCH] Shorten function name This struct is a wallet. The only thing it can meaningfully broadcast are transactions. The fact that they have to be signed for that is implied. You cannot broadcast unsigned transactions. --- swap/src/bitcoin/wallet.rs | 2 +- swap/src/protocol/alice/steps.rs | 12 +++--------- swap/src/protocol/bob/state.rs | 12 +++--------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 96382321..17d7ace5 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -147,7 +147,7 @@ impl Wallet { self.inner.lock().await.network() } - pub async fn broadcast_signed_transaction(&self, transaction: Transaction) -> Result { + pub async fn broadcast(&self, transaction: Transaction) -> Result { let txid = transaction.txid(); self.inner diff --git a/swap/src/protocol/alice/steps.rs b/swap/src/protocol/alice/steps.rs index 6adfbac4..cdb447ac 100644 --- a/swap/src/protocol/alice/steps.rs +++ b/swap/src/protocol/alice/steps.rs @@ -130,9 +130,7 @@ pub async fn publish_bitcoin_redeem_transaction( bitcoin_wallet: Arc, ) -> Result<::bitcoin::Txid> { info!("Attempting to publish bitcoin redeem txn"); - let txid = bitcoin_wallet - .broadcast_signed_transaction(redeem_tx) - .await?; + let txid = bitcoin_wallet.broadcast(redeem_tx).await?; Ok(txid) } @@ -172,9 +170,7 @@ pub async fn publish_cancel_transaction( .expect("sig_{a,b} to be valid signatures for tx_cancel"); // TODO(Franck): Error handling is delicate, why can't we broadcast? - bitcoin_wallet - .broadcast_signed_transaction(tx_cancel) - .await?; + bitcoin_wallet.broadcast(tx_cancel).await?; // TODO(Franck): Wait until transaction is mined and returned mined // block height @@ -258,9 +254,7 @@ pub async fn publish_bitcoin_punish_transaction( bitcoin_wallet: Arc, execution_params: ExecutionParams, ) -> Result { - let txid = bitcoin_wallet - .broadcast_signed_transaction(punish_tx) - .await?; + let txid = bitcoin_wallet.broadcast(punish_tx).await?; bitcoin_wallet .wait_for_transaction_finality(txid, execution_params) diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 77cac8a8..584fcee0 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -272,9 +272,7 @@ impl State2 { let signed_tx_lock = bitcoin_wallet.sign_tx_lock(self.tx_lock.clone()).await?; tracing::debug!("locking BTC in transaction {}", self.tx_lock.txid()); - let _ = bitcoin_wallet - .broadcast_signed_transaction(signed_tx_lock) - .await?; + let _ = bitcoin_wallet.broadcast(signed_tx_lock).await?; Ok(State3 { A: self.A, @@ -477,9 +475,7 @@ impl State4 { tx_cancel", ); - let tx_id = bitcoin_wallet - .broadcast_signed_transaction(tx_cancel) - .await?; + let tx_id = bitcoin_wallet.broadcast(tx_cancel).await?; Ok(tx_id) } @@ -548,9 +544,7 @@ impl State4 { let signed_tx_refund = tx_refund.add_signatures((self.A, sig_a), (self.b.public(), sig_b))?; - let txid = bitcoin_wallet - .broadcast_signed_transaction(signed_tx_refund) - .await?; + let txid = bitcoin_wallet.broadcast(signed_tx_refund).await?; bitcoin_wallet .wait_for_transaction_finality(txid, execution_params)