]> Untitled Git - bdk/commitdiff
Refactor sync time verification
authorrajarshimaitra <rajarshi149@gmail.com>
Fri, 21 Jan 2022 16:13:05 +0000 (21:43 +0530)
committerrajarshimaitra <rajarshi149@gmail.com>
Wed, 9 Feb 2022 11:29:53 +0000 (16:59 +0530)
Instead of verifying txs at sync time in every backend, its moved to
script_sync to by default be available to any backend.

src/blockchain/electrum.rs
src/blockchain/esplora/reqwest.rs
src/blockchain/esplora/ureq.rs
src/blockchain/script_sync.rs

index 9ebde98922581ac47bacd6df8b305cfb3aca6cf0..1ab0db1c3ee6cb79985faa5408192c5fad46d1e2 100644 (file)
@@ -190,19 +190,6 @@ 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()))
                                 })
index f1f39f9dcc911d293580676f3297fade96b029ba..494c6d307e9bc461c348e0489b391ee0a7d30724 100644 (file)
@@ -167,24 +167,6 @@ impl Blockchain for EsploraBlockchain {
                         .request()
                         .map(|txid| {
                             let tx = tx_index.get(txid).expect("must be in index");
-                            // 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::<Result<_, Error>>()?;
index a32d8137da2b90fbcd0ab50ffffbd0232e6314e3..856f6958e19c3eb60fc97f600e7ba75d5e9710a9 100644 (file)
@@ -166,24 +166,6 @@ impl Blockchain for EsploraBlockchain {
                         .request()
                         .map(|txid| {
                             let tx = tx_index.get(txid).expect("must be in index");
-                            // 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::<Result<_, Error>>()?;
index 0d450ef17970a2706540636e655ed33b8f7886d4..6fd3b9c816c001609dffd1359cc70cfea0145cfc 100644 (file)
@@ -178,7 +178,9 @@ impl<'a, D: BatchDatabase> TxReq<'a, D> {
                 let mut inputs_sum: u64 = 0;
                 let mut outputs_sum: u64 = 0;
 
-                for (txout, input) in vout.into_iter().zip(tx.input.iter()) {
+                for (txout, (_input_index, input)) in
+                    vout.into_iter().zip(tx.input.iter().enumerate())
+                {
                     let txout = match txout {
                         Some(txout) => txout,
                         None => {
@@ -190,7 +192,19 @@ impl<'a, D: BatchDatabase> TxReq<'a, D> {
                             continue;
                         }
                     };
-
+                    // 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(VerifyError::from)?;
+                    }
                     inputs_sum += txout.value;
                     if self.state.db.is_mine(&txout.script_pubkey)? {
                         sent += txout.value;