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

Commit 80ae23b

Browse files
committed
update Config::pubkey_or_default
1 parent 111440b commit 80ae23b

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

token/cli/src/clap_app.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use {
44
},
55
solana_clap_v3_utils::{
66
fee_payer::fee_payer_arg,
7-
input_parsers::Amount,
7+
input_parsers::{signer::SignerSourceParserBuilder, Amount},
88
input_validators::{is_pubkey, is_url_or_moniker, is_valid_pubkey, is_valid_signer},
99
memo::memo_arg,
1010
nonce::*,
@@ -280,6 +280,17 @@ pub fn owner_address_arg<'a>() -> Arg<'a> {
280280
.help(OWNER_ADDRESS_ARG.help)
281281
}
282282

283+
// Temporary function that uses proper parsing to minimize commit size
284+
// TODO: use this to replace `owner_address_arg`
285+
pub fn owner_address_arg_temp<'a>() -> Arg<'a> {
286+
Arg::with_name(OWNER_ADDRESS_ARG.name)
287+
.long(OWNER_ADDRESS_ARG.long)
288+
.takes_value(true)
289+
.value_name("OWNER_ADDRESS")
290+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
291+
.help(OWNER_ADDRESS_ARG.help)
292+
}
293+
283294
pub fn owner_keypair_arg_with_value_name<'a>(value_name: &'static str) -> Arg<'a> {
284295
Arg::with_name(OWNER_KEYPAIR_ARG.name)
285296
.long(OWNER_KEYPAIR_ARG.long)
@@ -1226,7 +1237,7 @@ pub fn app<'a>(
12261237
"Lock the owner of this token account from ever being changed"
12271238
),
12281239
)
1229-
.arg(owner_address_arg())
1240+
.arg(owner_address_arg_temp())
12301241
.nonce_args(true)
12311242
)
12321243
.subcommand(
@@ -1757,7 +1768,7 @@ pub fn app<'a>(
17571768
.arg(
17581769
Arg::with_name("recipient")
17591770
.long("recipient")
1760-
.validator(|s| is_valid_pubkey(s))
1771+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
17611772
.value_name("REFUND_ACCOUNT_ADDRESS")
17621773
.takes_value(true)
17631774
.help("The address of the account to receive remaining SOL [default: --owner]"),
@@ -1805,7 +1816,7 @@ pub fn app<'a>(
18051816
.arg(
18061817
Arg::with_name("recipient")
18071818
.long("recipient")
1808-
.validator(|s| is_valid_pubkey(s))
1819+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
18091820
.value_name("REFUND_ACCOUNT_ADDRESS")
18101821
.takes_value(true)
18111822
.help("The address of the account to receive remaining SOL [default: --owner]"),
@@ -1832,17 +1843,17 @@ pub fn app<'a>(
18321843
.about("Get token account balance")
18331844
.arg(
18341845
Arg::with_name("token")
1835-
.validator(|s| is_valid_pubkey(s))
1846+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
18361847
.value_name("TOKEN_MINT_ADDRESS")
18371848
.takes_value(true)
18381849
.index(1)
18391850
.required_unless("address")
18401851
.help("Token of associated account. To query a specific account, use the `--address` parameter instead"),
18411852
)
1842-
.arg(owner_address_arg().conflicts_with("address"))
1853+
.arg(owner_address_arg_temp().conflicts_with("address"))
18431854
.arg(
18441855
Arg::with_name("address")
1845-
.validator(|s| is_valid_pubkey(s))
1856+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
18461857
.value_name("TOKEN_ACCOUNT_ADDRESS")
18471858
.takes_value(true)
18481859
.long("address")
@@ -1903,7 +1914,7 @@ pub fn app<'a>(
19031914
"Print token account addresses only"
19041915
),
19051916
)
1906-
.arg(owner_address_arg())
1917+
.arg(owner_address_arg_temp())
19071918
)
19081919
.subcommand(
19091920
SubCommand::with_name(CommandName::Address.into())
@@ -1919,7 +1930,7 @@ pub fn app<'a>(
19191930
[Default: return the client keypair address]")
19201931
)
19211932
.arg(
1922-
owner_address_arg()
1933+
owner_address_arg_temp()
19231934
.requires("token")
19241935
.help("Return the associated token address for the given owner. \
19251936
[Default: return the associated token address for the client keypair]"),
@@ -1931,7 +1942,7 @@ pub fn app<'a>(
19311942
.setting(AppSettings::Hidden)
19321943
.arg(
19331944
Arg::with_name("token")
1934-
.validator(|s| is_valid_pubkey(s))
1945+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
19351946
.value_name("TOKEN_MINT_ADDRESS")
19361947
.takes_value(true)
19371948
.index(1)
@@ -2026,7 +2037,7 @@ pub fn app<'a>(
20262037
.about("Enable required transfer memos for token account")
20272038
.arg(
20282039
Arg::with_name("account")
2029-
.validator(|s| is_valid_pubkey(s))
2040+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
20302041
.value_name("TOKEN_ACCOUNT_ADDRESS")
20312042
.takes_value(true)
20322043
.index(1)
@@ -2044,7 +2055,7 @@ pub fn app<'a>(
20442055
.about("Disable required transfer memos for token account")
20452056
.arg(
20462057
Arg::with_name("account")
2047-
.validator(|s| is_valid_pubkey(s))
2058+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
20482059
.value_name("TOKEN_ACCOUNT_ADDRESS")
20492060
.takes_value(true)
20502061
.index(1)
@@ -2062,7 +2073,7 @@ pub fn app<'a>(
20622073
.about("Enable CPI Guard for token account")
20632074
.arg(
20642075
Arg::with_name("account")
2065-
.validator(|s| is_valid_pubkey(s))
2076+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
20662077
.value_name("TOKEN_ACCOUNT_ADDRESS")
20672078
.takes_value(true)
20682079
.index(1)
@@ -2080,7 +2091,7 @@ pub fn app<'a>(
20802091
.about("Disable CPI Guard for token account")
20812092
.arg(
20822093
Arg::with_name("account")
2083-
.validator(|s| is_valid_pubkey(s))
2094+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
20842095
.value_name("TOKEN_ACCOUNT_ADDRESS")
20852096
.takes_value(true)
20862097
.index(1)
@@ -2355,15 +2366,15 @@ pub fn app<'a>(
23552366
.about("Withdraw lamports from a Token Program owned account")
23562367
.arg(
23572368
Arg::with_name("from")
2358-
.validator(|s| is_valid_pubkey(s))
2369+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
23592370
.value_name("SOURCE_ACCOUNT_ADDRESS")
23602371
.takes_value(true)
23612372
.required(true)
23622373
.help("Specify the address of the account to recover lamports from"),
23632374
)
23642375
.arg(
23652376
Arg::with_name("recipient")
2366-
.validator(|s| is_valid_pubkey(s))
2377+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
23672378
.value_name("REFUND_ACCOUNT_ADDRESS")
23682379
.takes_value(true)
23692380
.required(true)

token/cli/src/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG},
33
clap::ArgMatches,
44
solana_clap_v3_utils::{
5-
input_parsers::pubkey_of_signer,
5+
input_parsers::{pubkey_of_signer, signer::SignerSource},
66
input_validators::normalize_to_url_if_moniker,
77
keypair::SignerFromPathConfig,
88
nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG},
@@ -398,7 +398,7 @@ impl<'a> Config<'a> {
398398
override_name: &str,
399399
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
400400
) -> Result<Pubkey, Error> {
401-
let token = pubkey_of_signer(arg_matches, "token", wallet_manager)
401+
let token = SignerSource::try_get_pubkey(arg_matches, "token", wallet_manager)
402402
.map_err(|e| -> Error { e.to_string().into() })?;
403403
self.associated_token_address_for_token_or_override(
404404
arg_matches,
@@ -449,8 +449,9 @@ impl<'a> Config<'a> {
449449
address_name: &str,
450450
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
451451
) -> Result<Pubkey, Error> {
452-
if let Some(address) = pubkey_of_signer(arg_matches, address_name, wallet_manager)
453-
.map_err(|e| -> Error { e.to_string().into() })?
452+
if let Some(address) =
453+
SignerSource::try_get_pubkey(arg_matches, address_name, wallet_manager)
454+
.map_err(|e| -> Error { e.to_string().into() })?
454455
{
455456
return Ok(address);
456457
}

0 commit comments

Comments
 (0)