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
6//! as they are involved in very different flows. As such, known states are modeled differently for
7//! the two structures, with [`InputNoteRecord`] having states described by the [`InputNoteState`]
8//! enum.
9//!
10//! ## Serialization / Deserialization
11//!
12//! We provide serialization and deserialization support via [`Serializable`] and [`Deserializable`]
13//! traits implementations.
14//!
15//! ## Type conversion
16//!
17//! We also facilitate converting from/into [`InputNote`](miden_objects::transaction::InputNote) /
18//! [`Note`](miden_objects::note::Note), although this is not always possible. Check both
19//! [`InputNoteRecord`]'s and [`OutputNoteRecord`]'s documentation for more details about this.
20
21use alloc::string::{String, ToString};
22
23use miden_objects::NoteError;
24use thiserror::Error;
25
26mod input_note_record;
27mod output_note_record;
28
29pub use input_note_record::{InputNoteRecord, InputNoteState};
30pub use output_note_record::{NoteExportType, OutputNoteRecord, OutputNoteState};
31
32/// Contains structures that model all states in which an input note can be.
33pub mod input_note_states {
34 pub use super::input_note_record::{
35 CommittedNoteState, ConsumedAuthenticatedLocalNoteState, ExpectedNoteState, InputNoteState,
36 InvalidNoteState, ProcessingAuthenticatedNoteState, ProcessingUnauthenticatedNoteState,
37 UnverifiedNoteState,
38 };
39}
40
41// NOTE RECORD ERROR
42// ================================================================================================
43
44/// Errors generated from note records.
45#[derive(Debug, Error)]
46pub enum NoteRecordError {
47 /// Error generated during conversion of note record.
48 #[error("note record conversion error: {0}")]
49 ConversionError(String),
50 /// Invalid underlying note object.
51 #[error("note error")]
52 NoteError(#[from] NoteError),
53 /// Note record isn't consumable.
54 #[error("note not consumable: {0}")]
55 NoteNotConsumable(String),
56 /// Invalid inclusion proof.
57 #[error("invalid inclusion proof")]
58 InvalidInclusionProof,
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}