| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  | use crate::{
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     checks::{check_account_for_fee_with_commitment, check_unique_pubkeys},
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     cli::{
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |         log_instruction_custom_error, CliCommand, CliCommandInfo, CliConfig, CliError,
 | 
					
						
							| 
									
										
										
										
											2020-09-22 15:25:10 -06:00
										 |  |  |         ProcessResult,
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     },
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     spend_utils::{resolve_spend_tx_and_check_account_balance, SpendAmount},
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  | use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
 | 
					
						
							| 
									
										
										
										
											2020-09-22 15:25:10 -06:00
										 |  |  | use solana_clap_utils::{
 | 
					
						
							|  |  |  |     input_parsers::*,
 | 
					
						
							|  |  |  |     input_validators::*,
 | 
					
						
							|  |  |  |     keypair::{DefaultSigner, SignerIndex},
 | 
					
						
							|  |  |  | };
 | 
					
						
							| 
									
										
										
										
											2020-09-22 18:29:11 -06:00
										 |  |  | use solana_cli_output::{CliEpochVotingHistory, CliLockout, CliVoteAccount};
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | use solana_client::rpc_client::RpcClient;
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | use solana_remote_wallet::remote_wallet::RemoteWalletManager;
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | use solana_sdk::{
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |     account::Account, commitment_config::CommitmentConfig, message::Message,
 | 
					
						
							|  |  |  |     native_token::lamports_to_sol, pubkey::Pubkey, system_instruction::SystemError,
 | 
					
						
							|  |  |  |     transaction::Transaction,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2019-11-20 10:12:43 -08:00
										 |  |  | use solana_vote_program::{
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     vote_instruction::{self, withdraw, VoteError},
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |     vote_state::{VoteAuthorize, VoteInit, VoteState},
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | use std::sync::Arc;
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  | pub trait VoteSubCommands {
 | 
					
						
							|  |  |  |     fn vote_subcommands(self) -> Self;
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | impl VoteSubCommands for App<'_, '_> {
 | 
					
						
							|  |  |  |     fn vote_subcommands(self) -> Self {
 | 
					
						
							|  |  |  |         self.subcommand(
 | 
					
						
							|  |  |  |             SubCommand::with_name("create-vote-account")
 | 
					
						
							|  |  |  |                 .about("Create a vote account")
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |                     Arg::with_name("vote_account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("ACCOUNT_KEYPAIR")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							| 
									
										
										
										
											2020-03-13 17:06:33 -06:00
										 |  |  |                         .validator(is_valid_signer)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .help("Vote account keypair to create"),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Arg::with_name("identity_account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(2)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("IDENTITY_KEYPAIR")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Keypair of validator that will vote with this account"),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("commission")
 | 
					
						
							|  |  |  |                         .long("commission")
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("PERCENTAGE")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							| 
									
										
										
										
											2020-01-04 09:20:44 -07:00
										 |  |  |                         .default_value("100")
 | 
					
						
							|  |  |  |                         .help("The commission taken on reward redemption (0-100)"),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("authorized_voter")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .long("authorized-voter")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .value_name("VOTER_PUBKEY"),
 | 
					
						
							|  |  |  |                         "Public key of the authorized voter [default: validator identity pubkey]. "),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("authorized_withdrawer")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .long("authorized-withdrawer")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .value_name("WITHDRAWER_PUBKEY"),
 | 
					
						
							|  |  |  |                         "Public key of the authorized withdrawer [default: validator identity pubkey]. "),
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("seed")
 | 
					
						
							|  |  |  |                         .long("seed")
 | 
					
						
							| 
									
										
										
										
											2020-03-16 09:24:59 -06:00
										 |  |  |                         .value_name("STRING")
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .help("Seed for address generation; if specified, the resulting account will be at a derived address of the VOTE ACCOUNT pubkey")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 ),
 | 
					
						
							|  |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         .subcommand(
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |             SubCommand::with_name("vote-authorize-voter")
 | 
					
						
							|  |  |  |                 .about("Authorize a new vote signing keypair for the given vote account")
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							| 
									
										
										
										
											2020-04-03 09:58:11 -07:00
										 |  |  |                         "Vote account in which to set the authorized voter. "),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |                     Arg::with_name("authorized")
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                         .index(2)
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |                         .value_name("AUTHORIZED_KEYPAIR")
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Current authorized vote signer."),
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     pubkey!(Arg::with_name("new_authorized_pubkey")
 | 
					
						
							|  |  |  |                         .index(3)
 | 
					
						
							|  |  |  |                         .value_name("NEW_AUTHORIZED_PUBKEY")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							| 
									
										
										
										
											2020-04-03 09:58:11 -07:00
										 |  |  |                         "New authorized vote signer. "),
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |                 ),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |         .subcommand(
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |             SubCommand::with_name("vote-authorize-withdrawer")
 | 
					
						
							|  |  |  |                 .about("Authorize a new withdraw signing keypair for the given vote account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							| 
									
										
										
										
											2020-04-03 09:58:11 -07:00
										 |  |  |                         "Vote account in which to set the authorized withdrawer. "),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |                     Arg::with_name("authorized")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(2)
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |                         .value_name("AUTHORIZED_KEYPAIR")
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Current authorized withdrawer."),
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     pubkey!(Arg::with_name("new_authorized_pubkey")
 | 
					
						
							|  |  |  |                         .index(3)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("AUTHORIZED_PUBKEY")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							| 
									
										
										
										
											2020-04-03 09:58:11 -07:00
										 |  |  |                         "New authorized withdrawer. "),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 ),
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |         .subcommand(
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |             SubCommand::with_name("vote-update-validator")
 | 
					
						
							|  |  |  |                 .about("Update the vote account's validator identity")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							|  |  |  |                         "Vote account to update. "),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Arg::with_name("new_identity_account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(2)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("IDENTITY_KEYPAIR")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Keypair of new validator that will vote with this account"),
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Arg::with_name("authorized_withdrawer")
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |                         .index(3)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("AUTHORIZED_KEYPAIR")
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_signer)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                         .help("Authorized withdrawer keypair"),
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |                 )
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |         .subcommand(
 | 
					
						
							|  |  |  |             SubCommand::with_name("vote-update-commission")
 | 
					
						
							|  |  |  |                 .about("Update the vote account's commission")
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							|  |  |  |                         .index(1)
 | 
					
						
							|  |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							|  |  |  |                         .required(true),
 | 
					
						
							|  |  |  |                         "Vote account to update. "),
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("commission")
 | 
					
						
							|  |  |  |                         .index(2)
 | 
					
						
							|  |  |  |                         .value_name("PERCENTAGE")
 | 
					
						
							|  |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_percentage)
 | 
					
						
							|  |  |  |                         .help("The new commission")
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("authorized_withdrawer")
 | 
					
						
							|  |  |  |                         .index(3)
 | 
					
						
							|  |  |  |                         .value_name("AUTHORIZED_KEYPAIR")
 | 
					
						
							|  |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Authorized withdrawer keypair"),
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |         .subcommand(
 | 
					
						
							| 
									
										
										
										
											2020-01-20 23:06:47 -07:00
										 |  |  |             SubCommand::with_name("vote-account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 .about("Show the contents of a vote account")
 | 
					
						
							| 
									
										
										
										
											2020-01-20 23:06:47 -07:00
										 |  |  |                 .alias("show-vote-account")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							|  |  |  |                         "Vote account pubkey. "),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("lamports")
 | 
					
						
							|  |  |  |                         .long("lamports")
 | 
					
						
							|  |  |  |                         .takes_value(false)
 | 
					
						
							|  |  |  |                         .help("Display balance in lamports instead of SOL"),
 | 
					
						
							| 
									
										
										
										
											2021-01-20 09:48:10 -07:00
										 |  |  |                 ),
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |         .subcommand(
 | 
					
						
							|  |  |  |             SubCommand::with_name("withdraw-from-vote-account")
 | 
					
						
							|  |  |  |                 .about("Withdraw lamports from a vote account into a specified account")
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("vote_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                         .index(1)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("VOTE_ACCOUNT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							|  |  |  |                         "Vote account from which to withdraw. "),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                     pubkey!(Arg::with_name("destination_account_pubkey")
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                         .index(2)
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:30:01 -06:00
										 |  |  |                         .value_name("RECIPIENT_ADDRESS")
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:45:37 -07:00
										 |  |  |                         .required(true),
 | 
					
						
							|  |  |  |                         "The recipient of withdrawn SOL. "),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("amount")
 | 
					
						
							|  |  |  |                         .index(3)
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("AMOUNT")
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .required(true)
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |                         .validator(is_amount_or_all)
 | 
					
						
							|  |  |  |                         .help("The amount to withdraw, in SOL; accepts keyword ALL"),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .arg(
 | 
					
						
							|  |  |  |                     Arg::with_name("authorized_withdrawer")
 | 
					
						
							|  |  |  |                         .long("authorized-withdrawer")
 | 
					
						
							| 
									
										
										
										
											2020-03-19 21:43:11 -06:00
										 |  |  |                         .value_name("AUTHORIZED_KEYPAIR")
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                         .takes_value(true)
 | 
					
						
							|  |  |  |                         .validator(is_valid_signer)
 | 
					
						
							|  |  |  |                         .help("Authorized withdrawer [default: cli config keypair]"),
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |         )
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:18:19 -06:00
										 |  |  |     }
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 11:41:18 -07:00
										 |  |  | pub fn parse_create_vote_account(
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     default_signer: &DefaultSigner,
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:54:21 -06:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |     let (vote_account, vote_account_pubkey) = signer_of(matches, "vote_account", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |     let seed = matches.value_of("seed").map(|s| s.to_string());
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     let (identity_account, identity_pubkey) =
 | 
					
						
							|  |  |  |         signer_of(matches, "identity_account", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2020-01-04 09:20:44 -07:00
										 |  |  |     let commission = value_t_or_exit!(matches, "commission", u8);
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |     let authorized_voter = pubkey_of_signer(matches, "authorized_voter", wallet_manager)?;
 | 
					
						
							|  |  |  |     let authorized_withdrawer = pubkey_of_signer(matches, "authorized_withdrawer", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2019-09-26 10:26:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     let payer_provided = None;
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     let signer_info = default_signer.generate_unique_signers(
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         vec![payer_provided, vote_account, identity_account],
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         matches,
 | 
					
						
							|  |  |  |         wallet_manager,
 | 
					
						
							|  |  |  |     )?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     Ok(CliCommandInfo {
 | 
					
						
							|  |  |  |         command: CliCommand::CreateVoteAccount {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |             vote_account: signer_info.index_of(vote_account_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |             seed,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             identity_account: signer_info.index_of(identity_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |             authorized_voter,
 | 
					
						
							|  |  |  |             authorized_withdrawer,
 | 
					
						
							|  |  |  |             commission,
 | 
					
						
							|  |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         signers: signer_info.signers,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     })
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  | pub fn parse_vote_authorize(
 | 
					
						
							|  |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     default_signer: &DefaultSigner,
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:54:21 -06:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |     vote_authorize: VoteAuthorize,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |     let vote_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							|  |  |  |     let new_authorized_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "new_authorized_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |     let (authorized, _) = signer_of(matches, "authorized", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |     let payer_provided = None;
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     let signer_info = default_signer.generate_unique_signers(
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |         vec![payer_provided, authorized],
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         matches,
 | 
					
						
							|  |  |  |         wallet_manager,
 | 
					
						
							|  |  |  |     )?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     Ok(CliCommandInfo {
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         command: CliCommand::VoteAuthorize {
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             vote_account_pubkey,
 | 
					
						
							|  |  |  |             new_authorized_pubkey,
 | 
					
						
							|  |  |  |             vote_authorize,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |         signers: signer_info.signers,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |     })
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | pub fn parse_vote_update_validator(
 | 
					
						
							|  |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     default_signer: &DefaultSigner,
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:54:21 -06:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |     let vote_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     let (new_identity_account, new_identity_pubkey) =
 | 
					
						
							|  |  |  |         signer_of(matches, "new_identity_account", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:49:59 -06:00
										 |  |  |     let (authorized_withdrawer, authorized_withdrawer_pubkey) =
 | 
					
						
							|  |  |  |         signer_of(matches, "authorized_withdrawer", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let payer_provided = None;
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     let signer_info = default_signer.generate_unique_signers(
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         vec![payer_provided, authorized_withdrawer, new_identity_account],
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         matches,
 | 
					
						
							|  |  |  |         wallet_manager,
 | 
					
						
							|  |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Ok(CliCommandInfo {
 | 
					
						
							|  |  |  |         command: CliCommand::VoteUpdateValidator {
 | 
					
						
							|  |  |  |             vote_account_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             new_identity_account: signer_info.index_of(new_identity_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:49:59 -06:00
										 |  |  |             withdraw_authority: signer_info.index_of(authorized_withdrawer_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         signers: signer_info.signers,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     })
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  | pub fn parse_vote_update_commission(
 | 
					
						
							|  |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     default_signer: &DefaultSigner,
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							|  |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							|  |  |  |     let vote_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:30:49 -06:00
										 |  |  |     let (authorized_withdrawer, authorized_withdrawer_pubkey) =
 | 
					
						
							|  |  |  |         signer_of(matches, "authorized_withdrawer", wallet_manager)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     let commission = value_t_or_exit!(matches, "commission", u8);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let payer_provided = None;
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     let signer_info = default_signer.generate_unique_signers(
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |         vec![payer_provided, authorized_withdrawer],
 | 
					
						
							|  |  |  |         matches,
 | 
					
						
							|  |  |  |         wallet_manager,
 | 
					
						
							|  |  |  |     )?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Ok(CliCommandInfo {
 | 
					
						
							|  |  |  |         command: CliCommand::VoteUpdateCommission {
 | 
					
						
							|  |  |  |             vote_account_pubkey,
 | 
					
						
							|  |  |  |             commission,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:30:49 -06:00
										 |  |  |             withdraw_authority: signer_info.index_of(authorized_withdrawer_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |         },
 | 
					
						
							|  |  |  |         signers: signer_info.signers,
 | 
					
						
							|  |  |  |     })
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  | pub fn parse_vote_get_account_command(
 | 
					
						
							|  |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:54:21 -06:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |     let vote_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-09-26 10:26:47 -07:00
										 |  |  |     let use_lamports_unit = matches.is_present("lamports");
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     Ok(CliCommandInfo {
 | 
					
						
							|  |  |  |         command: CliCommand::ShowVoteAccount {
 | 
					
						
							|  |  |  |             pubkey: vote_account_pubkey,
 | 
					
						
							|  |  |  |             use_lamports_unit,
 | 
					
						
							|  |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         signers: vec![],
 | 
					
						
							| 
									
										
										
										
											2019-09-26 10:26:47 -07:00
										 |  |  |     })
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  | pub fn parse_withdraw_from_vote_account(
 | 
					
						
							|  |  |  |     matches: &ArgMatches<'_>,
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     default_signer: &DefaultSigner,
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:54:21 -06:00
										 |  |  |     wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  | ) -> Result<CliCommandInfo, CliError> {
 | 
					
						
							| 
									
										
										
										
											2020-03-16 16:17:13 -06:00
										 |  |  |     let vote_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							|  |  |  |     let destination_account_pubkey =
 | 
					
						
							|  |  |  |         pubkey_of_signer(matches, "destination_account_pubkey", wallet_manager)?.unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |     let withdraw_amount = SpendAmount::new_from_matches(matches, "amount");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     let (withdraw_authority, withdraw_authority_pubkey) =
 | 
					
						
							|  |  |  |         signer_of(matches, "authorized_withdrawer", wallet_manager)?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let payer_provided = None;
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |     let signer_info = default_signer.generate_unique_signers(
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |         vec![payer_provided, withdraw_authority],
 | 
					
						
							|  |  |  |         matches,
 | 
					
						
							|  |  |  |         wallet_manager,
 | 
					
						
							|  |  |  |     )?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Ok(CliCommandInfo {
 | 
					
						
							|  |  |  |         command: CliCommand::WithdrawFromVoteAccount {
 | 
					
						
							|  |  |  |             vote_account_pubkey,
 | 
					
						
							|  |  |  |             destination_account_pubkey,
 | 
					
						
							|  |  |  |             withdraw_authority: signer_info.index_of(withdraw_authority_pubkey).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |             withdraw_amount,
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |         },
 | 
					
						
							|  |  |  |         signers: signer_info.signers,
 | 
					
						
							|  |  |  |     })
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | pub fn process_create_vote_account(
 | 
					
						
							|  |  |  |     rpc_client: &RpcClient,
 | 
					
						
							| 
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 |  |  |     config: &CliConfig,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |     vote_account: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |     seed: &Option<String>,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     identity_account: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |     authorized_voter: &Option<Pubkey>,
 | 
					
						
							|  |  |  |     authorized_withdrawer: &Option<Pubkey>,
 | 
					
						
							|  |  |  |     commission: u8,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |     let vote_account = config.signers[vote_account];
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |     let vote_account_pubkey = vote_account.pubkey();
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |     let vote_account_address = if let Some(seed) = seed {
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:20:48 -07:00
										 |  |  |         Pubkey::create_with_seed(&vote_account_pubkey, &seed, &solana_vote_program::id())?
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |     } else {
 | 
					
						
							|  |  |  |         vote_account_pubkey
 | 
					
						
							|  |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     check_unique_pubkeys(
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         (&config.signers[0].pubkey(), "cli keypair".to_string()),
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |         (&vote_account_address, "vote_account".to_string()),
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     let identity_account = config.signers[identity_account];
 | 
					
						
							|  |  |  |     let identity_pubkey = identity_account.pubkey();
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     check_unique_pubkeys(
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |         (&vote_account_address, "vote_account".to_string()),
 | 
					
						
							|  |  |  |         (&identity_pubkey, "identity_pubkey".to_string()),
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2019-12-09 21:56:43 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     let required_balance = rpc_client
 | 
					
						
							|  |  |  |         .get_minimum_balance_for_rent_exemption(VoteState::size_of())?
 | 
					
						
							|  |  |  |         .max(1);
 | 
					
						
							|  |  |  |     let amount = SpendAmount::Some(required_balance);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let build_message = |lamports| {
 | 
					
						
							|  |  |  |         let vote_init = VoteInit {
 | 
					
						
							|  |  |  |             node_pubkey: identity_pubkey,
 | 
					
						
							|  |  |  |             authorized_voter: authorized_voter.unwrap_or(identity_pubkey),
 | 
					
						
							|  |  |  |             authorized_withdrawer: authorized_withdrawer.unwrap_or(identity_pubkey),
 | 
					
						
							|  |  |  |             commission,
 | 
					
						
							|  |  |  |         };
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let ixs = if let Some(seed) = seed {
 | 
					
						
							|  |  |  |             vote_instruction::create_account_with_seed(
 | 
					
						
							|  |  |  |                 &config.signers[0].pubkey(), // from
 | 
					
						
							|  |  |  |                 &vote_account_address,       // to
 | 
					
						
							|  |  |  |                 &vote_account_pubkey,        // base
 | 
					
						
							|  |  |  |                 seed,                        // seed
 | 
					
						
							|  |  |  |                 &vote_init,
 | 
					
						
							|  |  |  |                 lamports,
 | 
					
						
							|  |  |  |             )
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             vote_instruction::create_account(
 | 
					
						
							|  |  |  |                 &config.signers[0].pubkey(),
 | 
					
						
							|  |  |  |                 &vote_account_pubkey,
 | 
					
						
							|  |  |  |                 &vote_init,
 | 
					
						
							|  |  |  |                 lamports,
 | 
					
						
							|  |  |  |             )
 | 
					
						
							|  |  |  |         };
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:52:38 -06:00
										 |  |  |         Message::new(&ixs, Some(&config.signers[0].pubkey()))
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     if let Ok(response) =
 | 
					
						
							|  |  |  |         rpc_client.get_account_with_commitment(&vote_account_address, config.commitment)
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         if let Some(vote_account) = response.value {
 | 
					
						
							|  |  |  |             let err_msg = if vote_account.owner == solana_vote_program::id() {
 | 
					
						
							|  |  |  |                 format!("Vote account {} already exists", vote_account_address)
 | 
					
						
							|  |  |  |             } else {
 | 
					
						
							|  |  |  |                 format!(
 | 
					
						
							|  |  |  |                     "Account {} already exists and is not a vote account",
 | 
					
						
							|  |  |  |                     vote_account_address
 | 
					
						
							|  |  |  |                 )
 | 
					
						
							|  |  |  |             };
 | 
					
						
							|  |  |  |             return Err(CliError::BadParameter(err_msg).into());
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     let (message, _) = resolve_spend_tx_and_check_account_balance(
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |         rpc_client,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         false,
 | 
					
						
							|  |  |  |         amount,
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |         &fee_calculator,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         &config.signers[0].pubkey(),
 | 
					
						
							|  |  |  |         build_message,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         config.commitment,
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     let mut tx = Transaction::new_unsigned(message);
 | 
					
						
							|  |  |  |     tx.try_sign(&config.signers, recent_blockhash)?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     log_instruction_custom_error::<SystemError>(result, &config)
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  | pub fn process_vote_authorize(
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     rpc_client: &RpcClient,
 | 
					
						
							| 
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 |  |  |     config: &CliConfig,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     vote_account_pubkey: &Pubkey,
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |     new_authorized_pubkey: &Pubkey,
 | 
					
						
							|  |  |  |     vote_authorize: VoteAuthorize,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |     // If the `authorized_account` is also the fee payer, `config.signers` will only have one
 | 
					
						
							|  |  |  |     // keypair in it
 | 
					
						
							|  |  |  |     let authorized = if config.signers.len() == 2 {
 | 
					
						
							|  |  |  |         config.signers[1]
 | 
					
						
							|  |  |  |     } else {
 | 
					
						
							|  |  |  |         config.signers[0]
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     check_unique_pubkeys(
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |         (&authorized.pubkey(), "authorized_account".to_string()),
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         (new_authorized_pubkey, "new_authorized_pubkey".to_string()),
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |     let ixs = vec![vote_instruction::authorize(
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |         vote_account_pubkey,   // vote account to update
 | 
					
						
							|  |  |  |         &authorized.pubkey(),  // current authorized
 | 
					
						
							|  |  |  |         new_authorized_pubkey, // new vote signer/withdrawer
 | 
					
						
							|  |  |  |         vote_authorize,        // vote or withdraw
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     )];
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:52:38 -06:00
										 |  |  |     let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
 | 
					
						
							| 
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 |  |  |     let mut tx = Transaction::new_unsigned(message);
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     tx.try_sign(&config.signers, recent_blockhash)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_account_for_fee_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |         rpc_client,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         &config.signers[0].pubkey(),
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |         &fee_calculator,
 | 
					
						
							|  |  |  |         &tx.message,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         config.commitment,
 | 
					
						
							| 
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     log_instruction_custom_error::<VoteError>(result, &config)
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  | pub fn process_vote_update_validator(
 | 
					
						
							|  |  |  |     rpc_client: &RpcClient,
 | 
					
						
							|  |  |  |     config: &CliConfig,
 | 
					
						
							|  |  |  |     vote_account_pubkey: &Pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     new_identity_account: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:49:59 -06:00
										 |  |  |     withdraw_authority: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:49:59 -06:00
										 |  |  |     let authorized_withdrawer = config.signers[withdraw_authority];
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |     let new_identity_account = config.signers[new_identity_account];
 | 
					
						
							|  |  |  |     let new_identity_pubkey = new_identity_account.pubkey();
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |     check_unique_pubkeys(
 | 
					
						
							|  |  |  |         (vote_account_pubkey, "vote_account_pubkey".to_string()),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         (&new_identity_pubkey, "new_identity_account".to_string()),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
 | 
					
						
							| 
									
										
										
										
											2020-04-10 14:09:56 -07:00
										 |  |  |     let ixs = vec![vote_instruction::update_validator_identity(
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         vote_account_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         &authorized_withdrawer.pubkey(),
 | 
					
						
							|  |  |  |         &new_identity_pubkey,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |     )];
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:52:38 -06:00
										 |  |  |     let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
 | 
					
						
							| 
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 |  |  |     let mut tx = Transaction::new_unsigned(message);
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     tx.try_sign(&config.signers, recent_blockhash)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_account_for_fee_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         rpc_client,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         &config.signers[0].pubkey(),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         &fee_calculator,
 | 
					
						
							|  |  |  |         &tx.message,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         config.commitment,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     log_instruction_custom_error::<VoteError>(result, &config)
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  | pub fn process_vote_update_commission(
 | 
					
						
							|  |  |  |     rpc_client: &RpcClient,
 | 
					
						
							|  |  |  |     config: &CliConfig,
 | 
					
						
							|  |  |  |     vote_account_pubkey: &Pubkey,
 | 
					
						
							|  |  |  |     commission: u8,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:30:49 -06:00
										 |  |  |     withdraw_authority: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:30:49 -06:00
										 |  |  |     let authorized_withdrawer = config.signers[withdraw_authority];
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     let ixs = vec![vote_instruction::update_commission(
 | 
					
						
							|  |  |  |         vote_account_pubkey,
 | 
					
						
							|  |  |  |         &authorized_withdrawer.pubkey(),
 | 
					
						
							|  |  |  |         commission,
 | 
					
						
							|  |  |  |     )];
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:52:38 -06:00
										 |  |  |     let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     let mut tx = Transaction::new_unsigned(message);
 | 
					
						
							|  |  |  |     tx.try_sign(&config.signers, recent_blockhash)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_account_for_fee_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |         rpc_client,
 | 
					
						
							|  |  |  |         &config.signers[0].pubkey(),
 | 
					
						
							|  |  |  |         &fee_calculator,
 | 
					
						
							|  |  |  |         &tx.message,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         config.commitment,
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |     log_instruction_custom_error::<VoteError>(result, &config)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  | fn get_vote_account(
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     rpc_client: &RpcClient,
 | 
					
						
							|  |  |  |     vote_account_pubkey: &Pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-03 17:53:30 -07:00
										 |  |  |     commitment_config: CommitmentConfig,
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  | ) -> Result<(Account, VoteState), Box<dyn std::error::Error>> {
 | 
					
						
							| 
									
										
										
										
											2020-03-03 17:53:30 -07:00
										 |  |  |     let vote_account = rpc_client
 | 
					
						
							|  |  |  |         .get_account_with_commitment(vote_account_pubkey, commitment_config)?
 | 
					
						
							|  |  |  |         .value
 | 
					
						
							|  |  |  |         .ok_or_else(|| {
 | 
					
						
							|  |  |  |             CliError::RpcRequestError(format!("{:?} account does not exist", vote_account_pubkey))
 | 
					
						
							|  |  |  |         })?;
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 10:12:43 -08:00
										 |  |  |     if vote_account.owner != solana_vote_program::id() {
 | 
					
						
							| 
									
										
										
										
											2019-12-19 23:27:54 -08:00
										 |  |  |         return Err(CliError::RpcRequestError(format!(
 | 
					
						
							|  |  |  |             "{:?} is not a vote account",
 | 
					
						
							|  |  |  |             vote_account_pubkey
 | 
					
						
							|  |  |  |         ))
 | 
					
						
							| 
									
										
										
										
											2019-10-02 18:33:01 -07:00
										 |  |  |         .into());
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     }
 | 
					
						
							|  |  |  |     let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
 | 
					
						
							| 
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 |  |  |         CliError::RpcRequestError(
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |             "Account data could not be deserialized to vote state".to_string(),
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |     })?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  |     Ok((vote_account, vote_state))
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pub fn process_show_vote_account(
 | 
					
						
							|  |  |  |     rpc_client: &RpcClient,
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     config: &CliConfig,
 | 
					
						
							| 
									
										
										
										
											2020-10-07 14:38:17 -07:00
										 |  |  |     vote_account_address: &Pubkey,
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  |     use_lamports_unit: bool,
 | 
					
						
							|  |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2020-03-03 17:53:30 -07:00
										 |  |  |     let (vote_account, vote_state) =
 | 
					
						
							| 
									
										
										
										
											2020-10-07 14:38:17 -07:00
										 |  |  |         get_vote_account(rpc_client, vote_account_address, config.commitment)?;
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:41:18 -04:00
										 |  |  |     let epoch_schedule = rpc_client.get_epoch_schedule()?;
 | 
					
						
							| 
									
										
										
										
											2019-10-08 22:34:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     let mut votes: Vec<CliLockout> = vec![];
 | 
					
						
							|  |  |  |     let mut epoch_voting_history: Vec<CliEpochVotingHistory> = vec![];
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     if !vote_state.votes.is_empty() {
 | 
					
						
							|  |  |  |         for vote in &vote_state.votes {
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |             votes.push(vote.into());
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2020-11-07 00:07:40 +09:00
										 |  |  |         for (epoch, credits, prev_credits) in vote_state.epoch_credits().iter().copied() {
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |             let credits_earned = credits - prev_credits;
 | 
					
						
							| 
									
										
										
										
											2020-11-07 00:07:40 +09:00
										 |  |  |             let slots_in_epoch = epoch_schedule.get_slots_in_epoch(epoch);
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |             epoch_voting_history.push(CliEpochVotingHistory {
 | 
					
						
							| 
									
										
										
										
											2020-11-07 00:07:40 +09:00
										 |  |  |                 epoch,
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |                 slots_in_epoch,
 | 
					
						
							|  |  |  |                 credits_earned,
 | 
					
						
							| 
									
										
										
										
											2020-11-07 00:07:40 +09:00
										 |  |  |                 credits,
 | 
					
						
							|  |  |  |                 prev_credits,
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |             });
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 18:32:29 +09:00
										 |  |  |     let epoch_rewards = match crate::stake::fetch_epoch_rewards(rpc_client, vote_account_address, 1)
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         Ok(rewards) => Some(rewards),
 | 
					
						
							|  |  |  |         Err(error) => {
 | 
					
						
							|  |  |  |             eprintln!("Failed to fetch epoch rewards: {:?}", error);
 | 
					
						
							|  |  |  |             None
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2020-10-07 14:38:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     let vote_account_data = CliVoteAccount {
 | 
					
						
							|  |  |  |         account_balance: vote_account.lamports,
 | 
					
						
							|  |  |  |         validator_identity: vote_state.node_pubkey.to_string(),
 | 
					
						
							|  |  |  |         authorized_voters: vote_state.authorized_voters().into(),
 | 
					
						
							|  |  |  |         authorized_withdrawer: vote_state.authorized_withdrawer.to_string(),
 | 
					
						
							|  |  |  |         credits: vote_state.credits(),
 | 
					
						
							|  |  |  |         commission: vote_state.commission,
 | 
					
						
							|  |  |  |         root_slot: vote_state.root_slot,
 | 
					
						
							|  |  |  |         recent_timestamp: vote_state.last_timestamp.clone(),
 | 
					
						
							|  |  |  |         votes,
 | 
					
						
							|  |  |  |         epoch_voting_history,
 | 
					
						
							|  |  |  |         use_lamports_unit,
 | 
					
						
							| 
									
										
										
										
											2020-10-07 14:38:17 -07:00
										 |  |  |         epoch_rewards,
 | 
					
						
							| 
									
										
										
										
											2020-04-14 13:10:25 -06:00
										 |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-06 20:27:15 -06:00
										 |  |  |     Ok(config.output_format.formatted_string(&vote_account_data))
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  | pub fn process_withdraw_from_vote_account(
 | 
					
						
							|  |  |  |     rpc_client: &RpcClient,
 | 
					
						
							|  |  |  |     config: &CliConfig,
 | 
					
						
							|  |  |  |     vote_account_pubkey: &Pubkey,
 | 
					
						
							|  |  |  |     withdraw_authority: SignerIndex,
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |     withdraw_amount: SpendAmount,
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     destination_account_pubkey: &Pubkey,
 | 
					
						
							|  |  |  | ) -> ProcessResult {
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     let withdraw_authority = config.signers[withdraw_authority];
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let current_balance = rpc_client.get_balance(&vote_account_pubkey)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |     let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let lamports = match withdraw_amount {
 | 
					
						
							|  |  |  |         SpendAmount::All => current_balance.saturating_sub(minimum_balance),
 | 
					
						
							|  |  |  |         SpendAmount::Some(withdraw_amount) => {
 | 
					
						
							|  |  |  |             if current_balance.saturating_sub(withdraw_amount) < minimum_balance {
 | 
					
						
							|  |  |  |                 return Err(CliError::BadParameter(format!(
 | 
					
						
							|  |  |  |                     "Withdraw amount too large. The vote account balance must be at least {} SOL to remain rent exempt", lamports_to_sol(minimum_balance)
 | 
					
						
							|  |  |  |                 ))
 | 
					
						
							|  |  |  |                 .into());
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             withdraw_amount
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     let ix = withdraw(
 | 
					
						
							|  |  |  |         vote_account_pubkey,
 | 
					
						
							|  |  |  |         &withdraw_authority.pubkey(),
 | 
					
						
							|  |  |  |         lamports,
 | 
					
						
							|  |  |  |         destination_account_pubkey,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:52:38 -06:00
										 |  |  |     let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     let mut transaction = Transaction::new_unsigned(message);
 | 
					
						
							|  |  |  |     transaction.try_sign(&config.signers, recent_blockhash)?;
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_account_for_fee_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |         rpc_client,
 | 
					
						
							|  |  |  |         &config.signers[0].pubkey(),
 | 
					
						
							|  |  |  |         &fee_calculator,
 | 
					
						
							|  |  |  |         &transaction.message,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         config.commitment,
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |     )?;
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let result = rpc_client.send_and_confirm_transaction_with_spinner(&transaction);
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     log_instruction_custom_error::<VoteError>(result, &config)
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | #[cfg(test)]
 | 
					
						
							|  |  |  | mod tests {
 | 
					
						
							|  |  |  |     use super::*;
 | 
					
						
							| 
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 |  |  |     use crate::cli::{app, parse_command};
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     use solana_sdk::signature::{read_keypair_file, write_keypair, Keypair, Signer};
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |     use tempfile::NamedTempFile;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fn make_tmp_file() -> (String, NamedTempFile) {
 | 
					
						
							|  |  |  |         let tmp_file = NamedTempFile::new().unwrap();
 | 
					
						
							|  |  |  |         (String::from(tmp_file.path().to_str().unwrap()), tmp_file)
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     #[test]
 | 
					
						
							|  |  |  |     fn test_parse_command() {
 | 
					
						
							|  |  |  |         let test_commands = app("test", "desc", "version");
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |         let keypair = Keypair::new();
 | 
					
						
							|  |  |  |         let pubkey = keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2019-09-29 21:18:15 -07:00
										 |  |  |         let pubkey_string = pubkey.to_string();
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         let keypair2 = Keypair::new();
 | 
					
						
							|  |  |  |         let pubkey2 = keypair2.pubkey();
 | 
					
						
							|  |  |  |         let pubkey2_string = pubkey2.to_string();
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         let default_keypair = Keypair::new();
 | 
					
						
							|  |  |  |         let (default_keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         write_keypair(&default_keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |         let default_signer = DefaultSigner {
 | 
					
						
							|  |  |  |             path: default_keypair_file.clone(),
 | 
					
						
							|  |  |  |             arg_name: String::new(),
 | 
					
						
							|  |  |  |         };
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         let test_authorize_voter = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |             "vote-authorize-voter",
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |             &pubkey_string,
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |             &default_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |             &pubkey2_string,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_authorize_voter, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                 command: CliCommand::VoteAuthorize {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     new_authorized_pubkey: pubkey2,
 | 
					
						
							|  |  |  |                     vote_authorize: VoteAuthorize::Voter
 | 
					
						
							|  |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |         let authorized_keypair = Keypair::new();
 | 
					
						
							|  |  |  |         let (authorized_keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         write_keypair(&authorized_keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let test_authorize_voter = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "vote-authorize-voter",
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							|  |  |  |             &authorized_keypair_file,
 | 
					
						
							|  |  |  |             &pubkey2_string,
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_authorize_voter, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-04-02 20:47:31 -07:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::VoteAuthorize {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     new_authorized_pubkey: pubkey2,
 | 
					
						
							|  |  |  |                     vote_authorize: VoteAuthorize::Voter
 | 
					
						
							|  |  |  |                 },
 | 
					
						
							|  |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							|  |  |  |                     read_keypair_file(&authorized_keypair_file).unwrap().into(),
 | 
					
						
							|  |  |  |                 ],
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |         let (keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         let keypair = Keypair::new();
 | 
					
						
							|  |  |  |         write_keypair(&keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         // Test CreateVoteAccount SubCommand
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |         let (identity_keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         let identity_keypair = Keypair::new();
 | 
					
						
							|  |  |  |         write_keypair(&identity_keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         let test_create_vote_account = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "create-vote-account",
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |             &keypair_file,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             &identity_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |             "--commission",
 | 
					
						
							|  |  |  |             "10",
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_create_vote_account, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::CreateVoteAccount {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |                     vote_account: 1,
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                     seed: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     identity_account: 2,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                     authorized_voter: None,
 | 
					
						
							|  |  |  |                     authorized_withdrawer: None,
 | 
					
						
							|  |  |  |                     commission: 10,
 | 
					
						
							|  |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Box::new(keypair),
 | 
					
						
							|  |  |  |                     read_keypair_file(&identity_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 ],
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         let (keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         let keypair = Keypair::new();
 | 
					
						
							|  |  |  |         write_keypair(&keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         let test_create_vote_account2 = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "create-vote-account",
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |             &keypair_file,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             &identity_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_create_vote_account2, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::CreateVoteAccount {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |                     vote_account: 1,
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                     seed: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     identity_account: 2,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                     authorized_voter: None,
 | 
					
						
							|  |  |  |                     authorized_withdrawer: None,
 | 
					
						
							| 
									
										
										
										
											2020-01-04 09:20:44 -07:00
										 |  |  |                     commission: 100,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Box::new(keypair),
 | 
					
						
							|  |  |  |                     read_keypair_file(&identity_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 ],
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         // test init with an authed voter
 | 
					
						
							| 
									
										
										
										
											2020-10-19 12:12:08 -07:00
										 |  |  |         let authed = solana_sdk::pubkey::new_rand();
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |         let (keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         let keypair = Keypair::new();
 | 
					
						
							|  |  |  |         write_keypair(&keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         let test_create_vote_account3 = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "create-vote-account",
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |             &keypair_file,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             &identity_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |             "--authorized-voter",
 | 
					
						
							|  |  |  |             &authed.to_string(),
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_create_vote_account3, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::CreateVoteAccount {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |                     vote_account: 1,
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                     seed: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     identity_account: 2,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                     authorized_voter: Some(authed),
 | 
					
						
							|  |  |  |                     authorized_withdrawer: None,
 | 
					
						
							| 
									
										
										
										
											2020-01-04 09:20:44 -07:00
										 |  |  |                     commission: 100
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Box::new(keypair),
 | 
					
						
							|  |  |  |                     read_keypair_file(&identity_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 ],
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         let (keypair_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         let keypair = Keypair::new();
 | 
					
						
							|  |  |  |         write_keypair(&keypair, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |         // test init with an authed withdrawer
 | 
					
						
							|  |  |  |         let test_create_vote_account4 = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "create-vote-account",
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:17:34 +05:30
										 |  |  |             &keypair_file,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             &identity_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-09-25 13:53:49 -07:00
										 |  |  |             "--authorized-withdrawer",
 | 
					
						
							|  |  |  |             &authed.to_string(),
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_create_vote_account4, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::CreateVoteAccount {
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 |  |  |                     vote_account: 1,
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 |  |  |                     seed: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     identity_account: 2,
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                     authorized_voter: None,
 | 
					
						
							|  |  |  |                     authorized_withdrawer: Some(authed),
 | 
					
						
							| 
									
										
										
										
											2020-01-04 09:20:44 -07:00
										 |  |  |                     commission: 100
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Box::new(keypair),
 | 
					
						
							|  |  |  |                     read_keypair_file(&identity_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 ],
 | 
					
						
							| 
									
										
										
										
											2019-10-21 17:08:09 -06:00
										 |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |         let test_update_validator = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "vote-update-validator",
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |             &identity_keypair_file,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |             &keypair_file,
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_update_validator, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::VoteUpdateValidator {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     new_identity_account: 2,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 21:49:59 -06:00
										 |  |  |                     withdraw_authority: 1,
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |                 },
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 |  |  |                     Box::new(read_keypair_file(&keypair_file).unwrap()),
 | 
					
						
							|  |  |  |                     read_keypair_file(&identity_keypair_file).unwrap().into(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |                 ],
 | 
					
						
							| 
									
										
										
										
											2019-12-12 16:04:03 -07:00
										 |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |         let test_update_commission = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "vote-update-commission",
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							|  |  |  |             "42",
 | 
					
						
							|  |  |  |             &keypair_file,
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_update_commission, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::VoteUpdateCommission {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     commission: 42,
 | 
					
						
							| 
									
										
										
										
											2020-07-13 20:30:49 -06:00
										 |  |  |                     withdraw_authority: 1,
 | 
					
						
							| 
									
										
										
										
											2020-06-09 21:15:46 -07:00
										 |  |  |                 },
 | 
					
						
							|  |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							|  |  |  |                     Box::new(read_keypair_file(&keypair_file).unwrap()),
 | 
					
						
							|  |  |  |                 ],
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |         // Test WithdrawFromVoteAccount subcommand
 | 
					
						
							|  |  |  |         let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "withdraw-from-vote-account",
 | 
					
						
							|  |  |  |             &keypair_file,
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							|  |  |  |             "42",
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_withdraw_from_vote_account, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::WithdrawFromVoteAccount {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: read_keypair_file(&keypair_file).unwrap().pubkey(),
 | 
					
						
							|  |  |  |                     destination_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     withdraw_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |                     withdraw_amount: SpendAmount::Some(42_000_000_000),
 | 
					
						
							|  |  |  |                 },
 | 
					
						
							|  |  |  |                 signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test WithdrawFromVoteAccount subcommand
 | 
					
						
							|  |  |  |         let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "withdraw-from-vote-account",
 | 
					
						
							|  |  |  |             &keypair_file,
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							|  |  |  |             "ALL",
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_withdraw_from_vote_account, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::WithdrawFromVoteAccount {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: read_keypair_file(&keypair_file).unwrap().pubkey(),
 | 
					
						
							|  |  |  |                     destination_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     withdraw_authority: 0,
 | 
					
						
							|  |  |  |                     withdraw_amount: SpendAmount::All,
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                 },
 | 
					
						
							|  |  |  |                 signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test WithdrawFromVoteAccount subcommand with authority
 | 
					
						
							|  |  |  |         let withdraw_authority = Keypair::new();
 | 
					
						
							|  |  |  |         let (withdraw_authority_file, mut tmp_file) = make_tmp_file();
 | 
					
						
							|  |  |  |         write_keypair(&withdraw_authority, tmp_file.as_file_mut()).unwrap();
 | 
					
						
							|  |  |  |         let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![
 | 
					
						
							|  |  |  |             "test",
 | 
					
						
							|  |  |  |             "withdraw-from-vote-account",
 | 
					
						
							|  |  |  |             &keypair_file,
 | 
					
						
							|  |  |  |             &pubkey_string,
 | 
					
						
							|  |  |  |             "42",
 | 
					
						
							|  |  |  |             "--authorized-withdrawer",
 | 
					
						
							|  |  |  |             &withdraw_authority_file,
 | 
					
						
							|  |  |  |         ]);
 | 
					
						
							|  |  |  |         assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2020-09-21 21:53:15 -06:00
										 |  |  |             parse_command(&test_withdraw_from_vote_account, &default_signer, &mut None).unwrap(),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |             CliCommandInfo {
 | 
					
						
							|  |  |  |                 command: CliCommand::WithdrawFromVoteAccount {
 | 
					
						
							|  |  |  |                     vote_account_pubkey: read_keypair_file(&keypair_file).unwrap().pubkey(),
 | 
					
						
							|  |  |  |                     destination_account_pubkey: pubkey,
 | 
					
						
							|  |  |  |                     withdraw_authority: 1,
 | 
					
						
							| 
									
										
										
										
											2020-06-15 14:36:47 -07:00
										 |  |  |                     withdraw_amount: SpendAmount::Some(42_000_000_000),
 | 
					
						
							| 
									
										
										
										
											2020-03-13 16:30:04 -04:00
										 |  |  |                 },
 | 
					
						
							|  |  |  |                 signers: vec![
 | 
					
						
							|  |  |  |                     read_keypair_file(&default_keypair_file).unwrap().into(),
 | 
					
						
							|  |  |  |                     read_keypair_file(&withdraw_authority_file).unwrap().into()
 | 
					
						
							|  |  |  |                 ],
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2019-09-18 10:29:57 -06:00
										 |  |  |     }
 | 
					
						
							|  |  |  | }
 |