diff --git a/demos/rust-cosmos-broadcaster/bin/client.rs b/demos/rust-cosmos-broadcaster/bin/client.rs index 349e8997ad..acbc9a505a 100644 --- a/demos/rust-cosmos-broadcaster/bin/client.rs +++ b/demos/rust-cosmos-broadcaster/bin/client.rs @@ -1,5 +1,4 @@ use clap::{Args, Parser, Subcommand}; - use nym_sdk::mixnet::Recipient; use nym_validator_client::nyxd::AccountId; use rust_cosmos_broadcaster::{ diff --git a/demos/rust-cosmos-broadcaster/bin/service.rs b/demos/rust-cosmos-broadcaster/bin/service.rs index d53652f713..72cd31b037 100644 --- a/demos/rust-cosmos-broadcaster/bin/service.rs +++ b/demos/rust-cosmos-broadcaster/bin/service.rs @@ -15,8 +15,10 @@ async fn main() -> anyhow::Result<()> { let broadcaster = create_broadcaster().await; loop { + // listen out for incoming requests from mixnet, parse and match them let request: (RequestTypes, AnonymousSenderTag) = listen_and_parse_request(&mut client).await; + // grab sender_tag from parsed request for anonymous replies let return_recipient: AnonymousSenderTag = request.1; match request.0 { RequestTypes::Sequence(request) => { @@ -24,10 +26,12 @@ async fn main() -> anyhow::Result<()> { "\nincoming sequence request details:\nsigner address: {}", request.signer_address ); + // query Nyx chain for sequence information on behalf of request sender let sequence: SequenceRequestResponse = get_sequence(broadcaster.clone(), request.signer_address) .await .unwrap(); + // send serialised sequence response back to request sender via mixnet client .send_str_reply(return_recipient, &serde_json::to_string(&sequence).unwrap()) .await; @@ -37,11 +41,13 @@ async fn main() -> anyhow::Result<()> { "\nincoming broadcast request: {}\n", request.base58_tx_bytes ); + // broadcast the signed tx on behalf of request sender let tx_hash: BroadcastResponse = broadcast(request.base58_tx_bytes, broadcaster.clone()) .await .unwrap(); println!("return recipient surb bucket: {}", &return_recipient); + // send response to tx (transaction hash) back to request sender via mixnet client .send_str_reply(return_recipient, &serde_json::to_string(&tx_hash).unwrap()) .await; diff --git a/demos/rust-cosmos-broadcaster/src/client.rs b/demos/rust-cosmos-broadcaster/src/client.rs index 6dbc2a7dfa..68230895a2 100644 --- a/demos/rust-cosmos-broadcaster/src/client.rs +++ b/demos/rust-cosmos-broadcaster/src/client.rs @@ -30,11 +30,12 @@ pub async fn offline_sign( signer_address, // our (sender) address, derived from mnemonic }; - // send req to client + // send req to service via the mixnet client .send_str(sp_address, &serde_json::to_string(&message).unwrap()) .await; + // listen for response from service let sp_response = crate::listen_and_parse_response(client).await; // match JSON -> ResponseType @@ -83,12 +84,12 @@ pub async fn offline_sign( .unwrap(); let tx_bytes = tx_raw.to_bytes().unwrap(); + // encode tx bytes as base58 for ease of logging + copying for user let base58_tx_bytes = bs58::encode(tx_bytes).into_string(); base58_tx_bytes } _ => String::from("unexpected response"), }; - Ok(res) } @@ -101,15 +102,16 @@ pub async fn send_tx( base58_tx_bytes: base58_tx, }; + // send broadcast request containing base58 encoded signed tx to service via mixnet client .send_str( sp_address, &serde_json::to_string(&broadcast_request).unwrap(), ) .await; - println!("Waiting for reply"); + // again, listen for response and parse accordingly let sp_response = crate::listen_and_parse_response(client).await; let res = match sp_response { @@ -125,6 +127,5 @@ pub async fn send_tx( false, ), }; - Ok(res) }