Skip to content

Commit 5eb3e98

Browse files
committed
f Simplify get_unconfirmed_transactions
.. now that we have the height to check.
1 parent b83b153 commit 5eb3e98

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

lightning-transaction-sync/src/electrum.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -326,36 +326,16 @@ where
326326
let relevant_txids = confirmables
327327
.iter()
328328
.flat_map(|c| c.get_relevant_txids())
329-
.collect::<HashSet<(Txid, Option<BlockHash>)>>();
329+
.collect::<HashSet<(Txid, u32, Option<BlockHash>)>>();
330330

331331
let mut unconfirmed_txs = Vec::new();
332332

333-
for (txid, block_hash_opt) in relevant_txids {
333+
for (txid, conf_height, block_hash_opt) in relevant_txids {
334334
if let Some(block_hash) = block_hash_opt {
335-
match self.client.transaction_get(&txid) {
336-
Ok(tx) => {
337-
if let Some(tx_out) = tx.output.first() {
338-
let script_history = self.client.script_get_history(&tx_out.script_pubkey)?;
339-
if let Some(history) = script_history.iter()
340-
.filter(|h| h.tx_hash == txid).max_by_key(|x| x.height)
341-
{
342-
let prob_conf_height = history.height;
343-
let block_header = self.client.block_header(
344-
prob_conf_height as usize)?;
345-
if block_header.block_hash() == block_hash {
346-
// Skip if the tx is still confirmed in the block in question.
347-
continue;
348-
}
349-
}
350-
}
351-
}
352-
Err(electrum_client::Error::Protocol(_)) => {
353-
// We couldn't find the tx, unconfirming..
354-
}
355-
Err(e) => {
356-
log_error!(self.logger, "Failed to look up transaction {}: {}.", txid, e);
357-
return Err(InternalError::Failed);
358-
}
335+
let block_header = self.client.block_header(conf_height as usize)?;
336+
if block_header.block_hash() == block_hash {
337+
// Skip if the tx is still confirmed in the block in question.
338+
continue;
359339
}
360340

361341
unconfirmed_txs.push(txid);

0 commit comments

Comments
 (0)