share status output

This commit is contained in:
wiesche
2026-09-12 19:31:22 +02:00
parent 24df4f4f29
commit b648b65024
3 changed files with 14 additions and 20 deletions
+2 -10
View File
@@ -686,14 +686,6 @@ fn slatepack_recipient(dest: Option<&str>) -> Result<Option<SlatepackAddress>, E
.map_err(Error::from) .map_err(Error::from)
} }
fn print_contract_status(message: &str, as_json: bool) {
if as_json {
eprintln!("{}", message);
} else {
println!("{}", message);
}
}
pub fn print_slatepack<L, C, K>( pub fn print_slatepack<L, C, K>(
api: &mut Owner<L, C, K>, api: &mut Owner<L, C, K>,
keychain_mask: Option<&SecretKey>, keychain_mask: Option<&SecretKey>,
@@ -1914,7 +1906,7 @@ where
K: keychain::Keychain + 'static, K: keychain::Keychain + 'static,
{ {
let recipient = slatepack_recipient(args.counterparty_addr.as_deref())?; let recipient = slatepack_recipient(args.counterparty_addr.as_deref())?;
print_contract_status("Paste slatepack:", args.as_json); display::print_status("Paste slatepack:", args.as_json);
let slatepack_msg = read_slatepack(&mut io::stdin().lock()) let slatepack_msg = read_slatepack(&mut io::stdin().lock())
.map_err(|e| libwallet::Error::GenericError(format!("Failed to read from stdin: {}", e)))?; .map_err(|e| libwallet::Error::GenericError(format!("Failed to read from stdin: {}", e)))?;
let (slate, sender, _) = let (slate, sender, _) =
@@ -1940,7 +1932,7 @@ where
if args.as_json { if args.as_json {
slate_out.print(true); slate_out.print(true);
} }
print_contract_status("Transaction was broadcasted.", args.as_json); display::print_status("Transaction was broadcasted.", args.as_json);
} else { } else {
slate_out.print(args.as_json); slate_out.print(args.as_json);
} }
+9
View File
@@ -26,6 +26,15 @@ use prettytable;
use std::io::prelude::Write; use std::io::prelude::Write;
use term; use term;
/// Print a status message to stdout or stderr
pub fn print_status(message: &str, stderr: bool) {
if stderr {
eprintln!("{}", message);
} else {
println!("{}", message);
}
}
/// Display outputs in a pretty way /// Display outputs in a pretty way
pub fn outputs( pub fn outputs(
account: &str, account: &str,
+3 -10
View File
@@ -15,6 +15,7 @@
use crate::cmd::wallet_args; use crate::cmd::wallet_args;
use crate::config::GlobalWalletConfig; use crate::config::GlobalWalletConfig;
use clap::ArgMatches; use clap::ArgMatches;
use grin_wallet_controller::display;
use grin_wallet_libwallet::NodeClient; use grin_wallet_libwallet::NodeClient;
use semver::Version; use semver::Version;
use std::thread; use std::thread;
@@ -22,14 +23,6 @@ use std::time::Duration;
const MIN_COMPAT_NODE_VERSION: &str = "4.0.0-alpha.1"; const MIN_COMPAT_NODE_VERSION: &str = "4.0.0-alpha.1";
fn print_status(message: &str, stderr: bool) {
if stderr {
eprintln!("{}", message);
} else {
println!("{}", message);
}
}
pub fn wallet_command<C>( pub fn wallet_command<C>(
wallet_args: &ArgMatches<'_>, wallet_args: &ArgMatches<'_>,
config: GlobalWalletConfig, config: GlobalWalletConfig,
@@ -73,10 +66,10 @@ where
thread::sleep(Duration::from_millis(100)); thread::sleep(Duration::from_millis(100));
if let Err(e) = res { if let Err(e) = res {
print_status(&format!("Wallet command failed: {}", e), json_output); display::print_status(&format!("Wallet command failed: {}", e), json_output);
1 1
} else { } else {
print_status( display::print_status(
&format!( &format!(
"Command '{}' completed successfully", "Command '{}' completed successfully",
wallet_args.subcommand().0 wallet_args.subcommand().0