From 89cab470114ce7a33a0310843fad7241c52e94fa Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Mon, 21 Sep 2020 18:12:52 -0600 Subject: [PATCH] Move CLI fee payer arg into clap-utils --- clap-utils/src/fee_payer.rs | 19 +++++++++++++++++++ clap-utils/src/lib.rs | 1 + cli/src/cli.rs | 27 ++++++++------------------- cli/src/stake.rs | 13 ++++++++++--- stake-accounts/src/arg_parser.rs | 8 +------- 5 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 clap-utils/src/fee_payer.rs diff --git a/clap-utils/src/fee_payer.rs b/clap-utils/src/fee_payer.rs new file mode 100644 index 000000000..4031ab4e8 --- /dev/null +++ b/clap-utils/src/fee_payer.rs @@ -0,0 +1,19 @@ +use crate::{input_validators, ArgConstant}; +use clap::Arg; + +pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant { + name: "fee_payer", + long: "fee-payer", + help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword \n\ + or the pubkey of an offline signer, provided an appropriate --signer argument \n\ + is also passed. Defaults to the client keypair.", +}; + +pub fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> { + Arg::with_name(FEE_PAYER_ARG.name) + .long(FEE_PAYER_ARG.long) + .takes_value(true) + .value_name("KEYPAIR") + .validator(input_validators::is_valid_signer) + .help(FEE_PAYER_ARG.help) +} diff --git a/clap-utils/src/lib.rs b/clap-utils/src/lib.rs index aeeaa9825..38f78fe4e 100644 --- a/clap-utils/src/lib.rs +++ b/clap-utils/src/lib.rs @@ -24,6 +24,7 @@ impl std::fmt::Debug for DisplayError { } pub mod commitment; +pub mod fee_payer; pub mod input_parsers; pub mod input_validators; pub mod keypair; diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 03036cd8f..71733248c 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -16,8 +16,14 @@ use num_traits::FromPrimitive; use serde_json::{self, json, Value}; use solana_account_decoder::{UiAccount, UiAccountEncoding}; use solana_clap_utils::{ - self, commitment::commitment_arg_with_default, input_parsers::*, input_validators::*, - keypair::signer_from_path, nonce::*, offline::*, ArgConstant, + self, + commitment::commitment_arg_with_default, + fee_payer::{fee_payer_arg, FEE_PAYER_ARG}, + input_parsers::*, + input_validators::*, + keypair::signer_from_path, + nonce::*, + offline::*, }; use solana_client::{ client_error::{ClientError, ClientErrorKind, Result as ClientResult}, @@ -118,23 +124,6 @@ pub(crate) fn generate_unique_signers( const DATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE pub const DEFAULT_RPC_TIMEOUT_SECONDS: &str = "30"; -pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant { - name: "fee_payer", - long: "fee-payer", - help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword \n\ - or the pubkey of an offline signer, provided an appropriate --signer argument \n\ - is also passed. Defaults to the client keypair.", -}; - -pub fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> { - Arg::with_name(FEE_PAYER_ARG.name) - .long(FEE_PAYER_ARG.long) - .takes_value(true) - .value_name("KEYPAIR") - .validator(is_valid_signer) - .help(FEE_PAYER_ARG.help) -} - #[derive(Debug, PartialEq)] #[allow(clippy::large_enum_variant)] pub enum CliCommand { diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 963f1807b..050f4705a 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1,8 +1,8 @@ use crate::{ checks::{check_account_for_fee_with_commitment, check_unique_pubkeys}, cli::{ - fee_payer_arg, generate_unique_signers, log_instruction_custom_error, return_signers, - CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult, SignerIndex, FEE_PAYER_ARG, + generate_unique_signers, log_instruction_custom_error, return_signers, CliCommand, + CliCommandInfo, CliConfig, CliError, ProcessResult, SignerIndex, }, cli_output::{CliStakeHistory, CliStakeHistoryEntry, CliStakeState, CliStakeType}, nonce::check_nonce_account, @@ -10,7 +10,14 @@ use crate::{ spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount}, }; use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand}; -use solana_clap_utils::{input_parsers::*, input_validators::*, nonce::*, offline::*, ArgConstant}; +use solana_clap_utils::{ + fee_payer::{fee_payer_arg, FEE_PAYER_ARG}, + input_parsers::*, + input_validators::*, + nonce::*, + offline::*, + ArgConstant, +}; use solana_client::{ nonce_utils, rpc_client::RpcClient, rpc_request::DELINQUENT_VALIDATOR_SLOT_DISTANCE, }; diff --git a/stake-accounts/src/arg_parser.rs b/stake-accounts/src/arg_parser.rs index 812c72900..fc2f029b4 100644 --- a/stake-accounts/src/arg_parser.rs +++ b/stake-accounts/src/arg_parser.rs @@ -13,13 +13,7 @@ use std::ffi::OsString; use std::process::exit; fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> { - Arg::with_name("fee_payer") - .long("fee-payer") - .required(true) - .takes_value(true) - .value_name("KEYPAIR") - .validator(is_valid_signer) - .help("Fee payer") + solana_clap_utils::fee_payer::fee_payer_arg().required(true) } fn funding_keypair_arg<'a, 'b>() -> Arg<'a, 'b> {