Pass height to decrypt_transaction()

This commit is contained in:
therealyingtong 2020-08-04 18:27:41 +08:00
parent 0a47a9dbea
commit 74b2f0a79e
No known key found for this signature in database
GPG Key ID: 179F32A1503D607E
2 changed files with 13 additions and 3 deletions

View File

@ -32,6 +32,7 @@ pub struct DecryptedOutput {
/// Scans a [`Transaction`] for any information that can be decrypted by the set of /// Scans a [`Transaction`] for any information that can be decrypted by the set of
/// [`ExtendedFullViewingKey`]s. /// [`ExtendedFullViewingKey`]s.
pub fn decrypt_transaction<P: consensus::Parameters>( pub fn decrypt_transaction<P: consensus::Parameters>(
height: u32,
parameters: &P, parameters: &P,
tx: &Transaction, tx: &Transaction,
extfvks: &[ExtendedFullViewingKey], extfvks: &[ExtendedFullViewingKey],
@ -53,7 +54,7 @@ pub fn decrypt_transaction<P: consensus::Parameters>(
for (account, (ivk, ovk)) in vks.iter().enumerate() { for (account, (ivk, ovk)) in vks.iter().enumerate() {
let ((note, to, memo), outgoing) = match try_sapling_note_decryption( let ((note, to, memo), outgoing) = match try_sapling_note_decryption(
parameters, parameters,
tx.expiry_height, height,
ivk, ivk,
&epk, &epk,
&output.cmu, &output.cmu,
@ -62,7 +63,7 @@ pub fn decrypt_transaction<P: consensus::Parameters>(
Some(ret) => (ret, false), Some(ret) => (ret, false),
None => match try_sapling_output_recovery( None => match try_sapling_output_recovery(
parameters, parameters,
tx.expiry_height, height,
ovk, ovk,
&output.cv, &output.cv,
&output.cmu, &output.cmu,

View File

@ -374,7 +374,16 @@ pub fn decrypt_and_store_transaction<P: AsRef<Path>>(
.collect::<Result<Result<Option<_>, _>, _>>()?? .collect::<Result<Result<Option<_>, _>, _>>()??
.ok_or(Error(ErrorKind::IncorrectHRPExtFVK))?; .ok_or(Error(ErrorKind::IncorrectHRPExtFVK))?;
let outputs = decrypt_transaction(&consensus::MainNetwork, tx, &extfvks); // Height is block height for mined transactions, and the "mempool height" (chain height + 1) for mempool transactions.
let last_height = data.query_row("SELECT MAX(height) FROM blocks", NO_PARAMS, |row| {
row.get(0).or(Ok(SAPLING_ACTIVATION_HEIGHT - 1))
})?;
let mut stmt_select_block = data.prepare("SELECT block FROM transactions WHERE txid = ?")?;
let height = stmt_select_block.query_row(&[tx.txid().0.to_vec()], |row| {
row.get(0).or(Ok(last_height + 1))
})?;
let outputs = decrypt_transaction(height as u32, &consensus::MainNetwork, tx, &extfvks);
if outputs.is_empty() { if outputs.is_empty() {
// Nothing to see here // Nothing to see here