Skip to content

Commit

Permalink
moved update_output_index to transaction_record
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidvanadium committed Aug 30, 2024
1 parent 7525d65 commit 60dfc8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 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 @@ -461,16 +461,11 @@ mod decrypt_transaction {
block_time,
);

// 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() {
transaction_record.add_pending_note::<D>(note.clone(), to, output_index);
} else {
let _todo_error_stack = tx_map.update_output_index::<D>(
transaction.txid(),
note.clone(),
output_index,
);
let _note_does_not_exist_result =
transaction_record.update_output_index::<D>(note.clone(), output_index);
}

let memo = memo_bytes
Expand Down
21 changes: 20 additions & 1 deletion zingolib/src/wallet/transaction_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ impl TransactionRecord {
}
}
}

/// 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,
Expand Down Expand Up @@ -144,6 +144,25 @@ impl TransactionRecord {
Some(_) => {}
}
}

/// returns Err(()) if note does not exist
pub(crate) fn update_output_index<D: DomainWalletExt>(
&mut self,
note: D::Note,
output_index: usize,
) -> Result<(), ()> {
if let Some(n) = D::WalletNote::transaction_metadata_notes_mut(self)
.iter_mut()
.find(|n| n.note() == &note)
{
if n.output_index().is_none() {
*n.output_index_mut() = Some(output_index as u32)
}
Ok(())
} else {
Err(())
}
}
}
//get
impl TransactionRecord {
Expand Down
23 changes: 0 additions & 23 deletions zingolib/src/wallet/transaction_records_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,29 +587,6 @@ impl TransactionRecordsById {
}
}

/// returns Err(()) if transaction or note does not exist
pub(crate) fn update_output_index<D: DomainWalletExt>(
&mut self,
txid: TxId,
note: D::Note,
output_index: usize,
) -> Result<(), ()> {
let has_transaction = self.get_mut(&txid);
let transaction_record = has_transaction.ok_or(())?;

if let Some(n) = D::WalletNote::transaction_metadata_notes_mut(transaction_record)
.iter_mut()
.find(|n| n.note() == &note)
{
if n.output_index().is_none() {
*n.output_index_mut() = Some(output_index as u32)
}
Ok(())
} else {
Err(())
}
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn add_new_note<D: DomainWalletExt>(
&mut self,
Expand Down

0 comments on commit 60dfc8d

Please sign in to comment.