From 74b2f0a79e71e223b9f3615a536b79d6d4d346f0 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 4 Aug 2020 18:27:41 +0800 Subject: [PATCH] Pass height to decrypt_transaction() --- zcash_client_backend/src/decrypt.rs | 5 +++-- zcash_client_sqlite/src/scan.rs | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/zcash_client_backend/src/decrypt.rs b/zcash_client_backend/src/decrypt.rs index ef6b94a2b..9079e9c9b 100644 --- a/zcash_client_backend/src/decrypt.rs +++ b/zcash_client_backend/src/decrypt.rs @@ -32,6 +32,7 @@ pub struct DecryptedOutput { /// Scans a [`Transaction`] for any information that can be decrypted by the set of /// [`ExtendedFullViewingKey`]s. pub fn decrypt_transaction( + height: u32, parameters: &P, tx: &Transaction, extfvks: &[ExtendedFullViewingKey], @@ -53,7 +54,7 @@ pub fn decrypt_transaction( for (account, (ivk, ovk)) in vks.iter().enumerate() { let ((note, to, memo), outgoing) = match try_sapling_note_decryption( parameters, - tx.expiry_height, + height, ivk, &epk, &output.cmu, @@ -62,7 +63,7 @@ pub fn decrypt_transaction( Some(ret) => (ret, false), None => match try_sapling_output_recovery( parameters, - tx.expiry_height, + height, ovk, &output.cv, &output.cmu, diff --git a/zcash_client_sqlite/src/scan.rs b/zcash_client_sqlite/src/scan.rs index f4510c861..d665e4b12 100644 --- a/zcash_client_sqlite/src/scan.rs +++ b/zcash_client_sqlite/src/scan.rs @@ -374,7 +374,16 @@ pub fn decrypt_and_store_transaction>( .collect::, _>, _>>()?? .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() { // Nothing to see here