From 00090dbfcd511895c2d6b9cced6d55545c4d4db7 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Fri, 29 Sep 2023 14:06:56 -0500 Subject: [PATCH] Improve error handling in Sapling decode --- librustzcash-wrapper/src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index e5879ef..f372a2e 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -364,16 +364,24 @@ pub extern "C" fn rust_wrapper_sapling_note_decrypt_v2( match svk { Ok(k) => { let domain = SaplingDomain::for_height(MainNetwork, BlockHeight::from_u32(2000000)); - let action2 = OutputDescription::read(&mut note_reader).unwrap(); - let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External); - let pivk = SaplingPreparedIncomingViewingKey::new(&fvk); - let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action2); - match result { - Some((n, r, m)) => { - let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() }; - marshall_to_haskell_var(&hn, out, out_len, RW); - } - None => { + let action2 = OutputDescription::read(&mut note_reader); + match action2 { + Ok(action3) => { + let fvk = k.to_diversifiable_full_viewing_key().to_ivk(SaplingScope::External); + let pivk = SaplingPreparedIncomingViewingKey::new(&fvk); + let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action3); + match result { + Some((n, r, m)) => { + let hn = Hnote {note: n.value().inner(), recipient: r.to_bytes().to_vec(), memo: m.as_slice().to_vec() }; + marshall_to_haskell_var(&hn, out, out_len, RW); + } + None => { + let hn0 = Hnote { note: 0, recipient: vec![0], memo: vec![0] }; + marshall_to_haskell_var(&hn0, out, out_len, RW); + } + } + }, + Err(_e1) => { let hn0 = Hnote { note: 0, recipient: vec![0], memo: vec![0] }; marshall_to_haskell_var(&hn0, out, out_len, RW); }