miden_client/transaction/
store_update.rs

1use alloc::vec::Vec;
2
3use miden_objects::block::BlockNumber;
4use miden_objects::note::{NoteDetails, NoteTag};
5use miden_objects::transaction::ExecutedTransaction;
6use miden_tx::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
7
8use crate::note::NoteUpdateTracker;
9use crate::sync::NoteTagRecord;
10
11// TRANSACTION STORE UPDATE
12// ================================================================================================
13
14/// Represents the changes that need to be applied to the client store as a result of a
15/// transaction execution.
16#[derive(Debug, Clone)]
17pub struct TransactionStoreUpdate {
18    /// Details of the executed transaction to be inserted.
19    executed_transaction: ExecutedTransaction,
20    /// Block number at which the transaction was submitted.
21    submission_height: BlockNumber,
22    /// Future notes that are expected to be created as a result of the transaction.
23    future_notes: Vec<(NoteDetails, NoteTag)>,
24    /// Information about note changes after the transaction execution.
25    note_updates: NoteUpdateTracker,
26    /// New note tags to be tracked.
27    new_tags: Vec<NoteTagRecord>,
28}
29
30impl TransactionStoreUpdate {
31    /// Creates a new [`TransactionStoreUpdate`] instance populated with all relevant note data.
32    ///
33    /// # Arguments
34    /// - `executed_transaction`: The executed transaction details.
35    /// - `submission_height`: The block number at which the transaction was submitted.
36    /// - `note_updates`: The note updates that need to be applied to the store after the
37    ///   transaction execution.
38    /// - `future_notes`: Notes expected to be received in follow-up transactions (e.g. swap
39    ///   paybacks).
40    /// - `new_tags`: New note tags that need to be tracked because of created notes.
41    pub fn new(
42        executed_transaction: ExecutedTransaction,
43        submission_height: BlockNumber,
44        note_updates: NoteUpdateTracker,
45        future_notes: Vec<(NoteDetails, NoteTag)>,
46        new_tags: Vec<NoteTagRecord>,
47    ) -> Self {
48        Self {
49            executed_transaction,
50            submission_height,
51            future_notes,
52            note_updates,
53            new_tags,
54        }
55    }
56    /// Returns the executed transaction.
57    pub fn executed_transaction(&self) -> &ExecutedTransaction {
58        &self.executed_transaction
59    }
60
61    /// Returns the block number at which the transaction was submitted.
62    pub fn submission_height(&self) -> BlockNumber {
63        self.submission_height
64    }
65
66    /// Returns the future notes that should be tracked as a result of the transaction.
67    pub fn future_notes(&self) -> &[(NoteDetails, NoteTag)] {
68        &self.future_notes
69    }
70
71    /// Returns the note updates that need to be applied after the transaction execution.
72    pub fn note_updates(&self) -> &NoteUpdateTracker {
73        &self.note_updates
74    }
75
76    /// Returns the new tags that were created as part of the transaction.
77    pub fn new_tags(&self) -> &[NoteTagRecord] {
78        &self.new_tags
79    }
80}
81
82impl Serializable for TransactionStoreUpdate {
83    fn write_into<W: ByteWriter>(&self, target: &mut W) {
84        self.executed_transaction.write_into(target);
85        self.submission_height.write_into(target);
86        self.future_notes.write_into(target);
87    }
88}
89
90impl Deserializable for TransactionStoreUpdate {
91    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
92        let executed_transaction = ExecutedTransaction::read_from(source)?;
93        let submission_height = BlockNumber::read_from(source)?;
94        let future_notes = Vec::<(NoteDetails, NoteTag)>::read_from(source)?;
95
96        Ok(Self {
97            executed_transaction,
98            submission_height,
99            future_notes,
100            note_updates: NoteUpdateTracker::default(),
101            new_tags: Vec::new(),
102        })
103    }
104}