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

Commit 58e0441

Browse files
committed
update Config::new_with_clients_and_ws_url to parse owner from source
1 parent 76f5da8 commit 58e0441

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

token/cli/src/clap_app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub fn owner_keypair_arg_with_value_name<'a>(value_name: &'static str) -> Arg<'a
298298
.long(OWNER_KEYPAIR_ARG.long)
299299
.takes_value(true)
300300
.value_name(value_name)
301-
.validator(|s| is_valid_signer(s))
301+
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
302302
.help(OWNER_KEYPAIR_ARG.help)
303303
}
304304

@@ -1798,7 +1798,7 @@ pub fn app<'a>(
17981798
.help("Specify the token account to close \
17991799
[default: owner's associated token account]"),
18001800
)
1801-
.arg(owner_address_arg())
1801+
.arg(owner_address_arg_temp())
18021802
.arg(multisig_signer_arg())
18031803
.nonce_args(true)
18041804
.offline_args(),
@@ -2382,7 +2382,7 @@ pub fn app<'a>(
23822382
.required(true)
23832383
.help("Specify the address of the account to send lamports to"),
23842384
)
2385-
.arg(owner_address_arg())
2385+
.arg(owner_address_arg_temp())
23862386
.arg(multisig_signer_arg())
23872387
)
23882388
.subcommand(

token/cli/src/command.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use {
66
config::{Config, MintInfo},
77
encryption_keypair::*,
88
output::*,
9+
print_error_and_exit,
910
sort::{sort_and_parse_token_accounts, AccountFilter},
1011
},
1112
clap::{value_t, value_t_or_exit, ArgMatches},
@@ -79,11 +80,6 @@ use {
7980
std::{collections::HashMap, fmt::Display, process::exit, rc::Rc, str::FromStr, sync::Arc},
8081
};
8182

82-
fn print_error_and_exit<T, E: Display>(e: E) -> T {
83-
eprintln!("error: {}", e);
84-
exit(1)
85-
}
86-
8783
fn amount_to_raw_amount(amount: Amount, decimals: u8, all_amount: Option<u64>, name: &str) -> u64 {
8884
match amount {
8985
Amount::Raw(ui_amount) => ui_amount,

token/cli/src/config.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use {
2-
crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG},
2+
crate::{
3+
clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG},
4+
print_error_and_exit,
5+
},
36
clap::ArgMatches,
47
solana_clap_v3_utils::{
5-
input_parsers::{pubkey_of_signer, signer::SignerSource},
8+
input_parsers::{
9+
pubkey_of_signer,
10+
signer::{SignerSource, SignerSourceKind},
11+
},
612
input_validators::normalize_to_url_if_moniker,
713
keypair::SignerFromPathConfig,
814
nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG},
@@ -181,23 +187,23 @@ impl<'a> Config<'a> {
181187
};
182188

183189
let default_keypair = cli_config.keypair_path.clone();
184-
190+
let default_keypair_source =
191+
SignerSource::parse(&default_keypair).unwrap_or_else(print_error_and_exit);
185192
let default_signer: Option<Arc<dyn Signer>> = {
186-
if let Some(owner_path) = matches.try_get_one::<String>("owner").ok().flatten() {
187-
signer_from_path_with_config(matches, owner_path, "owner", wallet_manager, &config)
193+
if let Some(source) = matches.try_get_one::<SignerSource>("owner").ok().flatten() {
194+
signer_from_source_with_config(matches, source, "owner", wallet_manager, &config)
188195
.ok()
189196
} else {
190-
signer_from_path_with_config(
197+
signer_from_source_with_config(
191198
matches,
192-
&default_keypair,
199+
&default_keypair_source,
193200
"default",
194201
wallet_manager,
195202
&config,
196203
)
197204
.map_err(|e| {
198205
if std::fs::metadata(&default_keypair).is_ok() {
199-
eprintln!("error: {}", e);
200-
exit(1);
206+
print_error_and_exit(e)
201207
} else {
202208
e
203209
}
@@ -616,3 +622,30 @@ fn signer_from_path_with_config(
616622
config,
617623
)
618624
}
625+
626+
/// A wrapper function around the `solana_clap_v3_utils` `signer_from_source
627+
/// with_config` function. If the signer source is a pubkey, then it checks for
628+
/// signing-only or if null signer is allowed and creates a null signer.
629+
/// Otherwise, it invokes the `solana_clap_v3_utils` version of the function.
630+
fn signer_from_source_with_config(
631+
matches: &ArgMatches,
632+
source: &SignerSource,
633+
keypair_name: &str,
634+
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
635+
config: &SignerFromPathConfig,
636+
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
637+
if let SignerSourceKind::Pubkey(pubkey) = source.kind {
638+
if matches.try_contains_id(SIGNER_ARG.name).is_err()
639+
&& (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?)
640+
{
641+
return Ok(Box::new(NullSigner::new(&pubkey)));
642+
}
643+
}
644+
solana_clap_v3_utils::keypair::signer_from_source_with_config(
645+
matches,
646+
source,
647+
keypair_name,
648+
wallet_manager,
649+
config,
650+
)
651+
}

token/cli/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ pub mod config;
55
mod encryption_keypair;
66
mod output;
77
mod sort;
8+
9+
fn print_error_and_exit<T, E: std::fmt::Display>(e: E) -> T {
10+
eprintln!("error: {}", e);
11+
std::process::exit(1)
12+
}

0 commit comments

Comments
 (0)