From 87e23f996033391c406a16acaf70d5df09afa3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Thu, 19 Sep 2024 11:57:30 +0400 Subject: [PATCH] Transactions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- Rust/examples/transaction.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Rust/examples/transaction.rs diff --git a/Rust/examples/transaction.rs b/Rust/examples/transaction.rs new file mode 100644 index 0000000..5b0a0b6 --- /dev/null +++ b/Rust/examples/transaction.rs @@ -0,0 +1,31 @@ +//! Shows how to work directly with transactions. + +use iroha::data_model::prelude::{Metadata, Mint}; +use iroha_examples::{AliceInWonderland, RosesOfAliceInWonderland}; + +fn main() -> iroha_examples::Result<()> { + // Prepare the instructions you want to execute + let roses_of_alice_in_wland = RosesOfAliceInWonderland::id(); + let mint_roses_of_alice_in_wland = Mint::asset_numeric(1_u32, roses_of_alice_in_wland); + + // Combine the instructions + let instructions = [ + mint_roses_of_alice_in_wland.clone(), + mint_roses_of_alice_in_wland, + ]; + + // Build a transaction with the prepared instructions and empty metadata + // on behalf of the account configured with the client + let as_alice_in_wland = AliceInWonderland::client(); + let signed_tx = as_alice_in_wland.build_transaction(instructions, Metadata::default()); + + let _tx_hash_1 = as_alice_in_wland.submit_transaction(&signed_tx)?; + + // Transaction 1 may or may not have been committed or rejected. + // If you want synchronous behavior, use the _blocking variant: + + let _tx_hash_2 = as_alice_in_wland.submit_transaction_blocking(&signed_tx)?; + + // If this line has been reached, Transaction 2 has been committed. + Ok(()) +}