From 678f1b673457091e514f833dd9dd78e91ea2f11a Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 25 Mar 2021 21:53:47 +1300 Subject: [PATCH] zcash_client_backend: Make transparent output indexing resilient It's cheap to scan all transparent outputs to find the output matching a transparent recipient. --- zcash_client_backend/src/data_api/wallet.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index 349233acf..94aa64a1c 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -235,10 +235,15 @@ where Some(idx) => idx, None => panic!("Output 0 should exist in the transaction"), }, - // This function only spends shielded notes, so there will only ever be a single - // transparent output in this case (and even if there were more, we don't shuffle - // the transparent outputs). - RecipientAddress::Transparent(_) => 0, + RecipientAddress::Transparent(addr) => { + let script = addr.script(); + tx.vout + .iter() + .enumerate() + .find(|(_, tx_out)| tx_out.script_pubkey == script) + .map(|(index, _)| index) + .expect("we sent to this address") + } }; wallet_db.store_sent_tx(&SentTransaction {