Skip to content

Commit df15a4a

Browse files
committed
fix(electrum): prevent populate_with_txids panic on transaction with no outputs
1 parent 726bb8a commit df15a4a

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

crates/electrum/src/bdk_electrum_client.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,24 +360,22 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
360360
Err(other_err) => return Err(other_err),
361361
};
362362

363-
let spk = tx
364-
.output
365-
.first()
366-
.map(|txo| &txo.script_pubkey)
367-
.expect("tx must have an output");
368-
369-
// because of restrictions of the Electrum API, we have to use the `script_get_history`
370-
// call to get confirmation status of our transaction
371-
if let Some(r) = self
372-
.inner
373-
.script_get_history(spk)?
374-
.into_iter()
375-
.find(|r| r.tx_hash == txid)
376-
{
377-
self.validate_merkle_for_anchor(tx_update, txid, r.height)?;
378-
}
363+
if let Some(txo) = tx.output.first() {
364+
let spk = &txo.script_pubkey;
365+
366+
// because of restrictions of the Electrum API, we have to use the `script_get_history`
367+
// call to get confirmation status of our transaction
368+
if let Some(r) = self
369+
.inner
370+
.script_get_history(spk)?
371+
.into_iter()
372+
.find(|r| r.tx_hash == txid)
373+
{
374+
self.validate_merkle_for_anchor(tx_update, txid, r.height)?;
375+
}
379376

380-
tx_update.txs.push(tx);
377+
tx_update.txs.push(tx);
378+
}
381379
}
382380
Ok(())
383381
}

0 commit comments

Comments
 (0)