use alloc::vec::Vec;
use miden_protocol::block::BlockNumber;
use miden_protocol::note::{NoteDetails, NoteTag};
use miden_protocol::transaction::ExecutedTransaction;
use miden_tx::utils::serde::{
ByteReader,
ByteWriter,
Deserializable,
DeserializationError,
Serializable,
};
use crate::note::NoteUpdateTracker;
use crate::sync::NoteTagRecord;
#[derive(Debug, Clone)]
pub struct TransactionStoreUpdate {
executed_transaction: ExecutedTransaction,
submission_height: BlockNumber,
future_notes: Vec<(NoteDetails, NoteTag)>,
note_updates: NoteUpdateTracker,
new_tags: Vec<NoteTagRecord>,
}
impl TransactionStoreUpdate {
pub fn new(
executed_transaction: ExecutedTransaction,
submission_height: BlockNumber,
note_updates: NoteUpdateTracker,
future_notes: Vec<(NoteDetails, NoteTag)>,
new_tags: Vec<NoteTagRecord>,
) -> Self {
Self {
executed_transaction,
submission_height,
future_notes,
note_updates,
new_tags,
}
}
pub fn executed_transaction(&self) -> &ExecutedTransaction {
&self.executed_transaction
}
pub fn submission_height(&self) -> BlockNumber {
self.submission_height
}
pub fn future_notes(&self) -> &[(NoteDetails, NoteTag)] {
&self.future_notes
}
pub fn note_updates(&self) -> &NoteUpdateTracker {
&self.note_updates
}
pub fn new_tags(&self) -> &[NoteTagRecord] {
&self.new_tags
}
}
impl Serializable for TransactionStoreUpdate {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.executed_transaction.write_into(target);
self.submission_height.write_into(target);
self.future_notes.write_into(target);
}
}
impl Deserializable for TransactionStoreUpdate {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let executed_transaction = ExecutedTransaction::read_from(source)?;
let submission_height = BlockNumber::read_from(source)?;
let future_notes = Vec::<(NoteDetails, NoteTag)>::read_from(source)?;
Ok(Self {
executed_transaction,
submission_height,
future_notes,
note_updates: NoteUpdateTracker::default(),
new_tags: Vec::new(),
})
}
}