* working on error propogation
* better comments
This commit is contained in:
@@ -26,12 +26,11 @@ async fn main() -> anyhow::Result<()> {
|
||||
"\nincoming sequence request details:\nsigner address: {} \nquerying Nyx blockchain on behalf of requesting client",
|
||||
request.signer_address
|
||||
);
|
||||
// query Nyx chain for sequence information on behalf of request sender
|
||||
// query chain for sequence information on behalf of request sender
|
||||
let sequence: SequenceRequestResponse =
|
||||
get_sequence(broadcaster.clone(), request.signer_address)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("sequence information query returned account number: {}, sequence:{}, chain id: {} \nsending response to requesting client via mixnet", sequence.account_number, sequence.sequence, sequence.chain_id);
|
||||
.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
|
||||
.send_str_reply(return_recipient, &serde_json::to_string(&sequence).unwrap())
|
||||
@@ -45,8 +44,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
|
||||
.unwrap();
|
||||
.await?;
|
||||
println!("return recipient surb bucket: {}", &return_recipient);
|
||||
// send response to tx (transaction hash) back to request sender via mixnet
|
||||
client
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::DEFAULT_VALIDATOR_RPC;
|
||||
use bs58;
|
||||
use cosmrs::rpc::{Client, HttpClient};
|
||||
use cosmrs::{tendermint, AccountId};
|
||||
use nym_validator_client::nyxd::CosmWasmClient;
|
||||
use nym_validator_client::nyxd::{CosmWasmClient,error::NyxdError};
|
||||
|
||||
pub async fn create_broadcaster() -> HttpClient {
|
||||
let broadcaster: HttpClient = HttpClient::new(DEFAULT_VALIDATOR_RPC).unwrap();
|
||||
@@ -12,10 +12,10 @@ pub async fn create_broadcaster() -> HttpClient {
|
||||
pub async fn get_sequence(
|
||||
broadcaster: HttpClient,
|
||||
signer_address: AccountId,
|
||||
) -> Result<crate::SequenceRequestResponse, std::io::Error> {
|
||||
) -> Result<crate::SequenceRequestResponse, NyxdError> {
|
||||
// get signer information
|
||||
let sequence = broadcaster.get_sequence(&signer_address).await.unwrap();
|
||||
let chain_id: tendermint::chain::Id = broadcaster.get_chain_id().await.unwrap();
|
||||
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,
|
||||
@@ -41,7 +41,7 @@ pub async fn broadcast(
|
||||
.unwrap();
|
||||
|
||||
// broadcast the tx
|
||||
println!("broadcasting the tx to Nyx blockchain");
|
||||
println!("broadcasting tx to validator");
|
||||
let broadcast_res = Client::broadcast_tx_commit(&broadcaster, tx_bytes.into())
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -60,7 +60,7 @@ pub async fn broadcast(
|
||||
println!("balance after transaction: {after}");
|
||||
println!("returning tx hash to sender");
|
||||
|
||||
let success: bool = after.amount < before.amount;
|
||||
let success: bool = broadcast_res.deliver_tx.code.is_ok();
|
||||
|
||||
Ok(crate::BroadcastResponse {
|
||||
tx_hash: serde_json::to_string(&broadcast_res.hash).unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user