Skip to content

Commit b33c0a5

Browse files
committed
fix(electrum): prevent populate_with_txids panic on transaction with no outputs
1 parent 943d762 commit b33c0a5

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
@@ -346,24 +346,22 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
346346
Err(other_err) => return Err(other_err),
347347
};
348348

349-
let spk = tx
350-
.output
351-
.first()
352-
.map(|txo| &txo.script_pubkey)
353-
.expect("tx must have an output");
354-
355-
// because of restrictions of the Electrum API, we have to use the `script_get_history`
356-
// call to get confirmation status of our transaction
357-
if let Some(r) = self
358-
.inner
359-
.script_get_history(spk)?
360-
.into_iter()
361-
.find(|r| r.tx_hash == txid)
362-
{
363-
self.validate_merkle_for_anchor(tx_update, txid, r.height)?;
364-
}
349+
if let Some(txo) = tx.output.first() {
350+
let spk = &txo.script_pubkey;
351+
352+
// because of restrictions of the Electrum API, we have to use the `script_get_history`
353+
// call to get confirmation status of our transaction
354+
if let Some(r) = self
355+
.inner
356+
.script_get_history(spk)?
357+
.into_iter()
358+
.find(|r| r.tx_hash == txid)
359+
{
360+
self.validate_merkle_for_anchor(tx_update, txid, r.height)?;
361+
}
365362

366-
tx_update.txs.push(tx);
363+
tx_update.txs.push(tx);
364+
}
367365
}
368366
Ok(())
369367
}

0 commit comments

Comments
 (0)