Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions docs/src/rust-client/creating_notes_in_masm_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ use miden_client::{
PartialNoteMetadata,
},
rpc::{Endpoint, GrpcClient},
transaction::TransactionRequestBuilder,
store::TransactionFilter,
transaction::{TransactionId, TransactionRequestBuilder, TransactionStatus},
Client, ClientError, Felt,
};
use miden_client_sqlite_store::ClientBuilderSqliteExt;
Expand Down Expand Up @@ -319,6 +320,38 @@ async fn wait_for_notes(
Ok(())
}

/// Waits for a specific transaction to be committed.
async fn wait_for_tx(
client: &mut Client<FilesystemKeyStore>,
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
Expand Down Expand Up @@ -489,6 +522,8 @@ async fn main() -> Result<(), ClientError> {
tx_id
);

wait_for_tx(&mut client, tx_id).await?;

Ok(())
}
```
Expand All @@ -502,26 +537,27 @@ cargo run --release
The output will look something like this:

```text
Latest block: 4186
Latest block: 488715

[STEP 1] Creating new accounts
Alice's account ID: "mtst1aqnztxg76d5exyr7ja05pzhvegx3jc84"
Bob's account ID: "mtst1az0mfyzm3xqe2yrezucvmc24dv5gset0"
Alice's account ID: "mtst1azvwquwfvh0jyytq0dk9xya9tvhvu935"
Bob's account ID: "mtst1ap9hwvau7sy9tvtka6smn0ev7cxtgt03"

Deploying a new fungible faucet.
Faucet account ID: "mtst1ary7kplxvatxkgpes4llcc53yu8px433"
Faucet account ID: "mtst1apj3jthkj4mweyf7qt254h5m5gdemp9u"

[STEP 2] Mint tokens with P2ID
Minted tokens. TX: 0x8577213057226b7d0545d73f6e1bc416354a324089450cb859f5784c133d4cc0
0 consumable notes found for account mtst1aqnztxg76d5exyr7ja05pzhvegx3jc84. Waiting...
Consumed minted note. TX: 0xd93e791d3283192df121de4cf938a4f9cfaed48f4e593e1b82d147e2d642b7bd
Minted tokens. TX: 0xf3c8f183aeefb086ca4a63f2a6f34535ea4217849e8e870033f892503302fb7d
0 consumable notes found for account mtst1azvwquwfvh0jyytq0dk9xya9tvhvu935. Waiting...
Consumed minted note. TX: 0x2d31ce827549d8bf35d1c3613610f8388d6c2369dbd1aa34f4f3406f86fdff55

[STEP 3] Create iterative output note
View transaction on MidenScan: https://testnet.midenscan.com/tx/0xcd71a1d87c60ab7632a7836723fff4014b02992ef7ea5d3fe2030a971e795a8a
View transaction on MidenScan: https://testnet.midenscan.com/tx/0xadabf7a920ee27bf1fabd3b02e8e6f3d80f84ece31a23d73f27b0b56bbc2fdc3

