From ae09cb37076fb2a8e435462236289f39de96bd7c Mon Sep 17 00:00:00 2001 From: Cryptoforge Date: Fri, 18 Sep 2020 12:35:13 -0700 Subject: [PATCH] fix crash on single unspent note --- lib/src/lightwallet.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 5d1feaa..865639c 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -1363,21 +1363,26 @@ impl LightWallet { for spend in &tx.shielded_spends { let txid = nfs .iter() - .find(|(nf, _, _)| &nf[..] == &spend.nullifier[..]) - .unwrap() - .2; - let spent_note = txs - .get_mut(&txid) - .unwrap() - .notes - .iter_mut() - .find(|nd| &nd.nullifier[..] == &spend.nullifier[..]) - .unwrap(); + .find(|(nf, _, _)| &nf[..] == &spend.nullifier[..]); + + match txid { + Some(id) => { + let spent_note = txs + .get_mut(&id.2) + .unwrap() + .notes + .iter_mut() + .find(|nd| &nd.nullifier[..] == &spend.nullifier[..]) + .unwrap(); + + zinputs.push(encode_payment_address( + self.config.hrp_sapling_address(), + &spent_note.extfvk.fvk.vk + .to_payment_address(spent_note.diversifier, &JUBJUB).unwrap())) + }, + None => {} + }; - zinputs.push(encode_payment_address( - self.config.hrp_sapling_address(), - &spent_note.extfvk.fvk.vk - .to_payment_address(spent_note.diversifier, &JUBJUB).unwrap())); }