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

index aaf487e4a720808f3f27713f29636145445a3316..f1f39f9dcc911d293580676f3297fade96b029ba 100644 (file)
@@ -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,
index f3895a15f10e31cb028e1fe71c5a8e854526b85e..a32d8137da2b90fbcd0ab50ffffbd0232e6314e3 100644 (file)
@@ -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,