diff --git a/zcash_client_backend/src/data_api/testing.rs b/zcash_client_backend/src/data_api/testing.rs index 5103b97a4..0f35d35f9 100644 --- a/zcash_client_backend/src/data_api/testing.rs +++ b/zcash_client_backend/src/data_api/testing.rs @@ -1153,14 +1153,12 @@ where let prover = LocalTxProver::bundled(); let (spend_vk, output_vk) = prover.verifying_keys(); - let orchard_vk = ::orchard::circuit::VerifyingKey::build(); extract_and_store_transaction_from_pczt( self.wallet_mut(), pczt, - &spend_vk, - &output_vk, - &orchard_vk, + Some((&spend_vk, &output_vk)), + None, ) } diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index a2b8deda2..0527f1956 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -1681,13 +1681,23 @@ where /// metadata necessary for the wallet backend. /// /// Returns the transaction ID for the resulting transaction. +/// +/// - `sapling_vk` is optional to allow the caller to check whether a PCZT has Sapling +/// with [`pczt::roles::prover::Prover::requires_sapling_proofs`], and avoid downloading +/// the Sapling parameters if they are not needed. If `sapling_vk` is `None`, and the +/// PCZT has a Sapling bundle, this function will return an error. +/// - `orchard_vk` is optional to allow the caller to control where the Orchard verifying +/// key is generated or cached. If `orchard_vk` is `None`, and the PCZT has an Orchard +/// bundle, an Orchard verifying key will be generated on the fly. #[cfg(feature = "pczt")] pub fn extract_and_store_transaction_from_pczt( wallet_db: &mut DbT, pczt: pczt::Pczt, - spend_vk: &sapling::circuit::SpendVerifyingKey, - output_vk: &sapling::circuit::OutputVerifyingKey, - #[cfg(feature = "orchard")] orchard_vk: &orchard::circuit::VerifyingKey, + sapling_vk: Option<( + &sapling::circuit::SpendVerifyingKey, + &sapling::circuit::OutputVerifyingKey, + )>, + #[cfg(feature = "orchard")] orchard_vk: Option<&orchard::circuit::VerifyingKey>, ) -> Result> where DbT: WalletWrite + WalletCommitmentTrees, @@ -1853,10 +1863,14 @@ where }) .collect::, _>>()?; - let transaction = TransactionExtractor::new(finalized) - .with_sapling(spend_vk, output_vk) - .with_orchard(orchard_vk) - .extract()?; + let mut tx_extractor = TransactionExtractor::new(finalized); + if let Some((spend_vk, output_vk)) = sapling_vk { + tx_extractor = tx_extractor.with_sapling(spend_vk, output_vk); + } + if let Some(orchard_vk) = orchard_vk { + tx_extractor = tx_extractor.with_orchard(orchard_vk); + } + let transaction = tx_extractor.extract()?; let txid = transaction.txid(); #[allow(clippy::too_many_arguments)]