From 3e6c488e5761fd58c4fd99a8a4e4583e719f3f32 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Fri, 29 Aug 2025 15:34:24 -0300 Subject: [PATCH] fix: note not being consumed --- .../src/bin/network_notes_counter_contract.rs | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/rust-client/src/bin/network_notes_counter_contract.rs b/rust-client/src/bin/network_notes_counter_contract.rs index 2c639e7..2edb4bf 100644 --- a/rust-client/src/bin/network_notes_counter_contract.rs +++ b/rust-client/src/bin/network_notes_counter_contract.rs @@ -459,7 +459,7 @@ async fn main() -> Result<(), Box> { // Build and submit the transaction containing the note let note_req = TransactionRequestBuilder::new() - .own_output_notes(vec![OutputNote::Full(staking_note)]) + .own_output_notes(vec![OutputNote::Full(staking_note.clone())]) .build()?; let tx_result = client.new_transaction(alice_account.id(), note_req).await?; @@ -469,7 +469,7 @@ async fn main() -> Result<(), Box> { let note_tx_id = tx_result.executed_transaction().id(); println!( "View transaction on MidenScan: https://testnet.midenscan.com/tx/{:?}", - note_tx_id + note_tx_id, ); client.sync_state().await?; @@ -488,35 +488,43 @@ async fn main() -> Result<(), Box> { println!("\n[STEP 8] Staking contarct will now consume Alice's note."); client.add_note_tag(tag).await?; - loop { - // Resync to get the latest data - client.sync_state().await?; + // loop { + // Resync to get the latest data + client.sync_state().await?; - let consumable_notes = client - .get_consumable_notes(Some(staking_contract.id())) - .await?; - let list_of_note_ids: Vec<_> = consumable_notes.iter().map(|(note, _)| note.id()).collect(); + let consumable_notes = client + .get_consumable_notes(Some(staking_contract.id())) + .await?; + let _list_of_note_ids: Vec<_> = consumable_notes.iter().map(|(note, _)| note.id()).collect(); - if list_of_note_ids.len() == 1 { - println!("Found Staking note onchain. Consuming it now..."); - let transaction_request = TransactionRequestBuilder::new() - .build_consume_notes(list_of_note_ids) - .unwrap(); - let tx_execution_result = client - .new_transaction(staking_contract.id(), transaction_request) - .await?; + let _ = client + .get_input_notes(miden_client::store::NoteFilter::All) + .await + .unwrap() + .iter() + .for_each(|n| println!("{}", n.id())); - client.submit_transaction(tx_execution_result).await?; - println!("Worked."); - break; - } else { - println!( - "Currently, Staking Contract has {} consumable notes. Waiting...", - list_of_note_ids.len() - ); - tokio::time::sleep(Duration::from_secs(3)).await; - } - } + //if list_of_note_ids.len() == 1 { + println!("Found Staking note onchain. Consuming it now..."); + let transaction_request = TransactionRequestBuilder::new() + .unauthenticated_input_notes([(staking_note, None)]) + .build_consume_notes(vec![]) + .unwrap(); + let tx_execution_result = client + .new_transaction(staking_contract.id(), transaction_request) + .await?; + + client.submit_transaction(tx_execution_result).await?; + println!("Worked."); + //break; + // } else { + // println!( + // "Currently, Staking Contract has {} consumable notes. Waiting...", + // list_of_note_ids.len() + // ); + // tokio::time::sleep(Duration::from_secs(3)).await; + // } + //} // Checking updated state let new_account_state = client.get_account(staking_contract.id()).await.unwrap();