]> Untitled Git - bdk/commitdiff
Add sync verification in `electrum`
authorrajarshimaitra <rajarshi149@gmail.com>
Thu, 16 Dec 2021 15:23:16 +0000 (20:53 +0530)
committerrajarshimaitra <rajarshi149@gmail.com>
Wed, 9 Feb 2022 06:59:47 +0000 (12:29 +0530)
src/blockchain/electrum.rs

index cb079a8743818718d84df0774016750261d66200..9ebde98922581ac47bacd6df8b305cfb3aca6cf0 100644 (file)
@@ -175,6 +175,7 @@ impl Blockchain for ElectrumBlockchain {
                     let full_details = full_transactions
                         .into_iter()
                         .map(|tx| {
+                            let mut input_index = 0usize;
                             let prev_outputs = tx
                                 .input
                                 .iter()
@@ -189,6 +190,20 @@ impl Blockchain for ElectrumBlockchain {
                                         .output
                                         .get(input.previous_output.vout as usize)
                                         .ok_or_else(electrum_goof)?;
+                                    // Verify this input if requested via feature flag
+                                    #[cfg(feature = "verify")]
+                                    {
+                                        use crate::wallet::verify::VerifyError;
+                                        let serialized_tx = bitcoin::consensus::serialize(&tx);
+                                        bitcoinconsensus::verify(
+                                            txout.script_pubkey.to_bytes().as_ref(),
+                                            txout.value,
+                                            &serialized_tx,
+                                            input_index,
+                                        )
+                                        .map_err(|e| VerifyError::from(e))?;
+                                    }
+                                    input_index += 1;
                                     Ok(Some(txout.clone()))
                                 })
                                 .collect::<Result<Vec<_>, Error>>()?;