Skip to content

feat: add StandardNote constructor from note script#2411

Merged
bobbinth merged 5 commits intonextfrom
tomasarrachea-standarnote-from-script
Feb 6, 2026
Merged

feat: add StandardNote constructor from note script#2411
bobbinth merged 5 commits intonextfrom
tomasarrachea-standarnote-from-script

Conversation

@TomasArrachea
Copy link
Copy Markdown
Collaborator

This PR:

  • Adds StandardNote::from_script_root(root: Word) to identify standard notes directly from a script root, and refactors from_note to delegate to it
  • Adds StandardNote::name(&self) to return the variant name as a string
  • Makes NoteType masks (PUBLIC, PRIVATE) public and re-exports them from miden_protocol::note

Copy link
Copy Markdown
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Left a few small comments.

Comment on lines +18 to +19
pub const PUBLIC: u8 = 0b01;
pub const PRIVATE: u8 = 0b10;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these associated constants, e.g. NoteType::PUBLIC? I think this is more readable than free-floating constants.

Comment on lines 54 to 56
/// Returns a [`StandardNote`] instance based on the note script of the provided [`Note`].
/// Returns `None` if the provided note is not a standard note.
pub fn from_note(note: &Note) -> Option<Self> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove from_note and replace it with from_script_root, or maybe have from_script(&NoteScript) additionally for more type safety. Semantically, we're not converting a full Note into a StandardNote, only its script root / note script, and so passing the full Note is unnecessarily restrictive, which basically prompted this PR. May be easy to do in this PR, but if not, can also be done separately.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in abb2696

Comment on lines +85 to +86
/// Returns the name of this [`StandardNote`] variant as a string.
pub fn name(&self) -> String {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the name of this [`StandardNote`] variant as a string.
pub fn name(&self) -> String {
/// Returns the name of this [`StandardNote`] variant as a string.
pub fn name(&self) -> &'static str {

Nit: I think we should be able to always return a reference to a string and avoid the extra allocation.

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@bobbinth bobbinth merged commit c9ff360 into next Feb 6, 2026
17 checks passed
@bobbinth bobbinth deleted the tomasarrachea-standarnote-from-script branch February 6, 2026 19:41
afa7789 pushed a commit to afa7789/miden-base that referenced this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants