miden_testing/mock_chain/
note.rs

1use miden_objects::{
2    NoteError,
3    note::{Note, NoteId, NoteInclusionProof, NoteMetadata, NoteType},
4    transaction::InputNote,
5};
6
7// MOCK CHAIN NOTE
8// ================================================================================================
9
10/// Represents a note that is stored in the mock chain.
11#[allow(clippy::large_enum_variant)]
12#[derive(Debug, Clone)]
13pub enum MockChainNote {
14    /// Details for a private note only include its [`NoteMetadata`] and [`NoteInclusionProof`].
15    /// Other details needed to consume the note are expected to be stored locally, off-chain.
16    Private(NoteId, NoteMetadata, NoteInclusionProof),
17    /// Contains the full [`Note`] object alongside its [`NoteInclusionProof`].
18    Public(Note, NoteInclusionProof),
19}
20
21impl MockChainNote {
22    /// Returns the note's inclusion details.
23    pub fn inclusion_proof(&self) -> &NoteInclusionProof {
24        match self {
25            MockChainNote::Private(_, _, inclusion_proof)
26            | MockChainNote::Public(_, inclusion_proof) => inclusion_proof,
27        }
28    }
29
30    /// Returns the note's metadata.
31    pub fn metadata(&self) -> &NoteMetadata {
32        match self {
33            MockChainNote::Private(_, metadata, _) => metadata,
34            MockChainNote::Public(note, _) => note.metadata(),
35        }
36    }
37
38    /// Returns the note's ID.
39    pub fn id(&self) -> NoteId {
40        match self {
41            MockChainNote::Private(id, ..) => *id,
42            MockChainNote::Public(note, _) => note.id(),
43        }
44    }
45
46    /// Returns the underlying note if it is public.
47    pub fn note(&self) -> Option<&Note> {
48        match self {
49            MockChainNote::Private(..) => None,
50            MockChainNote::Public(note, _) => Some(note),
51        }
52    }
53}
54
55impl TryFrom<MockChainNote> for InputNote {
56    type Error = NoteError;
57
58    fn try_from(value: MockChainNote) -> Result<Self, Self::Error> {
59        match value {
60            MockChainNote::Private(..) => {
61                Err(NoteError::PublicUseCaseRequiresPublicNote(NoteType::Private))
62            },
63            MockChainNote::Public(note, proof) => Ok(InputNote::Authenticated { note, proof }),
64        }
65    }
66}