Skip to content

Commit

Permalink
Move util function to output.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Aug 1, 2024
1 parent 6c503cd commit 76382f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl NetworkRunnable for Cmd {
}

output.globe("Submitting deploy transaction…");
utils::log_transaction(&output, &txn, &network, true)?;
output.log_transaction(&txn, &network, true)?;

let get_txn_resp = client
.send_transaction_polling(&config.sign_with_local_key(txn).await?)
Expand Down
30 changes: 30 additions & 0 deletions cmd/soroban-cli/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use std::fmt::Display;

use soroban_env_host::xdr::{Error as XdrError, Transaction};

use crate::{
config::network::Network,
utils::{explorer_url_for_transaction, transaction_hash},
};

pub struct Output {
pub quiet: bool,
}
Expand Down Expand Up @@ -30,4 +37,27 @@ impl Output {
pub fn link<T: Display>(&self, message: T) {
self.print("🔗", message);
}

/// # Errors
///
/// Might return an error
pub fn log_transaction(
&self,
tx: &Transaction,
network: &Network,
show_link: bool,
) -> Result<(), XdrError> {
let tx_hash = transaction_hash(tx, &network.network_passphrase)?;
let hash = hex::encode(tx_hash);

self.info(format!("Transaction hash is {hash}").as_str());

if show_link {
if let Some(url) = explorer_url_for_transaction(network, &hash) {
self.link(url);
}
}

Ok(())
}
}
25 changes: 1 addition & 24 deletions cmd/soroban-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use soroban_env_host::xdr::{

pub use soroban_spec_tools::contract as contract_spec;

use crate::{config::network::Network, output::Output};
use crate::config::network::Network;

/// # Errors
///
Expand Down Expand Up @@ -49,29 +49,6 @@ pub fn explorer_url_for_contract(network: &Network, contract_id: &str) -> Option
.map(|base_url| format!("{base_url}/contract/{contract_id}"))
}

/// # Errors
///
/// Might return an error
pub fn log_transaction(
output: &Output,
tx: &Transaction,
network: &Network,
show_link: bool,
) -> Result<(), XdrError> {
let tx_hash = transaction_hash(tx, &network.network_passphrase)?;
let hash = hex::encode(tx_hash);

output.info(format!("Transaction hash is {hash}").as_str());

if show_link {
if let Some(url) = explorer_url_for_transaction(network, &hash) {
output.link(url);
}
}

Ok(())
}

/// # Errors
///
/// Might return an error
Expand Down

0 comments on commit 76382f4

Please sign in to comment.