Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename output module to print. #1530

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function fund_all() {
exe eval "./soroban keys fund root"
}
function deploy() {
exe eval "(./soroban contract deploy --source root --wasm $1 --ignore-checks) > $2"
exe eval "(./soroban contract deploy --quiet --source root --wasm $1 --ignore-checks) > $2"
}
function deploy_all() {
deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt
Expand Down
20 changes: 10 additions & 10 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
output::Output,
print::Print,
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -165,7 +165,7 @@ impl NetworkRunnable for Cmd {
global_args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<TxnResult<String>, Error> {
let output = Output::new(global_args.map_or(false, |a| a.quiet));
let print = Print::new(global_args.map_or(false, |a| a.quiet));
let config = config.unwrap_or(&self.config);
let wasm_hash = if let Some(wasm) = &self.wasm {
let hash = if self.fee.build_only || self.fee.sim_only {
Expand Down Expand Up @@ -197,7 +197,7 @@ impl NetworkRunnable for Cmd {
}
})?);

output.info(format!("Using wasm hash {wasm_hash}").as_str());
print.info(format!("Using wasm hash {wasm_hash}").as_str());

let network = config.get_network()?;
let salt: [u8; 32] = match &self.salt {
Expand Down Expand Up @@ -230,22 +230,22 @@ impl NetworkRunnable for Cmd {
)?;

if self.fee.build_only {
output.check("Transaction built!");
print.check("Transaction built!");
return Ok(TxnResult::Txn(txn));
}

output.info("Simulating deploy transaction…");
print.info("Simulating deploy transaction…");

let txn = client.simulate_and_assemble_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn).transaction().clone();

if self.fee.sim_only {
output.check("Done!");
print.check("Done!");
return Ok(TxnResult::Txn(txn));
}

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

let get_txn_resp = client
.send_transaction_polling(&config.sign_with_local_key(txn).await?)
Expand All @@ -259,10 +259,10 @@ impl NetworkRunnable for Cmd {
let contract_id = stellar_strkey::Contract(contract_id.0).to_string();

if let Some(url) = utils::explorer_url_for_contract(&network, &contract_id) {
output.link(url);
print.link(url);
}

output.check("Deployed!");
print.check("Deployed!");

Ok(TxnResult::Res(contract_id))
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::commands::txn_result::{TxnEnvelopeResult, TxnResult};
use crate::commands::{global, NetworkRunnable};
use crate::config::{self, data, network};
use crate::key;
use crate::output::Output;
use crate::print::Print;
use crate::rpc::{self, Client};
use crate::{utils, wasm};

Expand Down Expand Up @@ -96,7 +96,7 @@ impl NetworkRunnable for Cmd {
args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<TxnResult<Hash>, Error> {
let output = Output::new(args.map_or(false, |a| a.quiet));
let print = Print::new(args.map_or(false, |a| a.quiet));
let config = config.unwrap_or(&self.config);
let contract = self.wasm.read()?;
let network = config.get_network()?;
Expand Down Expand Up @@ -163,7 +163,7 @@ impl NetworkRunnable for Cmd {
// Skip reupload if this isn't V0 because V1 extension already
// exists.
if code.ext.ne(&ContractCodeEntryExt::V0) {
output.info("Skipping install because wasm already installed");
print.info("Skipping install because wasm already installed");
return Ok(TxnResult::Res(hash));
}
}
Expand All @@ -175,7 +175,7 @@ impl NetworkRunnable for Cmd {
}
}

output.info("Simulating install transaction…");
print.info("Simulating install transaction…");

let txn = client
.simulate_and_assemble_transaction(&tx_without_preflight)
Expand All @@ -186,7 +186,7 @@ impl NetworkRunnable for Cmd {
return Ok(TxnResult::Txn(txn));
}

output.globe("Submitting install transaction…");
print.globe("Submitting install transaction…");

let txn_resp = client
.send_transaction_polling(&self.config.sign_with_local_key(txn).await?)
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod fee;
pub mod get_spec;
pub mod key;
pub mod log;
pub mod output;
pub mod print;
pub mod signer;
pub mod toid;
pub mod utils;
Expand Down
63 changes: 0 additions & 63 deletions cmd/soroban-cli/src/output.rs

This file was deleted.

70 changes: 70 additions & 0 deletions cmd/soroban-cli/src/print.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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 Print {
pub quiet: bool,
}

impl Print {
pub fn new(quiet: bool) -> Print {
Print { quiet }
}

/// # 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.infoln(format!("Transaction hash is {hash}").as_str());

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

Ok(())
}
}

macro_rules! create_print_functions {
($name:ident, $nameln:ident, $icon:expr) => {
impl Print {
#[allow(dead_code)]
pub fn $name<T: Display + Sized>(&self, message: T) {
if !self.quiet {
print!("{} {}", $icon, message);
}
}

#[allow(dead_code)]
pub fn $nameln<T: Display + Sized>(&self, message: T) {
if !self.quiet {
println!("{} {}", $icon, message);
}
}
}
};
}

create_print_functions!(bucket, bucketln, "🪣");
create_print_functions!(check, checkln, "✅");
create_print_functions!(error, errorln, "❌");
create_print_functions!(globe, globeln, "🌎");
create_print_functions!(info, infoln, "ℹ️");
create_print_functions!(link, linkln, "🔗");
create_print_functions!(save, saveln, "💾");
create_print_functions!(search, searchln, "🔎");
Loading