From 0f3a8314aea643ff6ed7dddc0696992dd9ce67d3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2019 11:35:14 -0700 Subject: [PATCH] Enable SOL or lamports for create-vote-account, show-{stake,vote}-account commands (#6114) (#6116) automerge --- cli/src/vote.rs | 26 ++++++++++----- cli/src/wallet.rs | 80 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/cli/src/vote.rs b/cli/src/vote.rs index 0edff51968..7324a1b687 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -22,11 +22,12 @@ pub fn parse_vote_create_account(matches: &ArgMatches<'_>) -> Result, ) -> Result { let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap(); - Ok(WalletCommand::ShowVoteAccount(vote_account_pubkey)) + let use_lamports_unit = matches.is_present("lamports"); + Ok(WalletCommand::ShowVoteAccount { + pubkey: vote_account_pubkey, + use_lamports_unit, + }) } pub fn process_create_vote_account( @@ -136,6 +141,7 @@ pub fn process_show_vote_account( rpc_client: &RpcClient, _config: &WalletConfig, vote_account_pubkey: &Pubkey, + use_lamports_unit: bool, ) -> ProcessResult { let vote_account = rpc_client.get_account(vote_account_pubkey)?; @@ -151,7 +157,10 @@ pub fn process_show_vote_account( ) })?; - println!("account lamports: {}", vote_account.lamports); + println!( + "account balance: {}", + crate::wallet::build_balance_message(vote_account.lamports, use_lamports_unit) + ); println!("node id: {}", vote_state.node_pubkey); println!( "authorized voter pubkey: {}", @@ -313,6 +322,7 @@ mod tests { "50", "--commission", "10", + "lamports", ]); assert_eq!( parse_command(&pubkey, &test_create_vote_account).unwrap(), @@ -327,7 +337,7 @@ mod tests { ]); assert_eq!( parse_command(&pubkey, &test_create_vote_account2).unwrap(), - WalletCommand::CreateVoteAccount(pubkey, node_pubkey, 0, 50) + WalletCommand::CreateVoteAccount(pubkey, node_pubkey, 0, 858993459200) ); // Test Uptime Subcommand diff --git a/cli/src/wallet.rs b/cli/src/wallet.rs index 6a8e47fb39..974dc02c63 100644 --- a/cli/src/wallet.rs +++ b/cli/src/wallet.rs @@ -71,7 +71,10 @@ pub enum WalletCommand { output_file: Option, use_lamports_unit: bool, }, - ShowVoteAccount(Pubkey), + ShowVoteAccount { + pubkey: Pubkey, + use_lamports_unit: bool, + }, Uptime { pubkey: Pubkey, aggregate: bool, @@ -81,7 +84,10 @@ pub enum WalletCommand { WithdrawStake(Keypair, Pubkey, u64), DeactivateStake(Keypair, Pubkey), RedeemVoteCredits(Pubkey, Pubkey), - ShowStakeAccount(Pubkey), + ShowStakeAccount { + pubkey: Pubkey, + use_lamports_unit: bool, + }, CreateReplicatorStorageAccount(Pubkey, Pubkey), CreateValidatorStorageAccount(Pubkey, Pubkey), ClaimStorageReward(Pubkey, Pubkey), @@ -286,7 +292,11 @@ pub fn parse_command( } ("show-stake-account", Some(matches)) => { let stake_account_pubkey = pubkey_of(matches, "stake_account_pubkey").unwrap(); - Ok(WalletCommand::ShowStakeAccount(stake_account_pubkey)) + let use_lamports_unit = matches.is_present("lamports"); + Ok(WalletCommand::ShowStakeAccount { + pubkey: stake_account_pubkey, + use_lamports_unit, + }) } ("create-replicator-storage-account", Some(matches)) => { let account_owner = pubkey_of(matches, "storage_account_owner").unwrap(); @@ -716,6 +726,7 @@ fn process_show_stake_account( rpc_client: &RpcClient, _config: &WalletConfig, stake_account_pubkey: &Pubkey, + use_lamports_unit: bool, ) -> ProcessResult { use solana_stake_api::stake_state::StakeState; let stake_account = rpc_client.get_account(stake_account_pubkey)?; @@ -726,9 +737,15 @@ fn process_show_stake_account( } match stake_account.state() { Ok(StakeState::Stake(stake)) => { - println!("total stake: {}", stake_account.lamports); + println!( + "total stake: {}", + build_balance_message(stake_account.lamports, use_lamports_unit) + ); println!("credits observed: {}", stake.credits_observed); - println!("delegated stake: {}", stake.stake); + println!( + "delegated stake: {}", + build_balance_message(stake.stake, use_lamports_unit) + ); if stake.voter_pubkey != Pubkey::default() { println!("delegated voter pubkey: {}", stake.voter_pubkey); } @@ -1307,9 +1324,15 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { *use_lamports_unit, ), - WalletCommand::ShowVoteAccount(vote_account_pubkey) => { - process_show_vote_account(&rpc_client, config, &vote_account_pubkey) - } + WalletCommand::ShowVoteAccount { + pubkey: vote_account_pubkey, + use_lamports_unit, + } => process_show_vote_account( + &rpc_client, + config, + &vote_account_pubkey, + *use_lamports_unit, + ), WalletCommand::Uptime { pubkey: vote_account_pubkey, @@ -1362,9 +1385,15 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { ) } - WalletCommand::ShowStakeAccount(stake_account_pubkey) => { - process_show_stake_account(&rpc_client, config, &stake_account_pubkey) - } + WalletCommand::ShowStakeAccount { + pubkey: stake_account_pubkey, + use_lamports_unit, + } => process_show_stake_account( + &rpc_client, + config, + &stake_account_pubkey, + *use_lamports_unit, + ), WalletCommand::CreateReplicatorStorageAccount( storage_account_owner, @@ -1538,7 +1567,7 @@ where } } -fn build_balance_message(lamports: u64, use_lamports_unit: bool) -> String { +pub(crate) fn build_balance_message(lamports: u64, use_lamports_unit: bool) -> String { if use_lamports_unit { let ess = if lamports == 1 { "" } else { "s" }; format!("{:?} lamport{}", lamports, ess) @@ -1550,7 +1579,7 @@ fn build_balance_message(lamports: u64, use_lamports_unit: bool) -> String { } } -fn parse_amount_lamports( +pub(crate) fn parse_amount_lamports( amount: &str, use_lamports_unit: Option<&str>, ) -> Result> { @@ -1698,12 +1727,19 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .help("Validator that will vote with this account"), ) .arg( - Arg::with_name("lamports") + Arg::with_name("amount") .index(3) - .value_name("LAMPORTS") + .value_name("AMOUNT") .takes_value(true) .required(true) - .help("The amount of lamports to send to the vote account"), + .help("The amount of send to the vote account (default unit SOL)"), + ) + .arg( + Arg::with_name("unit") + .index(4) + .takes_value(true) + .possible_values(&["SOL", "lamports"]) + .help("Specify unit to use for request"), ) .arg( Arg::with_name("commission") @@ -1751,6 +1787,12 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .required(true) .validator(is_pubkey_or_keypair) .help("Vote account pubkey"), + ) + .arg( + Arg::with_name("lamports") + .long("lamports") + .takes_value(false) + .help("Display balance in lamports instead of SOL"), ), ) .subcommand( @@ -1914,6 +1956,12 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .validator(is_pubkey_or_keypair) .help("Stake account pubkey"), ) + .arg( + Arg::with_name("lamports") + .long("lamports") + .takes_value(false) + .help("Display balance in lamports instead of SOL"), + ), ) .subcommand( SubCommand::with_name("create-storage-mining-pool-account")