Don't panic if the sapling key is missing from the UFVK

Instead, just skip Sapling decryption.

Also, a trivial namespacing fix.
This commit is contained in:
Kris Nuttycombe 2022-06-27 10:19:23 -06:00
parent b52e949bd6
commit 7236204b14
3 changed files with 25 additions and 22 deletions

View File

@ -215,7 +215,7 @@ where
// https://github.com/zcash/librustzcash/issues/403
let dfvks: Vec<_> = ufvks
.iter()
.map(|(account, ufvk)| (account, ufvk.sapling().expect("TODO Add Orchard support")))
.filter_map(|(account, ufvk)| ufvk.sapling().map(move |k| (account, k)))
.collect();
// Get the most recent CommitmentTree

View File

@ -46,28 +46,30 @@ pub fn decrypt_transaction<P: consensus::Parameters>(
if let Some(bundle) = tx.sapling_bundle() {
for (account, ufvk) in ufvks.iter() {
let dfvk = ufvk.sapling().expect("TODO: Add Orchard support");
let ivk = dfvk.fvk().vk.ivk();
let ovk = dfvk.fvk().ovk;
if let Some(dfvk) = ufvk.sapling() {
let ivk = dfvk.fvk().vk.ivk();
let ovk = dfvk.fvk().ovk;
for (index, output) in bundle.shielded_outputs.iter().enumerate() {
let ((note, to, memo), outgoing) =
match try_sapling_note_decryption(params, height, &ivk, output) {
Some(ret) => (ret, false),
None => match try_sapling_output_recovery(params, height, &ovk, output) {
Some(ret) => (ret, true),
None => continue,
},
};
for (index, output) in bundle.shielded_outputs.iter().enumerate() {
let ((note, to, memo), outgoing) =
match try_sapling_note_decryption(params, height, &ivk, output) {
Some(ret) => (ret, false),
None => match try_sapling_output_recovery(params, height, &ovk, output)
{
Some(ret) => (ret, true),
None => continue,
},
};
decrypted.push(DecryptedOutput {
index,
note,
account: *account,
to,
memo,
outgoing,
})
decrypted.push(DecryptedOutput {
index,
note,
account: *account,
to,
memo,
outgoing,
})
}
}
}
}

View File

@ -9,6 +9,7 @@ use zcash_primitives::{
consensus::{self, BlockHeight},
merkle_tree::{CommitmentTree, IncrementalWitness},
sapling::{
self,
keys::DiversifiableFullViewingKey,
note_encryption::{try_sapling_compact_note_decryption, SaplingDomain},
Node, Note, Nullifier, PaymentAddress, SaplingIvk,
@ -129,7 +130,7 @@ pub trait ScanningKey {
}
impl ScanningKey for DiversifiableFullViewingKey {
type Nf = Nullifier;
type Nf = sapling::Nullifier;
fn try_decryption<
P: consensus::Parameters,