Skip to content

Commit

Permalink
WIP: zcash_client_backend: Implement generation of ZIP-320 compliant …
Browse files Browse the repository at this point in the history
…proposals.
  • Loading branch information
nuttycom committed Mar 7, 2024
1 parent 8130359 commit 183529b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion zcash_client_backend/src/data_api/wallet/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions zcash_keys/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ pub enum Address {
Sapling(PaymentAddress),
Transparent(TransparentAddress),
Unified(UnifiedAddress),
TransparentSourceOnlyTransparent(TransparentAddress)
}

#[cfg(feature = "sapling")]
Expand Down Expand Up @@ -287,6 +288,10 @@ impl TryFromRawAddress for Address {
fn try_from_raw_transparent_p2sh(data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
Ok(TransparentAddress::ScriptHash(data).into())
}

fn try_from_raw_tex(data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address::TransparentSourceOnlyTransparent(TransparentAddress::PublicKeyHash(data)))
}
}

impl Address {
Expand Down

0 comments on commit 183529b

Please sign in to comment.