diff --git a/demos/rust-cosmos-broadcaster/bin/client.rs b/demos/rust-cosmos-broadcaster/bin/client.rs index 405849de52..8ae6cf29db 100644 --- a/demos/rust-cosmos-broadcaster/bin/client.rs +++ b/demos/rust-cosmos-broadcaster/bin/client.rs @@ -9,7 +9,7 @@ use rust_cosmos_broadcaster::{ #[derive(Debug, Parser)] #[clap(name = "nym cosmos tx signer ")] #[clap( - about = "demo binary with which users can perform offline signing and transmission of signed tx to broadcaster via the mixnet " + about = "demo binary with which users can perform offline signing and transmission of signed token tx to broadcaster via the mixnet " )] struct Cli { #[clap(subcommand)] @@ -26,7 +26,7 @@ enum Commands { #[derive(Debug, Clone, Args)] struct OfflineSignTx { - /// mnemonic of signing + sending account (you!) + /// mnemonic of signing + sending account (you!) mnemonic: bip39::Mnemonic, /// recipient nyx chain address for token transfer nyx_token_receipient: AccountId, @@ -40,12 +40,10 @@ struct SendTx { #[tokio::main] async fn main() -> anyhow::Result<()> { - let cli = Cli::parse(); let mut client = create_client("/tmp/cosmos-broadcaster-mixnet-client-5".into()).await; let our_address = client.nym_address(); println!("\nclient's nym address: {our_address}"); - let sp_address = Recipient::try_from_base58_string("2f499xz7AfEmsdjd9zaxEVMZ4ed5pod2AqomZ74PSdTW.6heKJmwFZMw14Yz7CKF56iyKDaBBssmNWZJHErGg5jgm@HWdr8jgcr32cVGbjisjmwnVF4xrUBRGvbw86F9e3rFzS").unwrap(); match cli.command { @@ -66,7 +64,7 @@ async fn main() -> anyhow::Result<()> { "Encoded response (signed tx data) as base58 for tx broadcast: \n\n{:?}\n", &base58_tx_bytes.as_ref() ); - println!("do you wish to send the tx? y/n"); + println!("do you also wish to send the tx? y/n"); let mut input = String::new(); let stdin = std::io::stdin(); @@ -74,7 +72,8 @@ async fn main() -> anyhow::Result<()> { if input.starts_with('y') { println!("\nsending pre-signed tx through the mixnet to broadcaster service"); - let (tx_hash, success) = send_tx(base58_tx_bytes.unwrap(), sp_address, &mut client).await?; + let (tx_hash, success) = + send_tx(base58_tx_bytes.unwrap(), sp_address, &mut client).await?; println!( "tx hash returned from the broadcaster: {}\ntx was successful: {}", tx_hash, success diff --git a/demos/rust-cosmos-broadcaster/bin/service.rs b/demos/rust-cosmos-broadcaster/bin/service.rs index bdcbe6a84b..6ef6e5268f 100644 --- a/demos/rust-cosmos-broadcaster/bin/service.rs +++ b/demos/rust-cosmos-broadcaster/bin/service.rs @@ -17,7 +17,7 @@ async fn main() -> anyhow::Result<()> { loop { // listen out for incoming requests from mixnet, parse and match them let request: (RequestTypes, AnonymousSenderTag) = - listen_and_parse_request(&mut client).await?; + 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 { @@ -28,8 +28,7 @@ async fn main() -> anyhow::Result<()> { ); // query chain for sequence information on behalf of request sender let sequence: SequenceRequestResponse = - get_sequence(broadcaster.clone(), request.signer_address) - .await?; + get_sequence(broadcaster.clone(), request.signer_address).await?; println!("sequence information returned from chain: account number: {}, sequence:{}, chain id: {} \nsending response to requesting client via mixnet", sequence.account_number, sequence.sequence, sequence.chain_id); // send serialised sequence response back to request sender via mixnet client @@ -43,8 +42,7 @@ async fn main() -> anyhow::Result<()> { ); // broadcast the signed tx on behalf of request sender let tx_hash: BroadcastResponse = - broadcast(request.base58_tx_bytes, broadcaster.clone()) - .await?; + broadcast(request.base58_tx_bytes, broadcaster.clone()).await?; println!("return recipient surb bucket: {}", &return_recipient); // send response to tx (transaction hash) back to request sender via mixnet client diff --git a/demos/rust-cosmos-broadcaster/src/client.rs b/demos/rust-cosmos-broadcaster/src/client.rs index daf95e8bc3..99bcf8a404 100644 --- a/demos/rust-cosmos-broadcaster/src/client.rs +++ b/demos/rust-cosmos-broadcaster/src/client.rs @@ -30,12 +30,12 @@ pub async fn offline_sign( signer_address: signer_address.clone(), // our (sender) address, derived from mnemonic }; - // send req to service via the mixnet + // send req to service via the mixnet client .send_str(sp_address, &serde_json::to_string(&message).unwrap()) .await; - // listen for response from service + // listen for response from service let sp_response = crate::listen_and_parse_response(client).await?; // match JSON -> ResponseType @@ -81,7 +81,7 @@ 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 + // 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 } @@ -108,7 +108,7 @@ pub async fn send_tx( .await; println!("Waiting for reply"); - // again, listen for response and parse accordingly + // again, listen for response and parse accordingly let sp_response = crate::listen_and_parse_response(client).await?; let res = match sp_response { diff --git a/demos/rust-cosmos-broadcaster/src/lib.rs b/demos/rust-cosmos-broadcaster/src/lib.rs index b0bf310cf2..98bdfa59ee 100644 --- a/demos/rust-cosmos-broadcaster/src/lib.rs +++ b/demos/rust-cosmos-broadcaster/src/lib.rs @@ -63,9 +63,7 @@ pub async fn create_client(config_path: PathBuf) -> MixnetClient { // parse returned response from service: ignore empty SURB data packets + parse incoming message to struct or error // we know we are expecting JSON here but an irl helper would parse conditionally on bytes / string incoming -pub async fn listen_and_parse_response( - client: &mut MixnetClient -) -> anyhow::Result { +pub async fn listen_and_parse_response(client: &mut MixnetClient) -> anyhow::Result { let mut message: Vec = Vec::new(); // get the actual message - discard the empty vec sent along with the SURB topup request @@ -80,9 +78,9 @@ pub async fn listen_and_parse_response( // parse vec -> JSON String let mut parsed = String::new(); if let Some(r) = message.iter().next() { - parsed = String::from_utf8(r.message.clone())?; + parsed = String::from_utf8(r.message.clone())?; } - let sp_response: crate::ResponseTypes = serde_json::from_str(&parsed)?; + let sp_response: crate::ResponseTypes = serde_json::from_str(&parsed)?; Ok(sp_response) } @@ -105,9 +103,9 @@ pub async fn listen_and_parse_request( // parse vec -> JSON String let mut parsed = String::new(); if let Some(r) = message.iter().next() { - parsed = String::from_utf8(r.message.clone())?; + parsed = String::from_utf8(r.message.clone())?; } - let client_request: crate::RequestTypes = serde_json::from_str(&parsed)?; + let client_request: crate::RequestTypes = serde_json::from_str(&parsed)?; // get the sender_tag for anon reply let return_recipient = message[0].sender_tag.unwrap(); diff --git a/demos/rust-cosmos-broadcaster/src/service.rs b/demos/rust-cosmos-broadcaster/src/service.rs index fa25c1e8b0..08186469b8 100644 --- a/demos/rust-cosmos-broadcaster/src/service.rs +++ b/demos/rust-cosmos-broadcaster/src/service.rs @@ -2,9 +2,9 @@ use crate::DEFAULT_VALIDATOR_RPC; use bs58; use cosmrs::rpc::{Client, HttpClient}; use cosmrs::{tendermint, AccountId}; -use nym_validator_client::nyxd::{CosmWasmClient,error::NyxdError}; +use nym_validator_client::nyxd::{error::NyxdError, CosmWasmClient}; -pub async fn create_broadcaster() -> anyhow::Result{ +pub async fn create_broadcaster() -> anyhow::Result { let broadcaster: HttpClient = HttpClient::new(DEFAULT_VALIDATOR_RPC)?; Ok(broadcaster) } @@ -12,10 +12,10 @@ pub async fn create_broadcaster() -> anyhow::Result{ pub async fn get_sequence( broadcaster: HttpClient, signer_address: AccountId, -) -> Result { +) -> Result { // get signer information - let sequence = broadcaster.get_sequence(&signer_address).await?; - let chain_id: tendermint::chain::Id = broadcaster.get_chain_id().await?; + let sequence = broadcaster.get_sequence(&signer_address).await?; + let chain_id: tendermint::chain::Id = broadcaster.get_chain_id().await?; Ok(crate::SequenceRequestResponse { account_number: sequence.account_number, sequence: sequence.sequence, @@ -60,7 +60,7 @@ pub async fn broadcast( println!("balance after transaction: {after}"); println!("returning tx hash to sender"); - let success: bool = broadcast_res.deliver_tx.code.is_ok(); + let success: bool = broadcast_res.deliver_tx.code.is_ok(); Ok(crate::BroadcastResponse { tx_hash: serde_json::to_string(&broadcast_res.hash).unwrap(),