Skip to main content

miden_standards/account/wallets/
note_creator.rs

1use miden_protocol::account::component::{AccountComponentCode, AccountComponentMetadata};
2use miden_protocol::account::{AccountComponent, AccountComponentName, AccountProcedureRoot};
3
4use crate::account::account_component_code;
5use crate::procedure_root;
6
7// NOTE CREATOR
8// ================================================================================================
9
10account_component_code!(NOTE_CREATOR_CODE, "miden-standards-wallets-note-creator.masp");
11
12// Initialize the procedure root of the `create_note` procedure of the Note Creator only once.
13procedure_root!(
14    NOTE_CREATOR_CREATE_NOTE,
15    NoteCreator::NAME,
16    NoteCreator::CREATE_NOTE_PROC_NAME,
17    NoteCreator::code()
18);
19
20/// An [`AccountComponent`] exposing only the `create_note` procedure.
21///
22/// When linking against this component, the `miden` library (i.e.
23/// [`ProtocolLib`](miden_protocol::ProtocolLib)) must be available to the assembler which is the
24/// case when using [`CodeBuilder`][builder].
25///
26/// `create_note` requires authentication. Thus, this component must be combined with a component
27/// providing authentication.
28///
29/// [builder]: crate::code_builder::CodeBuilder
30pub struct NoteCreator;
31
32impl NoteCreator {
33    // CONSTANTS
34    // --------------------------------------------------------------------------------------------
35
36    /// The name of the component.
37    pub const NAME: &'static str = "miden::standards::components::note::note_creator";
38
39    const CREATE_NOTE_PROC_NAME: &str = "create_note";
40
41    /// Returns the canonical [`AccountComponentName`] of this component.
42    pub const fn name() -> AccountComponentName {
43        AccountComponentName::from_static_str(Self::NAME)
44    }
45
46    // PUBLIC ACCESSORS
47    // --------------------------------------------------------------------------------------------
48
49    /// Returns the [`AccountComponentCode`] of this component.
50    pub fn code() -> &'static AccountComponentCode {
51        &NOTE_CREATOR_CODE
52    }
53
54    /// Returns the procedure root of the `create_note` procedure.
55    pub fn create_note_root() -> AccountProcedureRoot {
56        *NOTE_CREATOR_CREATE_NOTE
57    }
58
59    /// Returns the [`AccountComponentMetadata`] for this component.
60    pub fn component_metadata() -> AccountComponentMetadata {
61        AccountComponentMetadata::new(Self::NAME)
62            .with_description("Note creator component exposing only the create_note procedure")
63    }
64}
65
66impl From<NoteCreator> for AccountComponent {
67    fn from(_: NoteCreator) -> Self {
68        let metadata = NoteCreator::component_metadata();
69
70        AccountComponent::new(NoteCreator::code().clone(), vec![], metadata).expect(
71            "note creator component should satisfy the requirements of a valid account component",
72        )
73    }
74}