Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 04fc247

Browse files
Reorder App subcommands (#1485)
1 parent bb05462 commit 04fc247

File tree

1 file changed

+117
-117
lines changed

1 file changed

+117
-117
lines changed

token/cli/src/main.rs

Lines changed: 117 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,59 @@ fn command_accounts(config: &Config, token: Option<Pubkey>) -> CommandResult {
962962
Ok(None)
963963
}
964964

965+
fn command_account_info(config: &Config, address: Pubkey) -> CommandResult {
966+
let account = config.rpc_client.get_token_account(&address)?.unwrap();
967+
println!();
968+
println_name_value("Address:", &address.to_string());
969+
println_name_value(
970+
"Balance:",
971+
&account.token_amount.real_number_string_trimmed(),
972+
);
973+
let mint = format!(
974+
"{}{}",
975+
account.mint,
976+
if account.is_native { " (native)" } else { "" }
977+
);
978+
println_name_value("Mint:", &mint);
979+
println_name_value("Owner:", &account.owner);
980+
println_name_value("State:", &format!("{:?}", account.state));
981+
if let Some(delegate) = &account.delegate {
982+
println!("Delegation:");
983+
println_name_value(" Delegate:", delegate);
984+
let allowance = account.delegated_amount.as_ref().unwrap();
985+
println_name_value(" Allowance:", &allowance.real_number_string_trimmed());
986+
} else {
987+
println_name_value("Delegation:", "");
988+
}
989+
println_name_value(
990+
"Close authority:",
991+
&account.close_authority.as_ref().unwrap_or(&String::new()),
992+
);
993+
Ok(None)
994+
}
995+
996+
fn get_multisig(config: &Config, address: &Pubkey) -> Result<Multisig, Error> {
997+
let account = config.rpc_client.get_account(&address)?;
998+
Multisig::unpack(&account.data).map_err(|e| e.into())
999+
}
1000+
1001+
fn command_multisig(config: &Config, address: Pubkey) -> CommandResult {
1002+
let multisig = get_multisig(config, &address)?;
1003+
let n = multisig.n as usize;
1004+
assert!(n <= multisig.signers.len());
1005+
println!();
1006+
println_name_value("Address:", &address.to_string());
1007+
println_name_value("M/N:", &format!("{}/{}", multisig.m, n));
1008+
println_name_value("Signers:", " ");
1009+
let width = if n >= 9 { 4 } else { 3 };
1010+
for i in 0..n {
1011+
let title = format!("{1:>0$}:", width, i + 1);
1012+
let pubkey = &multisig.signers[i];
1013+
println_name_value(&title, &pubkey.to_string())
1014+
}
1015+
Ok(None)
1016+
}
1017+
9651018
fn command_gc(config: &Config) -> CommandResult {
9661019
println!("Fetching token accounts");
9671020
let accounts = config.rpc_client.get_token_accounts_by_owner(
@@ -1090,59 +1143,6 @@ fn command_gc(config: &Config) -> CommandResult {
10901143
Ok(Some((lamports_needed, instructions)))
10911144
}
10921145

1093-
fn command_account_info(config: &Config, address: Pubkey) -> CommandResult {
1094-
let account = config.rpc_client.get_token_account(&address)?.unwrap();
1095-
println!();
1096-
println_name_value("Address:", &address.to_string());
1097-
println_name_value(
1098-
"Balance:",
1099-
&account.token_amount.real_number_string_trimmed(),
1100-
);
1101-
let mint = format!(
1102-
"{}{}",
1103-
account.mint,
1104-
if account.is_native { " (native)" } else { "" }
1105-
);
1106-
println_name_value("Mint:", &mint);
1107-
println_name_value("Owner:", &account.owner);
1108-
println_name_value("State:", &format!("{:?}", account.state));
1109-
if let Some(delegate) = &account.delegate {
1110-
println!("Delegation:");
1111-
println_name_value(" Delegate:", delegate);
1112-
let allowance = account.delegated_amount.as_ref().unwrap();
1113-
println_name_value(" Allowance:", &allowance.real_number_string_trimmed());
1114-
} else {
1115-
println_name_value("Delegation:", "");
1116-
}
1117-
println_name_value(
1118-
"Close authority:",
1119-
&account.close_authority.as_ref().unwrap_or(&String::new()),
1120-
);
1121-
Ok(None)
1122-
}
1123-
1124-
fn get_multisig(config: &Config, address: &Pubkey) -> Result<Multisig, Error> {
1125-
let account = config.rpc_client.get_account(&address)?;
1126-
Multisig::unpack(&account.data).map_err(|e| e.into())
1127-
}
1128-
1129-
fn command_multisig(config: &Config, address: Pubkey) -> CommandResult {
1130-
let multisig = get_multisig(config, &address)?;
1131-
let n = multisig.n as usize;
1132-
assert!(n <= multisig.signers.len());
1133-
println!();
1134-
println_name_value("Address:", &address.to_string());
1135-
println_name_value("M/N:", &format!("{}/{}", multisig.m, n));
1136-
println_name_value("Signers:", " ");
1137-
let width = if n >= 9 { 4 } else { 3 };
1138-
for i in 0..n {
1139-
let title = format!("{1:>0$}:", width, i + 1);
1140-
let pubkey = &multisig.signers[i];
1141-
println_name_value(&title, &pubkey.to_string())
1142-
}
1143-
Ok(None)
1144-
}
1145-
11461146
struct SignOnlyNeedsFullMintSpec {}
11471147
impl offline::ArgsConfig for SignOnlyNeedsFullMintSpec {
11481148
fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> {
@@ -1529,44 +1529,6 @@ fn main() {
15291529
.nonce_args(true)
15301530
.offline_args_config(&SignOnlyNeedsMintAddress{}),
15311531
)
1532-
.subcommand(
1533-
SubCommand::with_name("balance")
1534-
.about("Get token account balance")
1535-
.arg(
1536-
Arg::with_name("address")
1537-
.validator(is_valid_pubkey)
1538-
.value_name("TOKEN_ACCOUNT_ADDRESS")
1539-
.takes_value(true)
1540-
.index(1)
1541-
.required(true)
1542-
.help("The token account address"),
1543-
),
1544-
)
1545-
.subcommand(
1546-
SubCommand::with_name("supply")
1547-
.about("Get token supply")
1548-
.arg(
1549-
Arg::with_name("address")
1550-
.validator(is_valid_pubkey)
1551-
.value_name("TOKEN_ADDRESS")
1552-
.takes_value(true)
1553-
.index(1)
1554-
.required(true)
1555-
.help("The token address"),
1556-
),
1557-
)
1558-
.subcommand(
1559-
SubCommand::with_name("accounts")
1560-
.about("List all token accounts by owner")
1561-
.arg(
1562-
Arg::with_name("token")
1563-
.validator(is_valid_pubkey)
1564-
.value_name("TOKEN_ADDRESS")
1565-
.takes_value(true)
1566-
.index(1)
1567-
.help("Limit results to the given token. [Default: list accounts for all tokens]"),
1568-
),
1569-
)
15701532
.subcommand(
15711533
SubCommand::with_name("wrap")
15721534
.about("Wrap native SOL in a SOL token account")
@@ -1598,32 +1560,6 @@ fn main() {
15981560
.nonce_args(true)
15991561
.offline_args(),
16001562
)
1601-
.subcommand(
1602-
SubCommand::with_name("account-info")
1603-
.about("Query details of an SPL Token account by address")
1604-
.arg(
1605-
Arg::with_name("address")
1606-
.validator(is_valid_pubkey)
1607-
.value_name("TOKEN_ACCOUNT_ADDRESS")
1608-
.takes_value(true)
1609-
.index(1)
1610-
.required(true)
1611-
.help("The address of the SPL Token account to query"),
1612-
),
1613-
)
1614-
.subcommand(
1615-
SubCommand::with_name("multisig-info")
1616-
.about("Query details about and SPL Token multisig account by address")
1617-
.arg(
1618-
Arg::with_name("address")
1619-
.validator(is_valid_pubkey)
1620-
.value_name("MULTISIG_ACCOUNT_ADDRESS")
1621-
.takes_value(true)
1622-
.index(1)
1623-
.required(true)
1624-
.help("The address of the SPL Token multisig account to query"),
1625-
),
1626-
)
16271563
.subcommand(
16281564
SubCommand::with_name("approve")
16291565
.about("Approve a delegate for a token account")
@@ -1700,6 +1636,70 @@ fn main() {
17001636
.nonce_args(true)
17011637
.offline_args(),
17021638
)
1639+
.subcommand(
1640+
SubCommand::with_name("balance")
1641+
.about("Get token account balance")
1642+
.arg(
1643+
Arg::with_name("address")
1644+
.validator(is_valid_pubkey)
1645+
.value_name("TOKEN_ACCOUNT_ADDRESS")
1646+
.takes_value(true)
1647+
.index(1)
1648+
.required(true)
1649+
.help("The token account address"),
1650+
),
1651+
)
1652+
.subcommand(
1653+
SubCommand::with_name("supply")
1654+
.about("Get token supply")
1655+
.arg(
1656+
Arg::with_name("address")
1657+
.validator(is_valid_pubkey)
1658+
.value_name("TOKEN_ADDRESS")
1659+
.takes_value(true)
1660+
.index(1)
1661+
.required(true)
1662+
.help("The token address"),
1663+
),
1664+
)
1665+
.subcommand(
1666+
SubCommand::with_name("accounts")
1667+
.about("List all token accounts by owner")
1668+
.arg(
1669+
Arg::with_name("token")
1670+
.validator(is_valid_pubkey)
1671+
.value_name("TOKEN_ADDRESS")
1672+
.takes_value(true)
1673+
.index(1)
1674+
.help("Limit results to the given token. [Default: list accounts for all tokens]"),
1675+
),
1676+
)
1677+
.subcommand(
1678+
SubCommand::with_name("account-info")
1679+
.about("Query details of an SPL Token account by address")
1680+
.arg(
1681+
Arg::with_name("address")
1682+
.validator(is_valid_pubkey)
1683+
.value_name("TOKEN_ACCOUNT_ADDRESS")
1684+
.takes_value(true)
1685+
.index(1)
1686+
.required(true)
1687+
.help("The address of the SPL Token account to query"),
1688+
),
1689+
)
1690+
.subcommand(
1691+
SubCommand::with_name("multisig-info")
1692+
.about("Query details about and SPL Token multisig account by address")
1693+
.arg(
1694+
Arg::with_name("address")
1695+
.validator(is_valid_pubkey)
1696+
.value_name("MULTISIG_ACCOUNT_ADDRESS")
1697+
.takes_value(true)
1698+
.index(1)
1699+
.required(true)
1700+
.help("The address of the SPL Token multisig account to query"),
1701+
),
1702+
)
17031703
.subcommand(
17041704
SubCommand::with_name("gc")
17051705
.about("Cleanup unnecessary token accounts")

0 commit comments

Comments
 (0)