Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
AloeareV committed Oct 17, 2024
1 parent f3372cf commit 0f924f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
38 changes: 24 additions & 14 deletions zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl TransactionContext {
mod decrypt_transaction {
use crate::{
error::{ZingoLibError, ZingoLibResult},
utils::interpret_taddr_as_tex_addr,
wallet::{
self,
data::OutgoingTxData,
Expand All @@ -93,6 +94,7 @@ mod decrypt_transaction {
use zcash_client_backend::address::{Address, UnifiedAddress};
use zcash_note_encryption::{try_output_recovery_with_ovk, Domain};
use zcash_primitives::{
legacy::TransparentAddress,
memo::{Memo, MemoBytes},
transaction::{
components::{transparent::Authorized, TxIn},
Expand All @@ -117,6 +119,7 @@ mod decrypt_transaction {
let mut txid_indexed_zingo_memos = Vec::new();

let mut outgoing_metadatas = vec![];
let mut sent_to_tex = false;

// Execute scanning operations
self.decrypt_transaction_to_record(
Expand All @@ -125,11 +128,12 @@ mod decrypt_transaction {
block_time,
&mut outgoing_metadatas,
&mut txid_indexed_zingo_memos,
&mut sent_to_tex,
)
.await;

// Post process scan results
self.post_process_scan_results(transaction, &mut outgoing_metadatas)
self.post_process_scan_results(transaction, &mut outgoing_metadatas, sent_to_tex)
.await;

if !outgoing_metadatas.is_empty() {
Expand Down Expand Up @@ -162,11 +166,17 @@ mod decrypt_transaction {
block_time: Option<u32>,
outgoing_metadatas: &mut Vec<OutgoingTxData>,
arbitrary_memos_with_txids: &mut Vec<(ParsedMemo, TxId)>,
sent_to_tex: &mut bool,
) {
//todo: investigate scanning all bundles simultaneously

self.decrypt_transaction_to_record_transparent(transaction, status, block_time)
.await;
self.decrypt_transaction_to_record_transparent(
transaction,
status,
block_time,
sent_to_tex,
)
.await;
self.decrypt_transaction_to_record_sapling(
transaction,
status,
Expand All @@ -190,12 +200,13 @@ mod decrypt_transaction {
transaction: &Transaction,
status: ConfirmationStatus,
block_time: Option<u32>,
sent_to_tex: &mut bool,
) {
// Scan all transparent outputs to see if we received any money
self.account_for_transparent_receipts(transaction, status, block_time)
.await;
// Scan transparent spends
self.account_for_transparent_spending(transaction, status, block_time)
self.account_for_transparent_spending(transaction, status, block_time, sent_to_tex)
.await;
}

Expand Down Expand Up @@ -296,6 +307,7 @@ mod decrypt_transaction {
transaction: &Transaction,
status: ConfirmationStatus,
block_time: Option<u32>,
sent_to_tex: &mut bool,
) {
// Scan all the inputs to see if we spent any transparent funds in this tx
let mut spent_utxos = vec![];
Expand Down Expand Up @@ -323,8 +335,7 @@ mod decrypt_transaction {
if let Some(_rejection_address) =
self.identify_rejection_address(spent_utxo)
{
let _ = t_bundle.vout.iter().map(|vout| vout.recipient_address());
todo!()
*sent_to_tex = true;
}
}
}
Expand Down Expand Up @@ -434,7 +445,7 @@ mod decrypt_transaction {
.await
.transaction_records_by_id;

let transaction_record = tx_map.create_modify_get_transaction_metadata(
let transaction_record = tx_map.create_modify_get_transaction_record(
&transaction.txid(),
status,
block_time,
Expand Down Expand Up @@ -617,8 +628,7 @@ mod decrypt_transaction {
&self,
transaction: &Transaction,
outgoing_metadatas: &mut Vec<OutgoingTxData>,
// if we're sending from t-to-t, the only way zingo
// could have created this transaction is if it's a send to tex.
sent_to_tex: bool,
) {
// TODO: Account for ephemeral_taddresses
// Collect our t-addresses for easy checking
Expand All @@ -636,11 +646,11 @@ mod decrypt_transaction {
if let Some(t_bundle) = transaction.transparent_bundle() {
for vout in &t_bundle.vout {
if let Some(taddr) = vout.recipient_address().map(|raw_taddr| {
match todo!() {
0 => address_from_pubkeyhash(&self.config, raw_taddr),
_nonzero => match raw_taddr{
zcash_primitives::legacy::TransparentAddress::PublicKeyHash(taddr_bytes) => crate::utils::interpret_taddr_as_tex_addr(taddr_bytes, &self.config.chain),
zcash_primitives::legacy::TransparentAddress::ScriptHash(_taddr_bytes) => {
match sent_to_tex {
false => address_from_pubkeyhash(&self.config, raw_taddr),
true=> match raw_taddr{
TransparentAddress::PublicKeyHash(taddr_bytes) => interpret_taddr_as_tex_addr(taddr_bytes, &self.config.chain),
TransparentAddress::ScriptHash(_taddr_bytes) => {
// tex addresses are P2PKH only. If this is a script hash, then we were wrong about
// it being a tex.
todo!("This happens if someone mislabels in a zingomemo, or zingolib logic an address as \"ephemeral\".");},
Expand Down
8 changes: 4 additions & 4 deletions zingolib/src/wallet/transaction_records_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ impl TransactionRecordsById {
}
});
}
pub(crate) fn create_modify_get_transaction_metadata(
pub(crate) fn create_modify_get_transaction_record(
&mut self,
txid: &TxId,
status: ConfirmationStatus,
Expand Down Expand Up @@ -602,7 +602,7 @@ impl TransactionRecordsById {
total_transparent_value_spent: u64,
) {
let transaction_metadata =
self.create_modify_get_transaction_metadata(&txid, status, timestamp);
self.create_modify_get_transaction_record(&txid, status, timestamp);

transaction_metadata.total_transparent_value_spent = total_transparent_value_spent;
}
Expand Down Expand Up @@ -652,7 +652,7 @@ impl TransactionRecordsById {
) {
// Read or create the current TxId
let transaction_metadata =
self.create_modify_get_transaction_metadata(&txid, status, timestamp);
self.create_modify_get_transaction_record(&txid, status, timestamp);

// Add this UTXO if it doesn't already exist
if transaction_metadata
Expand Down Expand Up @@ -691,7 +691,7 @@ impl TransactionRecordsById {
position: incrementalmerkletree::Position,
) {
let transaction_metadata =
self.create_modify_get_transaction_metadata(&txid, status, timestamp);
self.create_modify_get_transaction_record(&txid, status, timestamp);

let nd = D::WalletNote::from_parts(
D::Recipient::diversifier(&to),
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/tx_map/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl super::TxMap {
// Record this Tx as having spent some funds
let transaction_metadata = self
.transaction_records_by_id
.create_modify_get_transaction_metadata(&spending_txid, status, timestamp);
.create_modify_get_transaction_record(&spending_txid, status, timestamp);

if !<D::WalletNote as ShieldedNoteInterface>::Nullifier::get_nullifiers_spent_in_transaction(
transaction_metadata,
Expand Down

0 comments on commit 0f924f1

Please sign in to comment.