zcash_client_backend: Make transparent output indexing resilient

It's cheap to scan all transparent outputs to find the output matching
a transparent recipient.
This commit is contained in:
Jack Grigg 2021-03-25 21:53:47 +13:00
parent 6f93530554
commit 678f1b6734
1 changed files with 9 additions and 4 deletions

View File

@ -235,10 +235,15 @@ where
Some(idx) => idx, Some(idx) => idx,
None => panic!("Output 0 should exist in the transaction"), None => panic!("Output 0 should exist in the transaction"),
}, },
// This function only spends shielded notes, so there will only ever be a single RecipientAddress::Transparent(addr) => {
// transparent output in this case (and even if there were more, we don't shuffle let script = addr.script();
// the transparent outputs). tx.vout
RecipientAddress::Transparent(_) => 0, .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 { wallet_db.store_sent_tx(&SentTransaction {