Skip to content

Commit

Permalink
f Use tracked BlockHash for unconfirm
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Nov 4, 2022
1 parent 9ead046 commit 5f6676f
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,25 @@ where
&self, confirmables: &Vec<&(dyn Confirm + Sync)>,
) -> Result<(), Error> {
let client = &*self.blockchain;
// Query the interface for relevant txids and check whether they have been
// reorged-out of the chain.
let relevant_txids =
confirmables.iter().flat_map(|c| c.get_relevant_txids()).collect::<HashSet<Txid>>();
for txid in relevant_txids {
let tx_unconfirmed = client
.get_tx_status(&txid)
.await
.ok()
.unwrap_or(None)
.map_or(true, |status| !status.confirmed);
if tx_unconfirmed {
for c in confirmables {
c.transaction_unconfirmed(&txid);
// Query the interface for relevant txids and check whether the relevant blocks are still
// in the best chain, mark them unconfirmed otherwise. If the transactions have been
// reconfirmed in another block, we'll confirm them in the next sync iteration.
let relevant_txids = confirmables
.iter()
.flat_map(|c| c.get_relevant_txids())
.collect::<HashSet<(Txid, Option<BlockHash>)>>();
for (txid, block_hash_opt) in relevant_txids {
if let Some(block_hash) = block_hash_opt {
let block_status = client.get_block_status(&block_hash).await?;
if block_status.in_best_chain {
// Skip if the block in queestion is still confirmed.
continue;
}
}

for c in confirmables {
c.transaction_unconfirmed(&txid);
}
}

Ok(())
Expand Down

0 comments on commit 5f6676f

Please sign in to comment.