Skip to content

Commit

Permalink
bitcoind: reorganize code in cpfp_package()
Browse files Browse the repository at this point in the history
A nit, but it makes the check and assumption on the two vectors lengths
closer. Also rename the 'listunspent' var for being self-descriptive.
  • Loading branch information
darosior committed Dec 14, 2021
1 parent f3b92aa commit f066dbf
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/daemon/bitcoind/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,25 +429,8 @@ fn cpfp_package(
return Ok(());
}

let listunspent: Vec<_> = listunspent
.into_iter()
.filter_map(|l| {
// Not considering UTXOs still in mempool
if l.confirmations < 1 {
None
} else {
let txout = CpfpTxOut::new(
Amount::from_sat(l.txo.value),
&revaultd.derived_cpfp_descriptor(l.derivation_index.expect("Must be here")),
);
Some(CpfpTxIn::new(l.outpoint, txout))
}
})
.collect();

my_listunspent.sort_by_key(|l| l.outpoint.txid);
tx_package.sort_by_key(|tx| tx.txid());

// I can do this as I just ordered by txid
let mut txins = Vec::with_capacity(tx_package.len());
let mut package_weight = 0;
Expand All @@ -466,12 +449,27 @@ fn cpfp_package(
package_fees += Amount::from_sat(tx.fees()); // TODO(revault_tx): This should return an Amount!
}

let confirmed_cpfp_utxos: Vec<_> = listunspent
.into_iter()
.filter_map(|l| {
// Not considering UTXOs still in mempool
if l.confirmations < 1 {
None
} else {
let txout = CpfpTxOut::new(
Amount::from_sat(l.txo.value),
&revaultd.derived_cpfp_descriptor(l.derivation_index.expect("Must be here")),
);
Some(CpfpTxIn::new(l.outpoint, txout))
}
})
.collect();
let psbt = match CpfpTransaction::from_txins(
txins,
package_weight,
package_fees,
added_feerate,
listunspent,
confirmed_cpfp_utxos,
) {
Ok(tx) => tx,
Err(TransactionCreationError::InsufficientFunds) => {
Expand Down

0 comments on commit f066dbf

Please sign in to comment.