CLI: Cleanup authority arg usage inconsistencies (#7922) (#7924)

automerge
This commit is contained in:
mergify[bot]
2020-01-22 14:09:26 -08:00
committed by Grimes
parent 5b4b086ebf
commit bec1cf3145
4 changed files with 177 additions and 184 deletions

View File

@@ -1,7 +1,7 @@
use crate::{
cluster_query::*,
display::{println_name_value, println_signers},
nonce::*,
nonce::{self, *},
stake::*,
storage::*,
validator_info::*,
@@ -146,6 +146,10 @@ impl PartialEq for SigningAuthority {
}
}
pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
nonce::nonce_authority_arg().requires(NONCE_ARG.name)
}
#[derive(Default, Debug, PartialEq)]
pub struct PayCommand {
pub lamports: u64,
@@ -1969,23 +1973,8 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.takes_value(false)
.help("Sign the transaction offline"),
)
.arg(
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey_or_keypair)
.help(NONCE_ARG.help),
)
.arg(
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.requires(NONCE_ARG.name)
.validator(is_pubkey_or_keypair_or_ask_keyword)
.help(NONCE_AUTHORITY_ARG.help),
)
.arg(nonce_arg())
.arg(nonce_authority_arg())
.arg(
Arg::with_name("signer")
.long("signer")

View File

@@ -49,13 +49,23 @@ pub trait NonceSubCommands {
fn nonce_subcommands(self) -> Self;
}
fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("nonce_authority")
.long("nonce-authority")
pub fn nonce_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("KEYPAIR")
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey)
.help(NONCE_ARG.help)
}
pub fn nonce_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.value_name("KEYPAIR or PUBKEY")
.validator(is_pubkey_or_keypair_or_ask_keyword)
.help("Specify nonce authority if different from account")
.help(NONCE_AUTHORITY_ARG.help)
}
impl NonceSubCommands for App<'_, '_> {
@@ -113,8 +123,8 @@ impl NonceSubCommands for App<'_, '_> {
.help("Specify unit to use for request"),
)
.arg(
Arg::with_name("nonce_authority")
.long("nonce-authority")
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.value_name("BASE58_PUBKEY")
.validator(is_pubkey_or_keypair)
@@ -236,7 +246,7 @@ pub fn parse_authorize_nonce_account(matches: &ArgMatches<'_>) -> Result<CliComm
pub fn parse_nonce_create_account(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let nonce_account = keypair_of(matches, "nonce_account_keypair").unwrap();
let lamports = required_lamports_from(matches, "amount", "unit")?;
let nonce_authority = pubkey_of(matches, "nonce_authority");
let nonce_authority = pubkey_of(matches, NONCE_AUTHORITY_ARG.name);
Ok(CliCommandInfo {
command: CliCommand::CreateNonceAccount {

View File

@@ -1,11 +1,11 @@
use crate::{
cli::{
build_balance_message, check_account_for_fee, check_unique_pubkeys,
get_blockhash_fee_calculator, log_instruction_custom_error, replace_signatures,
required_lamports_from, return_signers, CliCommand, CliCommandInfo, CliConfig, CliError,
ProcessResult, SigningAuthority,
get_blockhash_fee_calculator, log_instruction_custom_error, nonce_authority_arg,
replace_signatures, required_lamports_from, return_signers, CliCommand, CliCommandInfo,
CliConfig, CliError, ProcessResult, SigningAuthority,
},
nonce::{check_nonce_account, NONCE_ARG, NONCE_AUTHORITY_ARG},
nonce::{check_nonce_account, nonce_arg, NONCE_ARG, NONCE_AUTHORITY_ARG},
};
use clap::{App, Arg, ArgMatches, SubCommand};
use console::style;
@@ -48,7 +48,7 @@ fn stake_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name(STAKE_AUTHORITY_ARG.name)
.long(STAKE_AUTHORITY_ARG.long)
.takes_value(true)
.value_name("KEYPAIR")
.value_name("KEYPAIR of PUBKEY")
.validator(is_pubkey_or_keypair_or_ask_keyword)
.help(STAKE_AUTHORITY_ARG.help)
}
@@ -57,7 +57,7 @@ fn withdraw_authority_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name(WITHDRAW_AUTHORITY_ARG.name)
.long(WITHDRAW_AUTHORITY_ARG.long)
.takes_value(true)
.value_name("KEYPAIR")
.value_name("KEYPAIR or PUBKEY")
.validator(is_pubkey_or_keypair_or_ask_keyword)
.help(WITHDRAW_AUTHORITY_ARG.help)
}
@@ -189,23 +189,8 @@ impl StakeSubCommands for App<'_, '_> {
.validator(is_hash)
.help("Use the supplied blockhash"),
)
.arg(
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey)
.help(NONCE_ARG.help)
)
.arg(
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.requires(NONCE_ARG.name)
.validator(is_keypair_or_ask_keyword)
.help(NONCE_AUTHORITY_ARG.help)
),
.arg(nonce_arg())
.arg(nonce_authority_arg())
)
.subcommand(
SubCommand::with_name("stake-authorize-staker")
@@ -252,23 +237,8 @@ impl StakeSubCommands for App<'_, '_> {
.validator(is_hash)
.help("Use the supplied blockhash"),
)
.arg(
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey)
.help(NONCE_ARG.help)
)
.arg(
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.requires(NONCE_ARG.name)
.validator(is_keypair_or_ask_keyword)
.help(NONCE_AUTHORITY_ARG.help)
),
.arg(nonce_arg())
.arg(nonce_authority_arg())
)
.subcommand(
SubCommand::with_name("stake-authorize-withdrawer")
@@ -315,23 +285,8 @@ impl StakeSubCommands for App<'_, '_> {
.validator(is_hash)
.help("Use the supplied blockhash"),
)
.arg(
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey)
.help(NONCE_ARG.help)
)
.arg(
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.requires(NONCE_ARG.name)
.validator(is_keypair_or_ask_keyword)
.help(NONCE_AUTHORITY_ARG.help)
),
.arg(nonce_arg())
.arg(nonce_authority_arg())
)
.subcommand(
SubCommand::with_name("deactivate-stake")
@@ -368,23 +323,8 @@ impl StakeSubCommands for App<'_, '_> {
.validator(is_hash)
.help("Use the supplied blockhash"),
)
.arg(
Arg::with_name(NONCE_ARG.name)
.long(NONCE_ARG.long)
.takes_value(true)
.value_name("PUBKEY")
.requires("blockhash")
.validator(is_pubkey)
.help(NONCE_ARG.help)
)
.arg(
Arg::with_name(NONCE_AUTHORITY_ARG.name)
.long(NONCE_AUTHORITY_ARG.long)
.takes_value(true)
.requires(NONCE_ARG.name)
.validator(is_keypair_or_ask_keyword)
.help(NONCE_AUTHORITY_ARG.help)
),
.arg(nonce_arg())
.arg(nonce_authority_arg())
)
.subcommand(
SubCommand::with_name("withdraw-stake")