From 8058424016307078c94d337aac6a74f7bedc2c34 Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Tue, 11 Aug 2026 15:12:51 +0300 Subject: [PATCH 1/4] refactor: add shared transaction wait helper --- rust-client/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rust-client/src/lib.rs diff --git a/rust-client/src/lib.rs b/rust-client/src/lib.rs new file mode 100644 index 0000000..ec61efb --- /dev/null +++ b/rust-client/src/lib.rs @@ -0,0 +1,39 @@ +use std::time::Duration; + +use miden_client::{ + keystore::FilesystemKeyStore, + store::TransactionFilter, + transaction::{TransactionId, TransactionStatus}, + Client, ClientError, +}; +use tokio::time::sleep; + +/// Waits until the specified transaction is committed, syncing the client between polls. +pub async fn wait_for_tx( + client: &mut Client, + tx_id: TransactionId, +) -> Result<(), ClientError> { + loop { + client.sync_state().await?; + + let txs = client + .get_transactions(TransactionFilter::Ids(vec![tx_id])) + .await?; + let tx_committed = txs + .first() + .is_some_and(|tx| matches!(tx.status, TransactionStatus::Committed { .. })); + + if tx_committed { + println!("✅ transaction {} committed", tx_id.to_hex()); + break; + } + + println!( + "Transaction {} not yet committed. Waiting...", + tx_id.to_hex() + ); + sleep(Duration::from_secs(2)).await; + } + + Ok(()) +} From 60e89237df3f2244464d7f1f0ace95c1b77550c6 Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Tue, 11 Aug 2026 16:13:23 +0300 Subject: [PATCH 2/4] Use shared wait_for_tx helper --- rust-client/src/bin/hash_preimage_note.rs | 37 ++--------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/rust-client/src/bin/hash_preimage_note.rs b/rust-client/src/bin/hash_preimage_note.rs index 1385cb1..0972848 100644 --- a/rust-client/src/bin/hash_preimage_note.rs +++ b/rust-client/src/bin/hash_preimage_note.rs @@ -1,6 +1,5 @@ use rand::RngCore; use std::{path::PathBuf, sync::Arc}; -use tokio::time::{sleep, Duration}; use miden_client::{ account::{ @@ -18,12 +17,12 @@ use miden_client::{ keystore::{FilesystemKeyStore, Keystore}, note::{Note, NoteAssets, NoteRecipient, NoteStorage, NoteTag, NoteType, PartialNoteMetadata}, rpc::{Endpoint, GrpcClient}, - store::TransactionFilter, - transaction::{TransactionId, TransactionRequestBuilder, TransactionStatus}, + transaction::TransactionRequestBuilder, Client, ClientError, Felt, }; use miden_client_sqlite_store::ClientBuilderSqliteExt; use miden_protocol::Hasher; +use rust_client::wait_for_tx; // Helper to create a basic account async fn create_basic_account( @@ -88,38 +87,6 @@ async fn create_basic_faucet( Ok(account) } -/// Waits for a specific transaction to be committed. -async fn wait_for_tx( - client: &mut Client, - tx_id: TransactionId, -) -> Result<(), ClientError> { - loop { - client.sync_state().await?; - - // Check transaction status - let txs = client - .get_transactions(TransactionFilter::Ids(vec![tx_id])) - .await?; - let tx_committed = if !txs.is_empty() { - matches!(txs[0].status, TransactionStatus::Committed { .. }) - } else { - false - }; - - if tx_committed { - println!("✅ transaction {} committed", tx_id.to_hex()); - break; - } - - println!( - "Transaction {} not yet committed. Waiting...", - tx_id.to_hex() - ); - sleep(Duration::from_secs(2)).await; - } - Ok(()) -} - #[tokio::main] async fn main() -> Result<(), ClientError> { // Initialize client From d8bad51c9ab71a83c0b03b914d1f07d1be1f0b4d Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Tue, 11 Aug 2026 17:03:01 +0300 Subject: [PATCH 3/4] refactor: reuse shared wait_for_tx in network notes tutorial --- .../src/bin/network_notes_counter_contract.rs | 40 ++----------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/rust-client/src/bin/network_notes_counter_contract.rs b/rust-client/src/bin/network_notes_counter_contract.rs index b48a51a..2edc64a 100644 --- a/rust-client/src/bin/network_notes_counter_contract.rs +++ b/rust-client/src/bin/network_notes_counter_contract.rs @@ -15,48 +15,14 @@ use miden_client::{ NoteRecipient, NoteStorage, NoteTag, NoteType, PartialNoteMetadata, }, rpc::{Endpoint, GrpcClient}, - store::TransactionFilter, - transaction::{ - TransactionId, TransactionRequestBuilder, TransactionStatus, - }, - Client, ClientError, Felt, Word, + transaction::TransactionRequestBuilder, + Felt, Word, }; use miden_client_sqlite_store::ClientBuilderSqliteExt; use rand::RngCore; +use rust_client::wait_for_tx; use tokio::time::{sleep, Duration}; -/// Waits for a specific transaction to be committed. -async fn wait_for_tx( - client: &mut Client, - tx_id: TransactionId, -) -> Result<(), ClientError> { - loop { - client.sync_state().await?; - - // Check transaction status - let txs = client - .get_transactions(TransactionFilter::Ids(vec![tx_id])) - .await?; - let tx_committed = if !txs.is_empty() { - matches!(txs[0].status, TransactionStatus::Committed { .. }) - } else { - false - }; - - if tx_committed { - println!("✅ transaction {} committed", tx_id.to_hex()); - break; - } - - println!( - "Transaction {} not yet committed. Waiting...", - tx_id.to_hex() - ); - sleep(Duration::from_secs(2)).await; - } - Ok(()) -} - #[tokio::main] async fn main() -> Result<(), Box> { // Initialize client From 364e8830fe63e868f112a746029211e573ec19ea Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Wed, 12 Aug 2026 09:06:08 +0300 Subject: [PATCH 4/4] refactor: reuse shared transaction wait helper --- .../src/bin/unauthenticated_note_transfer.rs | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/rust-client/src/bin/unauthenticated_note_transfer.rs b/rust-client/src/bin/unauthenticated_note_transfer.rs index b64f4a2..37dff98 100644 --- a/rust-client/src/bin/unauthenticated_note_transfer.rs +++ b/rust-client/src/bin/unauthenticated_note_transfer.rs @@ -1,6 +1,6 @@ use rand::RngCore; use std::{path::PathBuf, sync::Arc}; -use tokio::time::{sleep, Duration, Instant}; +use tokio::time::{Duration, Instant}; use miden_client::{ account::{ @@ -17,44 +17,12 @@ use miden_client::{ keystore::{FilesystemKeyStore, Keystore}, note::{Note, NoteAttachments, NoteType, P2idNote}, rpc::{Endpoint, GrpcClient}, - store::TransactionFilter, - transaction::{TransactionId, TransactionRequestBuilder, TransactionStatus}, + transaction::TransactionRequestBuilder, utils::{Deserializable, Serializable}, - Client, ClientError, + ClientError, }; use miden_client_sqlite_store::ClientBuilderSqliteExt; - -/// Waits for a specific transaction to be committed. -async fn wait_for_tx( - client: &mut Client, - tx_id: TransactionId, -) -> Result<(), ClientError> { - loop { - client.sync_state().await?; - - // Check transaction status - let txs = client - .get_transactions(TransactionFilter::Ids(vec![tx_id])) - .await?; - let tx_committed = if !txs.is_empty() { - matches!(txs[0].status, TransactionStatus::Committed { .. }) - } else { - false - }; - - if tx_committed { - println!("✅ transaction {} committed", tx_id.to_hex()); - break; - } - - println!( - "Transaction {} not yet committed. Waiting...", - tx_id.to_hex() - ); - sleep(Duration::from_secs(2)).await; - } - Ok(()) -} +use rust_client::wait_for_tx; #[tokio::main] async fn main() -> Result<(), ClientError> {