Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Enhancements

- [BREAKING] Updated miden-base dependencies to use `next` branch; renamed `NoteInputs` to `NoteStorage`, `.inputs()` to `.storage()`, and database `inputs` column to `storage` ([#1595](https://github.com/0xMiden/miden-node/pull/1595)).
### Changes

- Changed `note_type` field in proto `NoteMetadata` from `uint32` to a `NoteType` enum ([#1594](https://github.com/0xMiden/miden-node/pull/1594)).

## v0.13.3 (2026-01-29)

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions crates/proto/src/domain/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ use super::account::NetworkAccountId;
use crate::errors::{ConversionError, MissingFieldHelper};
use crate::generated as proto;

// NOTE TYPE
// ================================================================================================

impl From<NoteType> for proto::note::NoteType {
fn from(note_type: NoteType) -> Self {
match note_type {
NoteType::Public => proto::note::NoteType::Public,
NoteType::Private => proto::note::NoteType::Private,
}
}
}

impl TryFrom<proto::note::NoteType> for NoteType {
type Error = ConversionError;

fn try_from(note_type: proto::note::NoteType) -> Result<Self, Self::Error> {
match note_type {
proto::note::NoteType::Public => Ok(NoteType::Public),
proto::note::NoteType::Private => Ok(NoteType::Private),
proto::note::NoteType::Unspecified => Err(ConversionError::EnumDiscriminantOutOfRange),
}
}
}

// NOTE METADATA
// ================================================================================================

impl TryFrom<proto::note::NoteMetadata> for NoteMetadata {
type Error = ConversionError;

Expand All @@ -31,7 +58,9 @@ impl TryFrom<proto::note::NoteMetadata> for NoteMetadata {
.sender
.ok_or_else(|| proto::note::NoteMetadata::missing_field(stringify!(sender)))?
.try_into()?;
let note_type = NoteType::try_from(u64::from(value.note_type))?;
let note_type = proto::note::NoteType::try_from(value.note_type)
.map_err(|_| ConversionError::EnumDiscriminantOutOfRange)?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this required? Seems like its mapping from E -> E?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This try_from is implemented by prost, is the casting from the i32 to an Enum variant and returns a custom error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Man that's so weird. What's even the point of the enum if they never actually use it in the code..

.try_into()?;
let tag = NoteTag::new(value.tag);

// Deserialize attachment if present
Expand Down Expand Up @@ -77,7 +106,7 @@ impl From<NetworkNote> for proto::note::NetworkNote {
impl From<NoteMetadata> for proto::note::NoteMetadata {
fn from(val: NoteMetadata) -> Self {
let sender = Some(val.sender().into());
let note_type = val.note_type() as u32;
let note_type = proto::note::NoteType::from(val.note_type()) as i32;
let tag = val.tag().as_u32();
let attachment = val.attachment().to_bytes();

Expand Down
39 changes: 36 additions & 3 deletions crates/proto/src/generated/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct NoteMetadata {
/// The account which sent the note.
#[prost(message, optional, tag = "1")]
pub sender: ::core::option::Option<super::account::AccountId>,
/// The type of the note (0b01 = public, 0b10 = private, 0b11 = encrypted).
#[prost(uint32, tag = "2")]
pub note_type: u32,
/// The type of the note.
#[prost(enumeration = "NoteType", tag = "2")]
pub note_type: i32,
/// A value which can be used by the recipient(s) to identify notes intended for them.
///
/// See `miden_protocol::note::note_tag` for more info.
Expand Down Expand Up @@ -128,3 +128,36 @@ pub struct NoteScript {
#[prost(bytes = "vec", tag = "2")]
pub mast: ::prost::alloc::vec::Vec<u8>,
}
/// The type of a note.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum NoteType {
/// Unspecified note type (default value, should not be used).
Unspecified = 0,
/// Public note - details are visible on-chain.
Public = 1,
/// Private note - details are not visible on-chain.
Private = 2,
}
impl NoteType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "NOTE_TYPE_UNSPECIFIED",
Self::Public => "NOTE_TYPE_PUBLIC",
Self::Private => "NOTE_TYPE_PRIVATE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"NOTE_TYPE_UNSPECIFIED" => Some(Self::Unspecified),
"NOTE_TYPE_PUBLIC" => Some(Self::Public),
"NOTE_TYPE_PRIVATE" => Some(Self::Private),
_ => None,
}
}
}
14 changes: 12 additions & 2 deletions proto/proto/types/note.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import "types/account.proto";
// NOTES
// ================================================================================================

// The type of a note.
enum NoteType {
// Unspecified note type (default value, should not be used).
NOTE_TYPE_UNSPECIFIED = 0;
// Public note - details are visible on-chain.
NOTE_TYPE_PUBLIC = 1;
// Private note - details are not visible on-chain.
NOTE_TYPE_PRIVATE = 2;
}

// Represents a note's ID.
message NoteId {
// A unique identifier of the note which is a 32-byte commitment to the underlying note data.
Expand All @@ -24,8 +34,8 @@ message NoteMetadata {
// The account which sent the note.
account.AccountId sender = 1;

// The type of the note (0b01 = public, 0b10 = private, 0b11 = encrypted).
uint32 note_type = 2;
// The type of the note.
NoteType note_type = 2;

// A value which can be used by the recipient(s) to identify notes intended for them.
//
Expand Down