spl-token: provide more useful output when using create-token with the output option and small redesign of token cli architecture (#2593)
* spl-token: WIP * Remove and_then, move tx handling in separate function- output handling still missing * spl-token: add basic output handling for all calls, add detailed output to create-token * spl-token: remove changes in bench that are not strictly necessary to remove # of files touched in this PR * [spl-token] cli: HandleTxReturn is now TransactionReturnData * [spl-token] cli: Make commands return output String that is printed in fn main() * [spl-token] cli: remove old todos * [spl-token] cli: only use no_wait arg in command_transfer and use constant for "create-token"
This commit is contained in:
parent
f83240a868
commit
7393f1de43
|
@ -1,3 +1,5 @@
|
|||
use crate::CommandResult;
|
||||
|
||||
/// The `bench` subcommand
|
||||
use {
|
||||
crate::{
|
||||
|
@ -165,7 +167,7 @@ pub(crate) fn bench_process_command(
|
|||
config: &Config,
|
||||
mut signers: Vec<Box<dyn Signer>>,
|
||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||
) -> Result<(), Error> {
|
||||
) -> CommandResult {
|
||||
assert!(!config.sign_only);
|
||||
|
||||
match matches.subcommand() {
|
||||
|
@ -229,7 +231,7 @@ pub(crate) fn bench_process_command(
|
|||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok("".to_string())
|
||||
}
|
||||
|
||||
fn get_token_address_with_seed(token: &Pubkey, owner: &Pubkey, i: usize) -> (Pubkey, String) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,10 +3,50 @@ use console::Emoji;
|
|||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use solana_account_decoder::parse_token::{UiAccountState, UiTokenAccount, UiTokenAmount};
|
||||
use solana_cli_output::{display::writeln_name_value, OutputFormat, QuietDisplay, VerboseDisplay};
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
pub(crate) trait Output: Serialize + fmt::Display + QuietDisplay + VerboseDisplay {}
|
||||
|
||||
static WARNING: Emoji = Emoji("⚠️", "!");
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct CommandOutput<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
pub(crate) command_name: String,
|
||||
pub(crate) command_output: T,
|
||||
}
|
||||
|
||||
impl<T> Display for CommandOutput<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.command_output, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> QuietDisplay for CommandOutput<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||
QuietDisplay::write_str(&self.command_output, w)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> VerboseDisplay for CommandOutput<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||
writeln_name_value(w, "Command: ", &self.command_name)?;
|
||||
VerboseDisplay::write_str(&self.command_output, w)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn println_display(config: &Config, message: String) {
|
||||
match config.output_format {
|
||||
OutputFormat::Display | OutputFormat::DisplayVerbose => {
|
||||
|
@ -16,6 +56,51 @@ pub(crate) fn println_display(config: &Config, message: String) {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct CliMint<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
pub(crate) address: String,
|
||||
pub(crate) decimals: u8,
|
||||
pub(crate) transaction_data: T,
|
||||
}
|
||||
|
||||
impl<T> Display for CliMint<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f)?;
|
||||
writeln_name_value(f, "Address: ", &self.address)?;
|
||||
writeln_name_value(f, "Decimals: ", &format!("{}", self.decimals))?;
|
||||
Display::fmt(&self.transaction_data, f)
|
||||
}
|
||||
}
|
||||
impl<T> QuietDisplay for CliMint<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||
writeln!(w)?;
|
||||
writeln_name_value(w, "Address: ", &self.address)?;
|
||||
writeln_name_value(w, "Decimals: ", &format!("{}", self.decimals))?;
|
||||
QuietDisplay::write_str(&self.transaction_data, w)
|
||||
}
|
||||
}
|
||||
impl<T> VerboseDisplay for CliMint<T>
|
||||
where
|
||||
T: Serialize + Display + QuietDisplay + VerboseDisplay,
|
||||
{
|
||||
fn write_str(&self, w: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||
writeln!(w)?;
|
||||
writeln_name_value(w, "Address: ", &self.address)?;
|
||||
writeln_name_value(w, "Decimals: ", &format!("{}", self.decimals))?;
|
||||
VerboseDisplay::write_str(&self.transaction_data, w)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct CliTokenAmount {
|
||||
|
|
Loading…
Reference in New Issue