diff --git a/CHANGELOG.md b/CHANGELOG.md index 5920efa1a6..72d0b993a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Removed redundant note storage item count from advice map ([#2376](https://github.com/0xMiden/miden-base/pull/2376)). - [BREAKING] Prefixed transaction kernel events with `miden::protocol` ([#2364](https://github.com/0xMiden/miden-base/pull/2364)). +- [BREAKING] Simplified `NoteMetadata::new()` constructor to not require tag parameter; tag defaults to zero and can be set via `with_tag()` builder method ([#2384](https://github.com/0xMiden/miden-base/pull/2384)). - [BREAKING] Renamed `WellKnownComponent` to `StandardAccountComponent`, `WellKnownNote` to `StandardNote`, and `WellKnownNoteAttachment` to `StandardNoteAttachment` ([#2332](https://github.com/0xMiden/miden-base/pull/2332)). - Skip requests to the `DataStore` for asset vault witnesses which are already in transaction inputs ([#2298](https://github.com/0xMiden/miden-base/pull/2298)). - [BREAKING] Refactored `TransactionAuthenticator::get_public_key()` method to return `Arc `instead of `&PublicKey` ([#2304](https://github.com/0xMiden/miden-base/pull/2304)). diff --git a/crates/miden-agglayer/src/lib.rs b/crates/miden-agglayer/src/lib.rs index 53378ea2de..b6716f9b40 100644 --- a/crates/miden-agglayer/src/lib.rs +++ b/crates/miden-agglayer/src/lib.rs @@ -482,7 +482,8 @@ pub fn create_claim_note(params: ClaimNoteParams<'_, R>) -> Result Self { + /// + /// The tag defaults to [`NoteTag::default()`]. Use [`NoteMetadata::with_tag`] to set a + /// specific tag if needed. + pub fn new(sender: AccountId, note_type: NoteType) -> Self { Self { sender, note_type, - tag, + tag: NoteTag::default(), attachment: NoteAttachment::default(), } } @@ -153,12 +156,27 @@ impl NoteMetadata { // MUTATORS // -------------------------------------------------------------------------------------------- - /// Overwrites the note's attachment with the provided one. + /// Mutates the note's tag by setting it to the provided value. + pub fn set_tag(&mut self, tag: NoteTag) { + self.tag = tag; + } + + /// Returns a new [`NoteMetadata`] with the tag set to the provided value. + /// + /// This is a builder method that consumes self and returns a new instance for method chaining. + pub fn with_tag(mut self, tag: NoteTag) -> Self { + self.tag = tag; + self + } + + /// Mutates the note's attachment by setting it to the provided value. pub fn set_attachment(&mut self, attachment: NoteAttachment) { self.attachment = attachment; } - /// Overwrites the note's attachment with the provided one. + /// Returns a new [`NoteMetadata`] with the attachment set to the provided value. + /// + /// This is a builder method that consumes self and returns a new instance for method chaining. pub fn with_attachment(mut self, attachment: NoteAttachment) -> Self { self.attachment = attachment; self @@ -184,7 +202,7 @@ impl Deserializable for NoteMetadata { let tag = NoteTag::read_from(source)?; let attachment = NoteAttachment::read_from(source)?; - Ok(NoteMetadata::new(sender, note_type, tag).with_attachment(attachment)) + Ok(NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment)) } } @@ -351,7 +369,8 @@ mod tests { let sender = AccountId::try_from(ACCOUNT_ID_MAX_ONES).unwrap(); let note_type = NoteType::Public; let tag = NoteTag::new(u32::MAX); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); // Serialization Roundtrip let deserialized = NoteMetadata::read_from_bytes(&metadata.to_bytes())?; diff --git a/crates/miden-protocol/src/testing/note.rs b/crates/miden-protocol/src/testing/note.rs index 4ce184788f..913fd0f7ee 100644 --- a/crates/miden-protocol/src/testing/note.rs +++ b/crates/miden-protocol/src/testing/note.rs @@ -24,11 +24,8 @@ impl Note { let note_script = NoteScript::mock(); let assets = NoteAssets::new(vec![FungibleAsset::mock(200)]).expect("note assets should be valid"); - let metadata = NoteMetadata::new( - sender_id, - NoteType::Private, - NoteTag::with_account_target(sender_id), - ); + let metadata = NoteMetadata::new(sender_id, NoteType::Private) + .with_tag(NoteTag::with_account_target(sender_id)); let inputs = NoteStorage::new(Vec::new()).unwrap(); let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-standards/src/account/interface/test.rs b/crates/miden-standards/src/account/interface/test.rs index fecdb6a7e8..34ad6399f4 100644 --- a/crates/miden-standards/src/account/interface/test.rs +++ b/crates/miden-standards/src/account/interface/test.rs @@ -253,7 +253,7 @@ fn test_basic_wallet_custom_notes() { let sender_account_id = ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE_2.try_into().unwrap(); let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(wallet_account.id()); - let metadata = NoteMetadata::new(sender_account_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account_id, NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![FungibleAsset::mock(100)]).unwrap(); let compatible_source_code = " @@ -336,7 +336,7 @@ fn test_basic_fungible_faucet_custom_notes() { let sender_account_id = ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE_2.try_into().unwrap(); let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(faucet_account.id()); - let metadata = NoteMetadata::new(sender_account_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account_id, NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![FungibleAsset::mock(100)]).unwrap(); let compatible_source_code = " @@ -439,7 +439,7 @@ fn test_custom_account_custom_notes() { let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(target_account.id()); - let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![FungibleAsset::mock(100)]).unwrap(); let compatible_source_code = " @@ -543,7 +543,7 @@ fn test_custom_account_multiple_components_custom_notes() { let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(target_account.id()); - let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![FungibleAsset::mock(100)]).unwrap(); let compatible_source_code = " diff --git a/crates/miden-standards/src/note/burn.rs b/crates/miden-standards/src/note/burn.rs index 2b5fbf8532..d9b22572a1 100644 --- a/crates/miden-standards/src/note/burn.rs +++ b/crates/miden-standards/src/note/burn.rs @@ -99,7 +99,8 @@ impl BurnNote { let inputs = NoteStorage::new(vec![])?; let tag = NoteTag::with_account_target(faucet_id); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let assets = NoteAssets::new(vec![fungible_asset])?; // BURN notes contain the asset to burn let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-standards/src/note/mint.rs b/crates/miden-standards/src/note/mint.rs index f79258416f..f3363eaa76 100644 --- a/crates/miden-standards/src/note/mint.rs +++ b/crates/miden-standards/src/note/mint.rs @@ -104,7 +104,8 @@ impl MintNote { let tag = NoteTag::with_account_target(faucet_id); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let assets = NoteAssets::new(vec![])?; // MINT notes have no assets let recipient = NoteRecipient::new(serial_num, note_script, storage); diff --git a/crates/miden-standards/src/note/p2id.rs b/crates/miden-standards/src/note/p2id.rs index 15d1f9463e..16154b54ae 100644 --- a/crates/miden-standards/src/note/p2id.rs +++ b/crates/miden-standards/src/note/p2id.rs @@ -87,7 +87,8 @@ impl P2idNote { let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-standards/src/note/p2ide.rs b/crates/miden-standards/src/note/p2ide.rs index ac578a40fd..d45e11a85a 100644 --- a/crates/miden-standards/src/note/p2ide.rs +++ b/crates/miden-standards/src/note/p2ide.rs @@ -92,7 +92,8 @@ impl P2ideNote { let recipient = Self::build_recipient(target, reclaim_height, timelock_height, serial_num)?; let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type, tag).with_attachment(attachment); + let metadata = + NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-standards/src/note/swap.rs b/crates/miden-standards/src/note/swap.rs index 6a65696dee..e22ff92573 100644 --- a/crates/miden-standards/src/note/swap.rs +++ b/crates/miden-standards/src/note/swap.rs @@ -118,8 +118,9 @@ impl SwapNote { let serial_num = rng.draw_word(); // build the outgoing note - let metadata = - NoteMetadata::new(sender, swap_note_type, tag).with_attachment(swap_note_attachment); + let metadata = NoteMetadata::new(sender, swap_note_type) + .with_tag(tag) + .with_attachment(swap_note_attachment); let assets = NoteAssets::new(vec![offered_asset])?; let recipient = NoteRecipient::new(serial_num, note_script, inputs); let note = Note::new(assets, metadata, recipient); diff --git a/crates/miden-standards/src/testing/note.rs b/crates/miden-standards/src/testing/note.rs index e859d13a98..cc077e35ef 100644 --- a/crates/miden-standards/src/testing/note.rs +++ b/crates/miden-standards/src/testing/note.rs @@ -149,7 +149,8 @@ impl NoteBuilder { .compile_note_script(virtual_source_file) .expect("note script should compile"); let vault = NoteAssets::new(self.assets)?; - let metadata = NoteMetadata::new(self.sender, self.note_type, self.tag) + let metadata = NoteMetadata::new(self.sender, self.note_type) + .with_tag(self.tag) .with_attachment(self.attachment); let storage = NoteStorage::new(self.storage)?; let recipient = NoteRecipient::new(self.serial_num, note_script, storage); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs b/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs index e8f0efed52..3fa28f6d28 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_account_interface.rs @@ -791,7 +791,7 @@ fn create_p2ide_note_with_storage( ); let tag = NoteTag::with_account_target(sender); - let metadata = NoteMetadata::new(sender, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender, NoteType::Public).with_tag(tag); Note::new(NoteAssets::default(), metadata, recipient) } diff --git a/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs index 1c5b8488d7..9507e3393e 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_active_note.rs @@ -408,7 +408,7 @@ async fn test_active_note_get_exactly_8_inputs() -> anyhow::Result<()> { // prepare note data let serial_num = RpoRandomCoin::new(Word::from([4u32; 4])).draw_word(); let tag = NoteTag::with_account_target(target_id); - let metadata = NoteMetadata::new(sender_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_id, NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![]).context("failed to create input note assets")?; let note_script = CodeBuilder::default() .compile_note_script("begin nop end") diff --git a/crates/miden-testing/src/kernel_tests/tx/test_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_note.rs index 68e2a630f5..fc493a87d1 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_note.rs @@ -373,9 +373,10 @@ async fn test_build_metadata_header() -> anyhow::Result<()> { let receiver = AccountId::try_from(ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE) .map_err(|e| anyhow::anyhow!("Failed to convert account ID: {}", e))?; - let test_metadata1 = - NoteMetadata::new(sender, NoteType::Private, NoteTag::with_account_target(receiver)); - let test_metadata2 = NoteMetadata::new(sender, NoteType::Public, NoteTag::new(u32::MAX)); + let test_metadata1 = NoteMetadata::new(sender, NoteType::Private) + .with_tag(NoteTag::with_account_target(receiver)); + let test_metadata2 = + NoteMetadata::new(sender, NoteType::Public).with_tag(NoteTag::new(u32::MAX)); for (iteration, test_metadata) in [test_metadata1, test_metadata2].into_iter().enumerate() { let code = format!( @@ -516,7 +517,7 @@ async fn test_public_key_as_note_input() -> anyhow::Result<()> { let serial_num = RpoRandomCoin::new(Word::from([1, 2, 3, 4u32])).draw_word(); let tag = NoteTag::with_account_target(target_account.id()); - let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public, tag); + let metadata = NoteMetadata::new(sender_account.id(), NoteType::Public).with_tag(tag); let vault = NoteAssets::new(vec![])?; let note_script = CodeBuilder::default().compile_note_script("begin nop end")?; let recipient = diff --git a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs index f03dce4331..714aa5b493 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_output_note.rs @@ -100,7 +100,7 @@ async fn test_create_note() -> anyhow::Result<()> { "recipient must be stored at the correct memory location", ); - let metadata = NoteMetadata::new(account_id, NoteType::Public, tag); + let metadata = NoteMetadata::new(account_id, NoteType::Public).with_tag(tag); let expected_metadata_header = metadata.to_header_word(); let expected_note_attachment = metadata.to_attachment_word(); @@ -250,8 +250,8 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { let output_serial_no_1 = Word::from([8u32; 4]); let output_tag_1 = NoteTag::with_account_target(network_account); let assets = NoteAssets::new(vec![input_asset_1])?; - let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public, output_tag_1); + let metadata = NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) + .with_tag(output_tag_1); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_1, input_note_1.script().clone(), inputs); let output_note_1 = Note::new(assets, metadata, recipient); @@ -264,9 +264,9 @@ async fn test_get_output_notes_commitment() -> anyhow::Result<()> { NoteAttachmentScheme::new(5), [42, 43, 44, 45, 46u32].map(Felt::from).to_vec(), )?; - let metadata = - NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public, output_tag_2) - .with_attachment(attachment); + let metadata = NoteMetadata::new(tx_context.tx_inputs().account().id(), NoteType::Public) + .with_tag(output_tag_2) + .with_attachment(attachment); let inputs = NoteStorage::new(vec![])?; let recipient = NoteRecipient::new(output_serial_no_2, input_note_2.script().clone(), inputs); let output_note_2 = Note::new(assets, metadata, recipient); diff --git a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs index fb9d672668..126e493bd7 100644 --- a/crates/miden-testing/src/kernel_tests/tx/test_tx.rs +++ b/crates/miden-testing/src/kernel_tests/tx/test_tx.rs @@ -223,8 +223,9 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let serial_num_2 = Word::from([1, 2, 3, 4u32]); let note_script_2 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_2 = NoteStorage::new(vec![ONE])?; - let metadata_2 = - NoteMetadata::new(account_id, note_type2, tag2).with_attachment(attachment2.clone()); + let metadata_2 = NoteMetadata::new(account_id, note_type2) + .with_tag(tag2) + .with_attachment(attachment2.clone()); let vault_2 = NoteAssets::new(vec![removed_asset_3, removed_asset_4])?; let recipient_2 = NoteRecipient::new(serial_num_2, note_script_2, inputs_2); let expected_output_note_2 = Note::new(vault_2, metadata_2, recipient_2); @@ -233,8 +234,9 @@ async fn executed_transaction_output_notes() -> anyhow::Result<()> { let serial_num_3 = Word::from([Felt::new(5), Felt::new(6), Felt::new(7), Felt::new(8)]); let note_script_3 = CodeBuilder::default().compile_note_script(DEFAULT_NOTE_CODE)?; let inputs_3 = NoteStorage::new(vec![ONE, Felt::new(2)])?; - let metadata_3 = - NoteMetadata::new(account_id, note_type3, tag3).with_attachment(attachment3.clone()); + let metadata_3 = NoteMetadata::new(account_id, note_type3) + .with_tag(tag3) + .with_attachment(attachment3.clone()); let vault_3 = NoteAssets::new(vec![])?; let recipient_3 = NoteRecipient::new(serial_num_3, note_script_3, inputs_3); let expected_output_note_3 = Note::new(vault_3, metadata_3, recipient_3); diff --git a/crates/miden-testing/src/standards/network_account_target.rs b/crates/miden-testing/src/standards/network_account_target.rs index 9908377592..e3d0b0f798 100644 --- a/crates/miden-testing/src/standards/network_account_target.rs +++ b/crates/miden-testing/src/standards/network_account_target.rs @@ -16,9 +16,9 @@ async fn network_account_target_get_id() -> anyhow::Result<()> { let exec_hint = NoteExecutionHint::Always; let attachment = NoteAttachment::from(NetworkAccountTarget::new(target_id, exec_hint)?); - let metadata = - NoteMetadata::new(target_id, NoteType::Public, NoteTag::with_account_target(target_id)) - .with_attachment(attachment.clone()); + let metadata = NoteMetadata::new(target_id, NoteType::Public) + .with_tag(NoteTag::with_account_target(target_id)) + .with_attachment(attachment.clone()); let metadata_header = metadata.to_header_word(); let source = format!( diff --git a/crates/miden-testing/tests/agglayer/bridge_in.rs b/crates/miden-testing/tests/agglayer/bridge_in.rs index c87bd0d77c..7dfac45d5c 100644 --- a/crates/miden-testing/tests/agglayer/bridge_in.rs +++ b/crates/miden-testing/tests/agglayer/bridge_in.rs @@ -131,7 +131,7 @@ async fn test_bridge_in_claim_to_p2id() -> anyhow::Result<()> { let output_note_tag = NoteTag::with_account_target(user_account.id()); let expected_p2id_note = Note::new( NoteAssets::new(vec![mint_asset])?, - NoteMetadata::new(agglayer_faucet.id(), NoteType::Public, output_note_tag), + NoteMetadata::new(agglayer_faucet.id(), NoteType::Public).with_tag(output_note_tag), p2id_recipient, ); diff --git a/crates/miden-testing/tests/agglayer/bridge_out.rs b/crates/miden-testing/tests/agglayer/bridge_out.rs index fd64421070..72e8ec48b1 100644 --- a/crates/miden-testing/tests/agglayer/bridge_out.rs +++ b/crates/miden-testing/tests/agglayer/bridge_out.rs @@ -90,7 +90,7 @@ async fn test_bridge_out_consumes_b2agg_note() -> anyhow::Result<()> { let inputs = NoteStorage::new(input_felts.clone())?; // Create the B2AGG note with assets from the faucet - let b2agg_note_metadata = NoteMetadata::new(faucet.id(), note_type, tag); + let b2agg_note_metadata = NoteMetadata::new(faucet.id(), note_type).with_tag(tag); let b2agg_note_assets = NoteAssets::new(vec![bridge_asset])?; let serial_num = Word::from([1, 2, 3, 4u32]); let b2agg_note_script = NoteScript::new(b2agg_script); @@ -248,7 +248,7 @@ async fn test_b2agg_note_reclaim_scenario() -> anyhow::Result<()> { // Create the B2AGG note with the USER ACCOUNT as the sender // This is the key difference - the note sender will be the same as the consuming account - let b2agg_note_metadata = NoteMetadata::new(user_account.id(), note_type, tag); + let b2agg_note_metadata = NoteMetadata::new(user_account.id(), note_type).with_tag(tag); let b2agg_note_assets = NoteAssets::new(vec![bridge_asset])?; let serial_num = Word::from([1, 2, 3, 4u32]); let b2agg_note_script = NoteScript::new(b2agg_script); diff --git a/crates/miden-testing/tests/lib.rs b/crates/miden-testing/tests/lib.rs index ac31d839cd..ef884c34a8 100644 --- a/crates/miden-testing/tests/lib.rs +++ b/crates/miden-testing/tests/lib.rs @@ -62,7 +62,7 @@ pub fn get_note_with_fungible_asset_and_script( let sender_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap(); let vault = NoteAssets::new(vec![fungible_asset.into()]).unwrap(); - let metadata = NoteMetadata::new(sender_id, NoteType::Public, 1.into()); + let metadata = NoteMetadata::new(sender_id, NoteType::Public).with_tag(1.into()); let inputs = NoteStorage::new(vec![]).unwrap(); let recipient = NoteRecipient::new(serial_num, note_script, inputs); diff --git a/crates/miden-testing/tests/scripts/faucet.rs b/crates/miden-testing/tests/scripts/faucet.rs index ecce94ba3f..2b10db9aef 100644 --- a/crates/miden-testing/tests/scripts/faucet.rs +++ b/crates/miden-testing/tests/scripts/faucet.rs @@ -114,7 +114,7 @@ pub fn verify_minted_output_note( assert_eq!(output_note.id(), id); assert_eq!( output_note.metadata(), - &NoteMetadata::new(faucet.id(), params.note_type, params.tag) + &NoteMetadata::new(faucet.id(), params.note_type).with_tag(params.tag) ); Ok(()) @@ -377,7 +377,7 @@ async fn test_public_note_creation_with_script_from_datastore() -> anyhow::Resul let output_script_root = note_recipient.script().root(); let asset = FungibleAsset::new(faucet.id(), amount.into())?; - let metadata = NoteMetadata::new(faucet.id(), note_type, tag); + let metadata = NoteMetadata::new(faucet.id(), note_type).with_tag(tag); let expected_note = Note::new(NoteAssets::new(vec![asset.into()])?, metadata, note_recipient); let trigger_note_script_code = format!( diff --git a/crates/miden-testing/tests/scripts/send_note.rs b/crates/miden-testing/tests/scripts/send_note.rs index 0655f4bdd5..35ef74b57f 100644 --- a/crates/miden-testing/tests/scripts/send_note.rs +++ b/crates/miden-testing/tests/scripts/send_note.rs @@ -39,7 +39,8 @@ async fn test_send_note_script_basic_wallet() -> anyhow::Result<()> { let tag = NoteTag::with_account_target(sender_basic_wallet_account.id()); let elements = [9, 8, 7, 6, 5u32].map(Felt::from).to_vec(); let attachment = NoteAttachment::new_array(NoteAttachmentScheme::new(42), elements.clone())?; - let metadata = NoteMetadata::new(sender_basic_wallet_account.id(), NoteType::Public, tag) + let metadata = NoteMetadata::new(sender_basic_wallet_account.id(), NoteType::Public) + .with_tag(tag) .with_attachment(attachment.clone()); let assets = NoteAssets::new(vec![sent_asset]).unwrap(); let note_script = CodeBuilder::default().compile_note_script("begin nop end").unwrap(); @@ -96,9 +97,9 @@ async fn test_send_note_script_basic_fungible_faucet() -> anyhow::Result<()> { let tag = NoteTag::with_account_target(sender_basic_fungible_faucet_account.id()); let attachment = NoteAttachment::new_word(NoteAttachmentScheme::new(100), Word::empty()); - let metadata = - NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public, tag) - .with_attachment(attachment); + let metadata = NoteMetadata::new(sender_basic_fungible_faucet_account.id(), NoteType::Public) + .with_tag(tag) + .with_attachment(attachment); let assets = NoteAssets::new(vec![Asset::Fungible( FungibleAsset::new(sender_basic_fungible_faucet_account.id(), 10).unwrap(), )])?; diff --git a/crates/miden-testing/tests/scripts/swap.rs b/crates/miden-testing/tests/scripts/swap.rs index c26d236d30..463cfff6d6 100644 --- a/crates/miden-testing/tests/scripts/swap.rs +++ b/crates/miden-testing/tests/scripts/swap.rs @@ -348,7 +348,7 @@ pub fn create_p2id_note_exact( let tag = NoteTag::with_account_target(target); - let metadata = NoteMetadata::new(sender, note_type, tag); + let metadata = NoteMetadata::new(sender, note_type).with_tag(tag); let vault = NoteAssets::new(assets)?; Ok(Note::new(vault, metadata, recipient)) diff --git a/crates/miden-tx/src/host/tx_event.rs b/crates/miden-tx/src/host/tx_event.rs index d6fe1b73d6..94151e560d 100644 --- a/crates/miden-tx/src/host/tx_event.rs +++ b/crates/miden-tx/src/host/tx_event.rs @@ -724,7 +724,7 @@ fn build_note_metadata( .map_err(|_| TransactionKernelError::other("failed to decode note tag into u32")) .map(NoteTag::new)?; - Ok(NoteMetadata::new(sender, note_type, tag)) + Ok(NoteMetadata::new(sender, note_type).with_tag(tag)) } fn extract_note_attachment(