token-cli: modernize multisig display
This commit is contained in:
parent
c0ef1f95ef
commit
bdc3087533
|
@ -1643,17 +1643,25 @@ async fn command_account_info(config: &Config<'_>, address: Pubkey) -> CommandRe
|
|||
Ok(config.output_format.formatted_string(&cli_token_account))
|
||||
}
|
||||
|
||||
async fn get_multisig(config: &Config<'_>, address: &Pubkey) -> Result<Multisig, Error> {
|
||||
let account = config.rpc_client.get_account(address).await?;
|
||||
Multisig::unpack(&account.data).map_err(|e| e.into())
|
||||
}
|
||||
async fn command_display(config: &Config<'_>, address: Pubkey) -> CommandResult {
|
||||
let account = config.get_account_checked(&address).await?;
|
||||
|
||||
async fn command_multisig(config: &Config<'_>, address: Pubkey) -> CommandResult {
|
||||
let multisig = get_multisig(config, &address).await?;
|
||||
let cli_output = if let Ok(multisig) = Multisig::unpack(&account.data) {
|
||||
let n = multisig.n as usize;
|
||||
assert!(n <= multisig.signers.len());
|
||||
let cli_multisig = CliMultisig {
|
||||
|
||||
if n > multisig.signers.len() {
|
||||
return Err(format!(
|
||||
"Multisig {} malformed: {} signers required, but only {} declared",
|
||||
address,
|
||||
n,
|
||||
multisig.signers.len()
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
CliMultisig {
|
||||
address: address.to_string(),
|
||||
program_id: config.program_id.to_string(),
|
||||
m: multisig.m,
|
||||
n: multisig.n,
|
||||
signers: multisig
|
||||
|
@ -1668,8 +1676,12 @@ async fn command_multisig(config: &Config<'_>, address: Pubkey) -> CommandResult
|
|||
}
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
} else {
|
||||
panic!("unimplemented");
|
||||
};
|
||||
Ok(config.output_format.formatted_string(&cli_multisig))
|
||||
|
||||
Ok(config.output_format.formatted_string(&cli_output))
|
||||
}
|
||||
|
||||
async fn command_gc(
|
||||
|
@ -2723,7 +2735,8 @@ fn app<'a, 'b>(
|
|||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name(CommandName::AccountInfo.into())
|
||||
.about("Query details of an SPL Token account by address")
|
||||
.about("Query details of an SPL Token account by address (DEPRECATED: use `spl-token display`)")
|
||||
.setting(AppSettings::Hidden)
|
||||
.arg(
|
||||
Arg::with_name("token")
|
||||
.validator(is_valid_pubkey)
|
||||
|
@ -2755,7 +2768,8 @@ fn app<'a, 'b>(
|
|||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name(CommandName::MultisigInfo.into())
|
||||
.about("Query details about and SPL Token multisig account by address")
|
||||
.about("Query details about and SPL Token multisig account by address (DEPRECATED: use `spl-token display`)")
|
||||
.setting(AppSettings::Hidden)
|
||||
.arg(
|
||||
Arg::with_name("address")
|
||||
.validator(is_valid_pubkey)
|
||||
|
@ -3284,7 +3298,7 @@ async fn process_command<'a>(
|
|||
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
command_multisig(config, address).await
|
||||
command_display(config, address).await
|
||||
}
|
||||
(CommandName::Gc, arg_matches) => {
|
||||
match config.output_format {
|
||||
|
|
|
@ -148,6 +148,7 @@ impl fmt::Display for CliWalletAddress {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct CliMultisig {
|
||||
pub(crate) address: String,
|
||||
pub(crate) program_id: String,
|
||||
pub(crate) m: u8,
|
||||
pub(crate) n: u8,
|
||||
pub(crate) signers: Vec<String>,
|
||||
|
@ -159,7 +160,9 @@ impl VerboseDisplay for CliMultisig {}
|
|||
impl fmt::Display for CliMultisig {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f)?;
|
||||
writeln_name_value(f, "Type:", "Multisig")?;
|
||||
writeln_name_value(f, "Address:", &self.address)?;
|
||||
writeln_name_value(f, "Program:", &self.program_id)?;
|
||||
writeln_name_value(f, "M/N:", &format!("{}/{}", self.m, self.n))?;
|
||||
writeln_name_value(f, "Signers:", " ")?;
|
||||
let width = if self.n >= 9 { 4 } else { 3 };
|
||||
|
|
Loading…
Reference in New Issue