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 miden_protocol::errors::NoteError;
23use thiserror::Error;
24
25mod input_note_record;
26mod output_note_record;
27
28pub use input_note_record::{InputNoteRecord, InputNoteState};
29pub use output_note_record::{NoteExportType, OutputNoteRecord, OutputNoteState};
30
31/// Contains structures that model all states in which an input note can be.
32pub mod input_note_states {
33 pub use super::input_note_record::{
34 CommittedNoteState,
35 ConsumedAuthenticatedLocalNoteState,
36 ConsumedExternalNoteState,
37 ConsumedUnauthenticatedLocalNoteState,
38 ExpectedNoteState,
39 InputNoteState,
40 InvalidNoteState,
41 NoteSubmissionData,
42 ProcessingAuthenticatedNoteState,
43 ProcessingUnauthenticatedNoteState,
44 UnverifiedNoteState,
45 };
46}
47
48// NOTE RECORD ERROR
49// ================================================================================================
50
51/// Errors generated from note records.
52#[derive(Debug, Error)]
53pub enum NoteRecordError {
54 /// Error generated during conversion of note record.
55 #[error("note record conversion error: {0}")]
56 ConversionError(String),
57 /// Invalid underlying note object.
58 #[error("note error")]
59 NoteError(#[from] NoteError),
60 /// Note record isn't consumable.
61 #[error("note not consumable: {0}")]
62 NoteNotConsumable(String),
63 /// Invalid state transition.
64 #[error("invalid state transition: {0}")]
65 InvalidStateTransition(String),
66 /// Error generated during a state transition.
67 #[error("state transition error: {0}")]
68 StateTransitionError(String),
69}
70
71impl From<NoteRecordError> for String {
72 fn from(err: NoteRecordError) -> String {
73 err.to_string()
74 }
75}