Skip to content

Commit

Permalink
Add sync verification for esplora
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshimaitra committed Feb 9, 2022
1 parent ad07116 commit 6fa29fa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/blockchain/esplora/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,27 @@ impl Blockchain for EsploraBlockchain {
.request()
.map(|txid| {
let tx = tx_index.get(txid).expect("must be in index");
(tx.previous_outputs(), tx.to_tx())
// Verify this transaction if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let prev_outs = tx.previous_outputs();
let tx_bytes = serialize(&tx.to_tx());
for (index, output) in prev_outs.iter().enumerate() {
if let Some(output) = output {
bitcoinconsensus::verify(
output.script_pubkey.to_bytes().as_ref(),
output.value,
&tx_bytes,
index,
)
.map_err(|e| VerifyError::from(e))?;
}
}
}
Ok((tx.previous_outputs(), tx.to_tx()))
})
.collect();
.collect::<Result<_, Error>>()?;
tx_req.satisfy(full_txs)?
}
Request::Finish(batch_update) => break batch_update,
Expand Down
22 changes: 20 additions & 2 deletions src/blockchain/esplora/ureq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,27 @@ impl Blockchain for EsploraBlockchain {
.request()
.map(|txid| {
let tx = tx_index.get(txid).expect("must be in index");
(tx.previous_outputs(), tx.to_tx())
// Verify this transaction if requested via feature flag
#[cfg(feature = "verify")]
{
use crate::wallet::verify::VerifyError;
let prev_outs = tx.previous_outputs();
let tx_bytes = serialize(&tx.to_tx());
for (index, output) in prev_outs.iter().enumerate() {
if let Some(output) = output {
bitcoinconsensus::verify(
output.script_pubkey.to_bytes().as_ref(),
output.value,
&tx_bytes,
index,
)
.map_err(|e| VerifyError::from(e))?;
}
}
}
Ok((tx.previous_outputs(), tx.to_tx()))
})
.collect();
.collect::<Result<_, Error>>()?;
tx_req.satisfy(full_txs)?
}
Request::Finish(batch_update) => break batch_update,
Expand Down

0 comments on commit 6fa29fa

Please sign in to comment.