[STEP 4] Bob consumes the note and creates a copy
Consumed Note Tx on MidenScan: https://testnet.midenscan.com/tx/0x4d91519c180874c931480fa58620f864fd7c7aada35ada2d40082291298084bb
Account delta: AccountVaultDelta { fungible: FungibleAssetDelta({V0(Accoun
Consumed Note Tx on MidenScan: https://testnet.midenscan.com/tx/0xa003d298db5e7de263a8b98930b6e75336c3cca7cd4a090c707edb6a7f061ad5
Transaction 0xa003d298db5e7de263a8b98930b6e75336c3cca7cd4a090c707edb6a7f061ad5 not yet committed. Waiting...
✅ transaction 0xa003d298db5e7de263a8b98930b6e75336c3cca7cd4a090c707edb6a7f061ad5 committed
```

---
Expand Down
22 changes: 13 additions & 9 deletions docs/src/rust-client/custom_note_how_to.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,16 @@ async fn main() -> Result<(), ClientError> {
tx_id
);

wait_for_tx(&mut client, tx_id).await?;

Ok(())
}
```

The output of our program will look something like this:

```text
Latest block: 226943
Latest block: 488704

[STEP 1] Creating new accounts
Alice's account ID: "<testnet_account_id>"
Expand All @@ -411,19 +413,21 @@ Deploying a new fungible faucet.
Faucet account ID: "<testnet_account_id>"

[STEP 2] Mint tokens with P2ID
Note 0x88d8c4a50c0e6342e58026b051fb6038867de21d3bd3963aec67fd6c45861faf not found. Waiting...
Note 0x88d8c4a50c0e6342e58026b051fb6038867de21d3bd3963aec67fd6c45861faf not found. Waiting...
✅ note found 0x88d8c4a50c0e6342e58026b051fb6038867de21d3bd3963aec67fd6c45861faf
Minted tokens. TX: 0x970265408eb22068b22ec677f6ad09a2524913ab11b3dbf010e4cae73587e2e3
Transaction 0x970265408eb22068b22ec677f6ad09a2524913ab11b3dbf010e4cae73587e2e3 not yet committed. Waiting...
✅ transaction 0x970265408eb22068b22ec677f6ad09a2524913ab11b3dbf010e4cae73587e2e3 committed
Consumed minted note. TX: 0x47850a0c44d9e147b8866285c24ba05a0d4bed0a99c1f25a13f32e57feecfe1b

[STEP 3] Create custom note
digest: RpoDigest([14371582251229115050, 1386930022051078873, 17689831064175867466, 9632123050519021080])
note hash: "0x14c66143377223e090e5b4da0d1e5ce6c6521622ad5b92161a704a25c915769b"
View transaction on MidenScan: https://testnet.midenscan.com/tx/0xffbee228a2c6283efe958c6b3cd31af88018c029221b413b0f23fcfacb2cb611
digest: Word([14206540680072267069, 9571949196318390099, 5950603493574130513, 3457190364553631046])
note hash: "0xf48f362f1817bbc5575e0bb8b77c496dd67e4b85d8ff45d21dff5743de2b174d"
View transaction on MidenScan: https://testnet.midenscan.com/tx/0x9911ef1b9d2b066e017de187b7c1f8d95012748366358474b11adc91e49971b5

[STEP 4] Bob consumes the Custom Note with Correct Secret
Consumed Note Tx on MidenScan: https://testnet.midenscan.com/tx/0xe6c8bb7b469e03dcacd8f1f400011a781e96ad4266ede11af8e711379e85b929
Consumed Note Tx on MidenScan: https://testnet.midenscan.com/tx/0x2a7a192b692984ae649dd1a13d15e4b79178e9e554615ffec7426e25e75193fa

account delta: AccountVaultDelta { fungible: FungibleAssetDelta({V0(AccountIdV0 { prefix: 6702563556733766432, suffix: 1016103534633728 }): 100}), non_fungible: NonFungibleAssetDelta({}) }
Transaction 0x2a7a192b692984ae649dd1a13d15e4b79178e9e554615ffec7426e25e75193fa not yet committed. Waiting...
✅ transaction 0x2a7a192b692984ae649dd1a13d15e4b79178e9e554615ffec7426e25e75193fa committed
```

## Conclusion
Expand Down
2 changes: 2 additions & 0 deletions rust-client/src/bin/hash_preimage_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,7 @@ async fn main() -> Result<(), ClientError> {
tx_id
);

wait_for_tx(&mut client, tx_id).await?;

Ok(())
}
37 changes: 36 additions & 1 deletion rust-client/src/bin/note_creation_in_masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use miden_client::{
PartialNoteMetadata,
},
rpc::{Endpoint, GrpcClient},
transaction::TransactionRequestBuilder,
store::TransactionFilter,
transaction::{TransactionId, TransactionRequestBuilder, TransactionStatus},
Client, ClientError, Felt,
};
use miden_client_sqlite_store::ClientBuilderSqliteExt;
Expand Down Expand Up @@ -111,6 +112,38 @@ async fn wait_for_notes(
Ok(())
}

/// Waits for a specific transaction to be committed.
async fn wait_for_tx(
client: &mut Client<FilesystemKeyStore>,
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
Expand Down Expand Up @@ -281,5 +314,7 @@ async fn main() -> Result<(), ClientError> {
tx_id
);

wait_for_tx(&mut client, tx_id).await?;

Ok(())
}
Loading