From f39d867e6d2d7341c1d623ce412a316263a825b8 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Fri, 30 Aug 2024 02:13:45 +0000 Subject: [PATCH] moved update_output_index to transaction_record --- zingolib/src/wallet/transaction_context.rs | 9 ++------ zingolib/src/wallet/transaction_record.rs | 21 ++++++++++++++++- .../src/wallet/transaction_records_by_id.rs | 23 ------------------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/zingolib/src/wallet/transaction_context.rs b/zingolib/src/wallet/transaction_context.rs index 3b31b2dd8..f8100ed86 100644 --- a/zingolib/src/wallet/transaction_context.rs +++ b/zingolib/src/wallet/transaction_context.rs @@ -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::(note.clone(), to, output_index); } else { - let _todo_error_stack = tx_map.update_output_index::( - transaction.txid(), - note.clone(), - output_index, - ); + let _note_does_not_exist_result = + transaction_record.update_output_index::(note.clone(), output_index); } let memo = memo_bytes diff --git a/zingolib/src/wallet/transaction_record.rs b/zingolib/src/wallet/transaction_record.rs index 79f674a72..735b45543 100644 --- a/zingolib/src/wallet/transaction_record.rs +++ b/zingolib/src/wallet/transaction_record.rs @@ -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( &mut self, note: D::Note, @@ -144,6 +144,25 @@ impl TransactionRecord { Some(_) => {} } } + + /// returns Err(()) if note does not exist + pub(crate) fn update_output_index( + &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() == ¬e) + { + if n.output_index().is_none() { + *n.output_index_mut() = Some(output_index as u32) + } + Ok(()) + } else { + Err(()) + } + } } //get impl TransactionRecord { diff --git a/zingolib/src/wallet/transaction_records_by_id.rs b/zingolib/src/wallet/transaction_records_by_id.rs index 0e2452f21..edbe1c584 100644 --- a/zingolib/src/wallet/transaction_records_by_id.rs +++ b/zingolib/src/wallet/transaction_records_by_id.rs @@ -587,29 +587,6 @@ impl TransactionRecordsById { } } - /// returns Err(()) if transaction or note does not exist - pub(crate) fn update_output_index( - &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() == ¬e) - { - 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( &mut self,