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,
36 ConsumedAuthenticatedLocalNoteState,
37 ExpectedNoteState,
38 InputNoteState,
39 InvalidNoteState,
40 ProcessingAuthenticatedNoteState,
41 ProcessingUnauthenticatedNoteState,
42 UnverifiedNoteState,
43 };
44}
45
46// NOTE RECORD ERROR
47// ================================================================================================
48
49/// Errors generated from note records.
50#[derive(Debug, Error)]
51pub enum NoteRecordError {
52 /// Error generated during conversion of note record.
53 #[error("note record conversion error: {0}")]
54 ConversionError(String),
55 /// Invalid underlying note object.
56 #[error("note error")]
57 NoteError(#[from] NoteError),
58 /// Note record isn't consumable.
59 #[error("note not consumable: {0}")]
60 NoteNotConsumable(String),
61 /// Invalid inclusion proof.
62 #[error("invalid inclusion proof")]
63 InvalidInclusionProof,
64 /// Invalid state transition.
65 #[error("invalid state transition: {0}")]
66 InvalidStateTransition(String),
67 /// Error generated during a state transition.
68 #[error("state transition error: {0}")]
69 StateTransitionError(String),
70}
71
72impl From<NoteRecordError> for String {
73 fn from(err: NoteRecordError) -> String {
74 err.to_string()
75 }
76}