Skip to content

Simplify NoteMetadata constructor by making tag optional#2384

Merged
mmagician merged 6 commits intonextfrom
copilot/change-notemetadata-constructor
Feb 2, 2026
Merged

Simplify NoteMetadata constructor by making tag optional#2384
mmagician merged 6 commits intonextfrom
copilot/change-notemetadata-constructor

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Summary

This PR implements the change requested in issue #2334 to modify the NoteMetadata constructor API to use a builder pattern.

Changes Made

Constructor Modification

  • Modified NoteMetadata::new() to only take sender: AccountId and note_type: NoteType parameters
  • The tag now defaults to NoteTag::default() (which is 0)
  • This makes the API cleaner and more intuitive for common use cases where a tag is not needed

New Builder Methods

  • Added with_tag() builder method to set a custom tag when needed
  • Added set_tag() mutator method for setting tags on existing instances
  • Improved documentation to clarify the difference between builder and mutator methods

API Usage Comparison

Before:

let metadata = NoteMetadata::new(sender_id, NoteType::Public, tag);

After:

// Without custom tag (uses default)
let metadata = NoteMetadata::new(sender_id, NoteType::Public);

// With custom tag
let metadata = NoteMetadata::new(sender_id, NoteType::Public)
    .with_tag(tag)
    .with_attachment(attachment);

Updated Call Sites

Updated ~40 call sites across all crates:

  • ✅ miden-protocol (4 instances)
  • ✅ miden-testing (19 instances)
  • ✅ miden-standards (10 instances)
  • ✅ miden-tx (1 instance)
  • ✅ miden-agglayer (1 instance)

Testing

Security Summary

This change is a pure refactoring that maintains the same behavior but with a cleaner API. No security vulnerabilities were introduced:

  • The default tag value (0) is the same as before when tags weren't being used
  • All existing functionality is preserved
  • The change is backwards compatible at the binary level (serialization/deserialization unchanged)
Original prompt

This section details on the original issue you should resolve

<issue_title>Change the NoteMetadata constructor not to take the tag by default</issue_title>
<issue_description>Also, maybe we should change the NoteMetadata constructor not to take the tag by default. This way, we'd just do:

let metadata = NoteMetadata::new(sender_account_id, NoteType::Public)
    .with_attachment(attachment);

And in cases when the tag is required, we'd do:

let metadata = NoteMetadata::new(sender_account_id, NoteType::Public)
    .with_tag(tag)
    .with_attachment(attachment);

Originally posted by @bobbinth in #2334 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Change NoteMetadata constructor to avoid default tag Simplify NoteMetadata constructor by making tag optional Feb 1, 2026
Copilot AI requested a review from mmagician February 1, 2026 21:35
Copy link
Collaborator

@mmagician mmagician left a comment

Choose a reason for hiding this comment

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

lgtm

@mmagician
Copy link
Collaborator

@copilot add changelog entry, the PR number is 2384

@mmagician mmagician marked this pull request as ready for review February 1, 2026 22:00
Copilot AI added a commit that referenced this pull request Feb 1, 2026
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 1, 2026

@copilot add changelog entry, the PR number is 2384

Added changelog entry in commit 12a8f8f.

Copilot AI requested a review from mmagician February 1, 2026 22:02
@mmagician mmagician changed the title Simplify NoteMetadata constructor by making tag optional Simplify NoteMetadata constructor by making tag optional Feb 1, 2026
@mmagician mmagician requested a review from bobbinth February 1, 2026 22:06
Copilot AI and others added 5 commits February 1, 2026 22:42
Changed from NoteMetadata::new(sender, note_type, tag) to NoteMetadata::new(sender, note_type).with_tag(tag) across all files in the miden-testing crate.

Updated files:
- tests/agglayer/bridge_out.rs (2 occurrences)
- tests/agglayer/bridge_in.rs (1 occurrence)
- tests/scripts/faucet.rs (2 occurrences)
- tests/scripts/send_note.rs (2 occurrences)
- tests/scripts/swap.rs (1 occurrence)
- tests/lib.rs (1 occurrence)
- src/kernel_tests/tx/test_output_note.rs (3 occurrences)
- src/kernel_tests/tx/test_tx.rs (2 occurrences)
- src/kernel_tests/tx/test_account_interface.rs (1 occurrence)
- src/kernel_tests/tx/test_note.rs (2 occurrences)
- src/kernel_tests/tx/test_active_note.rs (1 occurrence)
- src/standards/network_account_target.rs (1 occurrence)
- Modified NoteMetadata::new() to only take sender and note_type
- Added with_tag() method for setting tag explicitly
- Updated all call sites across protocol, testing, standards, tx, and agglayer crates
- Tag now defaults to NoteTag::default() if not explicitly set

Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
@mmagician mmagician force-pushed the copilot/change-notemetadata-constructor branch from 12a8f8f to 9de85f1 Compare February 1, 2026 22:42
@mmagician mmagician merged commit e7366b0 into next Feb 2, 2026
17 checks passed
@mmagician mmagician deleted the copilot/change-notemetadata-constructor branch February 2, 2026 12:43
Comment on lines +167 to +170
pub fn with_tag(mut self, tag: NoteTag) -> Self {
self.tag = tag;
self
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would have maybe changed the parameter type to something like Into<NoteTag>. This way, we'd be able to call this method with anything that can be trivially converted into a NoteTag (would make testing code a bit easier).

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.

Change the NoteMetadata constructor not to take the tag by default

4 participants