Skip to content

Commit

Permalink
Move CLI fee payer arg into clap-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nelson committed Sep 23, 2020
1 parent 6cf74d1 commit 89cab47
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
19 changes: 19 additions & 0 deletions clap-utils/src/fee_payer.rs
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions clap-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 8 additions & 19 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
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,
offline::blockhash_query::BlockhashQuery,
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,
};
Expand Down
8 changes: 1 addition & 7 deletions stake-accounts/src/arg_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 89cab47

Please sign in to comment.