Skip to content

Commit

Permalink
Merge branch 'ephemeral_sync' into multistep_proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
AloeareV committed Oct 10, 2024
2 parents 8436a45 + 70949c4 commit 98650c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
14 changes: 12 additions & 2 deletions zingolib/src/wallet/keys/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use zcash_client_backend::address::UnifiedAddress;
use zcash_client_backend::keys::{Era, UnifiedSpendingKey};
use zcash_client_backend::wallet::TransparentAddressMetadata;
use zcash_encoding::{CompactSize, Vector};
use zcash_keys::keys::{DerivationError, UnifiedFullViewingKey};
use zcash_keys::{
encoding::AddressCodec,
keys::{DerivationError, UnifiedFullViewingKey},
};
use zcash_primitives::consensus::{NetworkConstants, Parameters};
use zcash_primitives::legacy::{
keys::{AccountPubKey, IncomingViewingKey, NonHardenedChildIndex},
Expand Down Expand Up @@ -556,7 +559,7 @@ impl WalletCapability {
})
}

pub(crate) fn get_all_taddrs(&self, chain: &crate::config::ChainType) -> HashSet<String> {
pub(crate) fn get_external_taddrs(&self, chain: &crate::config::ChainType) -> HashSet<String> {
self.unified_addresses
.iter()
.filter_map(|address| {
Expand All @@ -577,6 +580,13 @@ impl WalletCapability {
.collect()
}

pub(crate) fn get_ephemeral_taddrs(&self, chain: &crate::config::ChainType) -> HashSet<String> {
self.transparent_child_ephemeral_addresses
.iter()
.map(|(transparent_address, _metadata)| transparent_address.encode(chain))
.collect()
}

/// TODO: Add Doc Comment Here!
pub fn first_sapling_address(&self) -> sapling_crypto::PaymentAddress {
// This index is dangerous, but all ways to instantiate a UnifiedSpendAuthority
Expand Down
29 changes: 15 additions & 14 deletions zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl TransactionContext {
)
.map(|_| ())
}

fn handle_receipt_to_ephemeral_taddr(&self) {
todo!()
}
}

/// These functions are responsible for receiving a full Transaction and storing it, with a few major caveats.
Expand Down Expand Up @@ -82,7 +86,7 @@ mod decrypt_transaction {
};
use orchard::note_encryption::OrchardDomain;
use sapling_crypto::note_encryption::SaplingDomain;
use std::{collections::HashSet, convert::TryInto};
use std::convert::TryInto;

use zcash_client_backend::address::{Address, UnifiedAddress};
use zcash_note_encryption::{try_output_recovery_with_ovk, Domain};
Expand All @@ -107,7 +111,7 @@ mod decrypt_transaction {
let mut txid_indexed_zingo_memos = Vec::new();

// Collect our t-addresses for easy checking
let taddrs_set = self.key.get_all_taddrs(&self.config.chain);
let taddrs_set = self.key.get_external_taddrs(&self.config.chain);

let mut outgoing_metadatas = vec![];

Expand All @@ -118,7 +122,6 @@ mod decrypt_transaction {
block_time,
&mut outgoing_metadatas,
&mut txid_indexed_zingo_memos,
&taddrs_set,
)
.await;

Expand Down Expand Up @@ -182,17 +185,11 @@ mod decrypt_transaction {
block_time: Option<u32>,
outgoing_metadatas: &mut Vec<OutgoingTxData>,
arbitrary_memos_with_txids: &mut Vec<(ParsedMemo, TxId)>,
taddrs_set: &HashSet<String>,
) {
//todo: investigate scanning all bundles simultaneously

self.decrypt_transaction_to_record_transparent(
transaction,
status,
block_time,
taddrs_set,
)
.await;
self.decrypt_transaction_to_record_transparent(transaction, status, block_time)
.await;
self.decrypt_transaction_to_record_sapling(
transaction,
status,
Expand All @@ -216,10 +213,9 @@ mod decrypt_transaction {
transaction: &Transaction,
status: ConfirmationStatus,
block_time: Option<u32>,
taddrs_set: &HashSet<String>,
) {
// Scan all transparent outputs to see if we received any money
self.account_for_transparent_receipts(transaction, status, block_time, taddrs_set)
self.account_for_transparent_receipts(transaction, status, block_time)
.await;
// Scan transparent spends
self.account_for_transparent_spending(transaction, status, block_time)
Expand All @@ -230,9 +226,11 @@ mod decrypt_transaction {
transaction: &Transaction,
status: ConfirmationStatus,
block_time: Option<u32>,
taddrs_set: &HashSet<String>,
) {
if let Some(t_bundle) = transaction.transparent_bundle() {
// Collect our t-addresses for easy checking
let taddrs_set = self.key.get_external_taddrs(&self.config.chain);
let ephemeral_taddrs = self.key.get_ephemeral_taddrs(&self.config.chain);
for (n, vout) in t_bundle.vout.iter().enumerate() {
if let Some(taddr) = vout.recipient_address() {
let output_taddr = address_from_pubkeyhash(&self.config, taddr);
Expand All @@ -251,6 +249,9 @@ mod decrypt_transaction {
n as u32,
);
}
if ephemeral_taddrs.contains(&output_taddr) {
self.handle_receipt_to_ephemeral_taddr()
}
}
}
}
Expand Down

0 comments on commit 98650c7

Please sign in to comment.