CLI: Support offline fee payers (#8009)

* CLI: Support offline fee-payer

* Add some knobs to test genesis/validator helpers

* Add tests
This commit is contained in:
Trent Nelson
2020-02-07 09:14:27 -07:00
committed by GitHub
parent 6246405afd
commit 5b070ad014
6 changed files with 458 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ use log::*;
use num_traits::FromPrimitive;
use serde_json::{self, json, Value};
use solana_budget_program::budget_instruction::{self, BudgetError};
use solana_clap_utils::{input_parsers::*, input_validators::*};
use solana_clap_utils::{input_parsers::*, input_validators::*, ArgConstant};
use solana_client::{client_error::ClientError, rpc_client::RpcClient};
#[cfg(not(test))]
use solana_faucet::faucet::request_airdrop_transaction;
@@ -51,6 +51,23 @@ use std::{
const USERDATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE
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 or PUBKEY")
.validator(is_pubkey_or_keypair_or_ask_keyword)
.help(FEE_PAYER_ARG.help)
}
#[derive(Debug)]
pub struct KeypairEq(Keypair);
@@ -267,6 +284,7 @@ pub enum CliCommand {
blockhash_query: BlockhashQuery,
nonce_account: Option<Pubkey>,
nonce_authority: Option<SigningAuthority>,
fee_payer: Option<SigningAuthority>,
},
DelegateStake {
stake_account_pubkey: Pubkey,
@@ -278,6 +296,7 @@ pub enum CliCommand {
blockhash_query: BlockhashQuery,
nonce_account: Option<Pubkey>,
nonce_authority: Option<SigningAuthority>,
fee_payer: Option<SigningAuthority>,
},
SplitStake {
stake_account_pubkey: Pubkey,
@@ -308,6 +327,7 @@ pub enum CliCommand {
blockhash_query: BlockhashQuery,
nonce_account: Option<Pubkey>,
nonce_authority: Option<SigningAuthority>,
fee_payer: Option<SigningAuthority>,
},
WithdrawStake {
stake_account_pubkey: Pubkey,
@@ -1402,6 +1422,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
nonce_account,
ref nonce_authority,
ref fee_payer,
} => process_deactivate_stake_account(
&rpc_client,
config,
@@ -1412,6 +1433,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
*nonce_account,
nonce_authority.as_ref(),
fee_payer.as_ref(),
),
CliCommand::DelegateStake {
stake_account_pubkey,
@@ -1423,6 +1445,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
nonce_account,
ref nonce_authority,
ref fee_payer,
} => process_delegate_stake(
&rpc_client,
config,
@@ -1435,6 +1458,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
*nonce_account,
nonce_authority.as_ref(),
fee_payer.as_ref(),
),
CliCommand::SplitStake {
stake_account_pubkey,
@@ -1483,6 +1507,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
nonce_account,
ref nonce_authority,
ref fee_payer,
} => process_stake_authorize(
&rpc_client,
config,
@@ -1495,6 +1520,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
blockhash_query,
*nonce_account,
nonce_authority.as_ref(),
fee_payer.as_ref(),
),
CliCommand::WithdrawStake {
@@ -2808,6 +2834,7 @@ mod tests {
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
fee_payer: None,
};
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());