miden_client/store/note_record/mod.rs
1//! This module defines common structs to be used within the [`Store`](crate::store::Store) for
2//! notes that are available to be consumed ([`InputNoteRecord`]) and notes that have been produced
3//! as a result of executing a transaction ([`OutputNoteRecord`]).
4//!
5//! Both structs are similar in terms of the data they carry, but are differentiated semantically as
6//! they are involved in very different flows. As such, known states are modeled differently for the
7//! two structures, with [`InputNoteRecord`] having states described by the [`InputNoteState`] enum.
8//!
9//! ## Serialization / Deserialization
10//!
11//! We provide serialization and deserialization support via [`Serializable`] and [`Deserializable`]
12//! traits implementations.
13//!
14//! ## Type conversion
15//!
16//! We also facilitate converting from/into [`InputNote`](miden_protocol::transaction::InputNote) /
17//! [`Note`](miden_protocol::note::Note), although this is not always possible. Check both
18//! [`InputNoteRecord`]'s and [`OutputNoteRecord`]'s documentation for more details about this.
19
20use alloc::string::{String, ToString};
21
22use thiserror::Error;
23
24mod input_note_record;
25mod output_note_record;
26
27pub use input_note_record::{InputNoteRecord, InputNoteState};
28pub use output_note_record::{NoteExportType, OutputNoteRecord, OutputNoteState};
29
30/// Contains structures that model all states in which an input note can be.
31pub mod input_note_states {
32 pub use super::input_note_record::{
33 CommittedNoteState,
34 ConsumedAuthenticatedLocalNoteState,
35 ConsumedExternalNoteState,
36 ConsumedUnauthenticatedLocalNoteState,
37 ExpectedNoteState,
38 InputNoteState,
39 InvalidNoteState,
40 NoteSubmissionData,
41 ProcessingAuthenticatedNoteState,
42 ProcessingUnauthenticatedNoteState,
43 UnverifiedNoteState,
44 };
45}
46
47// NOTE RECORD ERROR
48// ================================================================================================
49
50/// Errors generated from note records.
51#[derive(Debug, Error)]
52pub enum NoteRecordError {
53 /// Error generated during conversion of note record.
54 #[error("note record conversion error: {0}")]
55 ConversionError(String),
56 /// Note record isn't consumable.
57 #[error("note not consumable: {0}")]
58 NoteNotConsumable(String),
59 /// Invalid state transition.
60 #[error("invalid state transition: {0}")]
61 InvalidStateTransition(String),
62 /// Error generated during a state transition.
63 #[error("state transition error: {0}")]
64 StateTransitionError(String),
65}
66
67impl From<NoteRecordError> for String {
68 fn from(err: NoteRecordError) -> String {
69 err.to_string()
70 }
71}