cli-output: Add CliTokenAccount type
This commit is contained in:
parent
bb144bf758
commit
d95bce2600
|
@ -3580,6 +3580,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"solana-account-decoder",
|
||||
"solana-clap-utils",
|
||||
"solana-client",
|
||||
"solana-sdk 1.4.0",
|
||||
|
|
|
@ -17,6 +17,7 @@ indicatif = "0.15.0"
|
|||
serde = "1.0.112"
|
||||
serde_derive = "1.0.103"
|
||||
serde_json = "1.0.56"
|
||||
solana-account-decoder = { path = "../account-decoder", version = "1.4.0" }
|
||||
solana-clap-utils = { path = "../clap-utils", version = "1.4.0" }
|
||||
solana-client = { path = "../client", version = "1.4.0" }
|
||||
solana-sdk = { path = "../sdk", version = "1.4.0" }
|
||||
|
|
|
@ -4,6 +4,7 @@ use console::{style, Emoji};
|
|||
use inflector::cases::titlecase::to_title_case;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
use solana_account_decoder::parse_token::UiTokenAccount;
|
||||
use solana_clap_utils::keypair::SignOnly;
|
||||
use solana_client::rpc_response::{
|
||||
RpcAccountBalance, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
|
||||
|
@ -1149,6 +1150,47 @@ impl fmt::Display for CliFees {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CliTokenAccount {
|
||||
pub address: String,
|
||||
#[serde(flatten)]
|
||||
pub token_account: UiTokenAccount,
|
||||
}
|
||||
|
||||
impl fmt::Display for CliTokenAccount {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f)?;
|
||||
writeln_name_value(f, "Address:", &self.address)?;
|
||||
let account = &self.token_account;
|
||||
writeln_name_value(
|
||||
f,
|
||||
"Balance:",
|
||||
&account.token_amount.real_number_string_trimmed(),
|
||||
)?;
|
||||
let mint = format!(
|
||||
"{}{}",
|
||||
account.mint,
|
||||
if account.is_native { " (native)" } else { "" }
|
||||
);
|
||||
writeln_name_value(f, "Mint:", &mint)?;
|
||||
writeln_name_value(f, "Owner:", &account.owner)?;
|
||||
writeln_name_value(f, "State:", &format!("{:?}", account.state))?;
|
||||
if let Some(delegate) = &account.delegate {
|
||||
writeln!(f, "Delegation:")?;
|
||||
writeln_name_value(f, " Delegate:", delegate)?;
|
||||
let allowance = account.delegated_amount.as_ref().unwrap();
|
||||
writeln_name_value(f, " Allowance:", &allowance.real_number_string_trimmed())?;
|
||||
}
|
||||
writeln_name_value(
|
||||
f,
|
||||
"Close authority:",
|
||||
&account.close_authority.as_ref().unwrap_or(&String::new()),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn return_signers(
|
||||
tx: &Transaction,
|
||||
output_format: &OutputFormat,
|
||||
|
|
Loading…
Reference in New Issue