Refactor sync time verification
Instead of verifying txs at sync time in every backend, its moved to script_sync to by default be available to any backend.
This commit is contained in:
parent
b05ee78c73
commit
1d7ea89d8a
@ -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()))
|
||||
})
|
||||
|
@ -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>>()?;
|
||||
|
@ -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>>()?;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user