From 04de9e9597b69fe31764e214736db5005fe2af07 Mon Sep 17 00:00:00 2001 From: 0xTitan Date: Fri, 13 Feb 2026 22:13:14 +0100 Subject: [PATCH] Update on network note creation --- Cargo.toml | 10 +++++----- src/notes.rs | 46 ++++++++++++++++++++++++++++++++-------------- src/scripts.rs | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 262e1bf..8172cfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,18 +4,18 @@ version = "0.1.0" edition = "2024" [dependencies] -miden-client = { version = "0.13", features = ["testing", "tonic"] } -miden-standards = { version = "0.13", default-features = false } -miden-protocol = { version = "0.13", default-features = false, features = ["testing"] } +miden-client = { version = "0.13.1", features = ["testing", "tonic"] } +miden-standards = { version = "0.13.3", default-features = false } +miden-protocol = { version = "0.13.3", default-features = false, features = ["testing"] } miden-crypto = { version = "0.19", features = ["executable"] } miden-assembly = "0.20" -miden-testing = "0.13" +miden-testing = "0.13.3" rand = { version = "0.9" } serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0", features = ["raw_value"] } tokio = { version = "1.46", features = ["rt-multi-thread", "net", "macros", "fs"] } rand_chacha = "0.9.0" -miden-client-sqlite-store = "0.13" +miden-client-sqlite-store = "0.13.1" chrono = "0.4" anyhow = "1" dotenvy = "0.15" diff --git a/src/notes.rs b/src/notes.rs index c6342ca..5dd92cd 100644 --- a/src/notes.rs +++ b/src/notes.rs @@ -12,7 +12,9 @@ use miden_client::{ }, }; use miden_standards::code_builder::CodeBuilder; +use miden_standards::note::NetworkAccountTarget; use miden_protocol::transaction::TransactionKernel; +use miden_protocol::note::NoteExecutionHint; use miden_crypto::{Felt, Word}; use rand::{Rng, RngCore}; use std::{fs, path::Path, sync::Arc}; @@ -21,9 +23,10 @@ pub async fn create_note_for_naming_with_client( name: String, inputs: NoteInputs, sender: AccountId, - _target_id: AccountId, + target_id: AccountId, assets: NoteAssets, client: &mut Client, + is_network_account: bool, ) -> anyhow::Result { let note_code = fs::read_to_string(Path::new(&format!("./masm/notes/{}.masm", name)))?; let naming_code = fs::read_to_string(Path::new("./masm/accounts/naming_unsafe.masm")).unwrap(); @@ -41,12 +44,19 @@ pub async fn create_note_for_naming_with_client( .compile_note_script(note_code)?; let recipient = NoteRecipient::new(serial_num, note_script, inputs.clone()); - let tag = NoteTag::with_account_target(_target_id); - let metadata = NoteMetadata::new( - sender, - NoteType::Public, - tag, - ); + let tag = NoteTag::with_account_target(target_id); + + let metadata = if is_network_account { + // For network accounts, attach NetworkAccountTarget so the network can consume the note + let network_target = NetworkAccountTarget::new(target_id, NoteExecutionHint::Always) + .map_err(|e| anyhow::anyhow!("Failed to create NetworkAccountTarget: {}", e))?; + NoteMetadata::new(sender, NoteType::Public, tag) + .with_attachment(network_target.into()) + } else { + // For public accounts, no attachment needed + NoteMetadata::new(sender, NoteType::Public, tag) + }; + let note = Note::new(assets, metadata, recipient); Ok(note) } @@ -55,8 +65,9 @@ pub async fn create_note_for_naming( name: String, inputs: NoteInputs, sender: AccountId, - _target_id: AccountId, + target_id: AccountId, assets: NoteAssets, + is_network_account: bool, ) -> anyhow::Result { let note_code = fs::read_to_string(Path::new(&format!("./masm/notes/{}.masm", name)))?; let naming_code = fs::read_to_string(Path::new("./masm/accounts/naming.masm")).unwrap(); @@ -68,12 +79,19 @@ pub async fn create_note_for_naming( .compile_note_script(note_code)?; let recipient = NoteRecipient::new(serial, note_script, inputs.clone()); - let tag = NoteTag::with_account_target(_target_id); - let metadata = NoteMetadata::new( - sender, - NoteType::Public, - tag, - ); + let tag = NoteTag::with_account_target(target_id); + + let metadata = if is_network_account { + // For network accounts, attach NetworkAccountTarget so the network can consume the note + let network_target = NetworkAccountTarget::new(target_id, NoteExecutionHint::Always) + .map_err(|e| anyhow::anyhow!("Failed to create NetworkAccountTarget: {}", e))?; + NoteMetadata::new(sender, NoteType::Public, tag) + .with_attachment(network_target.into()) + } else { + // For public accounts, no attachment needed + NoteMetadata::new(sender, NoteType::Public, tag) + }; + let note = Note::new(assets, metadata, recipient); Ok(note) } diff --git a/src/scripts.rs b/src/scripts.rs index 53930e1..ae5dbb6 100644 --- a/src/scripts.rs +++ b/src/scripts.rs @@ -96,6 +96,7 @@ pub async fn deploy(is_network: bool, use_testnet: bool) -> anyhow::Result<()> { naming_account.id(), NoteAssets::new(vec![]).unwrap(), &mut client, + is_network, ) .await?; @@ -155,6 +156,7 @@ pub async fn deploy(is_network: bool, use_testnet: bool) -> anyhow::Result<()> { naming_account.id(), NoteAssets::new(vec![]).unwrap(), &mut client, + is_network, ) .await?; @@ -405,6 +407,7 @@ pub async fn send_register_note( naming_account, register_asset, &mut client, + is_network, ) .await?;