Skip to content

Commit

Permalink
moved add_pending_note to transaction_record
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidvanadium committed Aug 30, 2024
1 parent 1b096c8 commit 85e5294
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
9 changes: 2 additions & 7 deletions zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,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_metadata(
&transaction.txid(),
status,
block_time,
Expand All @@ -464,12 +464,7 @@ mod decrypt_transaction {
// now that the transaction exists, add_pending_note or update_output_index will succeed _todo_error_stack is not to be handled.

if status.is_pending() {
let _todo_error_stack = tx_map.add_pending_note::<D>(
transaction.txid(),
note.clone(),
to,
output_index,
);
transaction_record.add_pending_note::<D>(note.clone(), to, output_index);
} else {
let _todo_error_stack = tx_map.update_output_index::<D>(
transaction.txid(),
Expand Down
35 changes: 34 additions & 1 deletion zingolib/src/wallet/transaction_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use zcash_client_backend::{
};
use zcash_primitives::{consensus::BlockHeight, transaction::TxId};

use crate::wallet::traits::Recipient as _;
use crate::{
error::ZingoLibError,
wallet::{
Expand Down Expand Up @@ -72,6 +73,8 @@ pub struct TransactionRecord {
pub price: Option<f64>,
}

// much data assignment of this struct is done through the pub fields as of january 2024. Todo: should have private fields and public methods.

// set
impl TransactionRecord {
/// TODO: Add Doc Comment Here!
Expand Down Expand Up @@ -110,7 +113,37 @@ impl TransactionRecord {
}
}
}
// much data assignment of this struct is done through the pub fields as of january 2024. Todo: should have private fields and public methods.
/// adds a note. however, does not fully commit to adding a note, because this note isnt chained into block
/// if the transaction is not already recorded, return Err(())
pub(crate) fn add_pending_note<D: DomainWalletExt>(
&mut self,
note: D::Note,
to: D::Recipient,
output_index: usize,
) {
match D::WalletNote::get_record_outputs(self)
.iter_mut()
.find(|n| n.note() == &note)
{
None => {
let nd = D::WalletNote::from_parts(
to.diversifier(),
note,
None,
None,
None,
None,
// if this is change, we'll mark it later in check_notes_mark_change
false,
false,
Some(output_index as u32),
);

D::WalletNote::transaction_metadata_notes_mut(self).push(nd);
}
Some(_) => {}
}
}
}
//get
impl TransactionRecord {
Expand Down
36 changes: 0 additions & 36 deletions zingolib/src/wallet/transaction_records_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,42 +610,6 @@ impl TransactionRecordsById {
}
}

/// adds a note. however, does not fully commit to adding a note, because this note isnt chained into block
/// if the transaction is not already recorded, return Err(())
pub(crate) fn add_pending_note<D: DomainWalletExt>(
&mut self,
txid: TxId,
note: D::Note,
to: D::Recipient,
output_index: usize,
) -> Result<(), ()> {
let has_transaction = self.get_mut(&txid);
let transaction_record = has_transaction.ok_or(())?;

match D::WalletNote::get_record_outputs(transaction_record)
.iter_mut()
.find(|n| n.note() == &note)
{
None => {
let nd = D::WalletNote::from_parts(
to.diversifier(),
note,
None,
None,
None,
None,
// if this is change, we'll mark it later in check_notes_mark_change
false,
false,
Some(output_index as u32),
);

D::WalletNote::transaction_metadata_notes_mut(transaction_record).push(nd);
}
Some(_) => {}
}
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn add_new_note<D: DomainWalletExt>(
&mut self,
Expand Down

0 comments on commit 85e5294

Please sign in to comment.