From 183529b08f3443519c232b75f7fc3f5378a128b7 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 7 Mar 2024 14:18:30 -0700 Subject: [PATCH] WIP: zcash_client_backend: Implement generation of ZIP-320 compliant proposals. --- .../src/data_api/wallet/input_selection.rs | 14 +++++++++++++- zcash_keys/src/address.rs | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/zcash_client_backend/src/data_api/wallet/input_selection.rs b/zcash_client_backend/src/data_api/wallet/input_selection.rs index ebf891ca1c..d97329d091 100644 --- a/zcash_client_backend/src/data_api/wallet/input_selection.rs +++ b/zcash_client_backend/src/data_api/wallet/input_selection.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use std::{ collections::BTreeMap, error, - fmt::{self, Debug, Display}, + fmt::{self, Debug, Display}, ptr::addr_of_mut, }; use nonempty::NonEmpty; @@ -343,6 +343,7 @@ where #[cfg(feature = "orchard")] let mut orchard_outputs = vec![]; let mut payment_pools = BTreeMap::new(); + let mut ephemeral_transparent_output: Option<(TransparentAddress, NonNegativeAmount)> = None; for (idx, payment) in transaction_request.payments() { match &payment.recipient_address { Address::Transparent(addr) => { @@ -352,6 +353,17 @@ where script_pubkey: addr.script(), }); } + Address::TransparentSourceOnlyTransparent(_) => { + if let Some((addr, amount)) = ephemeral_transparent_output { + ephemeral_transparent_output = Some((addr, amount + payment.amount)); + } else { + // create ephemeral address + let ephemeral_addr = wallet_db + .get_new_transparent_address(account, TransparentKeyScope::custom(2)) + .map_err(InputSelectorError::DataSource)?; + ephemeral_transparent_output = Some((ephemeral_addr, payment.amount + 10000)) + } + } Address::Sapling(_) => { payment_pools.insert(*idx, PoolType::Shielded(ShieldedProtocol::Sapling)); sapling_outputs.push(SaplingPayment(payment.amount)); diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index dd1fb9ac43..8793ae2ca1 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -240,6 +240,7 @@ pub enum Address { Sapling(PaymentAddress), Transparent(TransparentAddress), Unified(UnifiedAddress), + TransparentSourceOnlyTransparent(TransparentAddress) } #[cfg(feature = "sapling")] @@ -287,6 +288,10 @@ impl TryFromRawAddress for Address { fn try_from_raw_transparent_p2sh(data: [u8; 20]) -> Result> { Ok(TransparentAddress::ScriptHash(data).into()) } + + fn try_from_raw_tex(data: [u8; 20]) -> Result> { + Ok(Address::TransparentSourceOnlyTransparent(TransparentAddress::PublicKeyHash(data))) + } } impl Address {