Skip to content

Commit

Permalink
bitcoind: remove needless call to 'finalizepsbt'
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed Dec 14, 2021
1 parent afea49f commit 113db34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
26 changes: 7 additions & 19 deletions src/daemon/bitcoind/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ use crate::common::config::BitcoindConfig;
use crate::daemon::{bitcoind::BitcoindError, revaultd::BlockchainTip};
use revault_tx::{
bitcoin::{
blockdata::constants::COIN_VALUE,
consensus::{encode, Decodable},
hashes::hex::FromHex,
util::bip32::ChildNumber,
util::psbt::PartiallySignedTransaction as Psbt,
Amount, BlockHash, OutPoint, Script, Transaction, TxOut, Txid,
blockdata::constants::COIN_VALUE, consensus::encode, util::bip32::ChildNumber,
util::psbt::PartiallySignedTransaction as Psbt, Amount, BlockHash, OutPoint, Script,
Transaction, TxOut, Txid,
},
transactions::{DUST_LIMIT, UNVAULT_CPFP_VALUE},
};
Expand Down Expand Up @@ -718,6 +715,10 @@ impl BitcoinD {
})
}

/// Make bitcoind:
/// 1. Add information to the PSBT inputs
/// 2. Sign the PSBT inputs it can
/// 3. Finalize the PSBT if it is complete
pub fn sign_psbt(&self, psbt: &Psbt) -> Result<(bool, Psbt), BitcoindError> {
let res = self.make_cpfp_request(
"walletprocesspsbt",
Expand All @@ -740,19 +741,6 @@ impl BitcoinD {
Ok((complete, psbt))
}

pub fn finalize_psbt(&self, psbt: String) -> Result<Transaction, BitcoindError> {
let res = self.make_cpfp_request("finalizepsbt", &params!(Json::String(psbt)))?;
let hex_str = res
.get("hex")
.expect("API break: no 'hex' in 'finalizepsbt' result")
.as_str()
.expect("API break: invalid 'hex' in 'finalizepsbt' result");
let hex = <Vec<u8>>::from_hex(hex_str)
.expect("API break: invalid 'hex' in 'finalizepsbt' result");
Ok(Transaction::consensus_decode(hex.as_slice())
.expect("API break: invalid 'hex' in 'finalizepsbt' result"))
}

/// Broadcast a transaction with 'sendrawtransaction', discarding the returned txid
pub fn broadcast_transaction(&self, tx: &Transaction) -> Result<(), BitcoindError> {
let tx_hex = encode::serialize_hex(tx);
Expand Down
1 change: 0 additions & 1 deletion src/daemon/bitcoind/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ fn cpfp_package(
);
return Ok(());
}
let psbt_signed = bitcoind.finalize_psbt(psbt_signed)?;

let final_tx = psbt_signed.extract_tx();
if let Err(e) = bitcoind.broadcast_transaction(&final_tx) {
Expand Down

0 comments on commit 113db34

Please sign in to comment.