Skip to content

Commit e8cbf08

Browse files
jirijakesruben
authored andcommitted
refactor(wallet): Reuse chain position instead of obtaining new one
In `Wallet::preselect_utxos()`, the code used to obtain chain position of the UTXO's transaction from the graph, however the chain position is already recorded within the UTXO's representation (`LocalOutput`). This patch reuses the existing chain position instead of obtaining a fresh one.
1 parent 91b940a commit e8cbf08

File tree

1 file changed

+3
-13
lines changed
  • crates/wallet/src/wallet

1 file changed

+3
-13
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,6 @@ impl Wallet {
20112011
let must_only_use_confirmed_tx = bumping_fee.is_some();
20122012
let must_use_all_available = *drain_wallet;
20132013

2014-
let chain_tip = self.chain.tip().block_id();
20152014
// must_spend <- manually selected utxos
20162015
// may_spend <- all other available utxos
20172016
let mut may_spend = self.get_available_utxos();
@@ -2029,27 +2028,18 @@ impl Wallet {
20292028
return (must_spend, vec![]);
20302029
}
20312030

2032-
let canon_txs = self
2033-
.indexed_graph
2034-
.graph()
2035-
.list_canonical_txs(&self.chain, chain_tip)
2036-
.map(|canon_tx| (canon_tx.tx_node.txid, canon_tx))
2037-
.collect::<HashMap<Txid, _>>();
2038-
20392031
let satisfies_confirmed = may_spend
20402032
.iter()
20412033
.map(|u| -> bool {
20422034
let txid = u.0.outpoint.txid;
2043-
let (chain_position, tx) = match canon_txs.get(&txid) {
2044-
Some(CanonicalTx {
2045-
chain_position,
2046-
tx_node,
2047-
}) => (chain_position, tx_node.tx.clone()),
2035+
let tx = match self.indexed_graph.graph().get_tx(txid) {
2036+
Some(tx) => tx,
20482037
None => return false,
20492038
};
20502039

20512040
// Whether the UTXO is mature and, if needed, confirmed
20522041
let mut spendable = true;
2042+
let chain_position = u.0.chain_position;
20532043
if must_only_use_confirmed_tx && !chain_position.is_confirmed() {
20542044
return false;
20552045
}

0 commit comments

Comments
 (0)