diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 91b5dad92c..202769692e 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -408,6 +408,10 @@ pub enum CliCommand { vote_account_pubkey: Pubkey, new_identity_account: SignerIndex, }, + VoteUpdateCommission { + vote_account_pubkey: Pubkey, + commission: u8, + }, // Wallet Commands Address, Airdrop { @@ -728,6 +732,9 @@ pub fn parse_command( ("vote-update-validator", Some(matches)) => { parse_vote_update_validator(matches, default_signer_path, wallet_manager) } + ("vote-update-commission", Some(matches)) => { + parse_vote_update_commission(matches, default_signer_path, wallet_manager) + } ("vote-authorize-voter", Some(matches)) => parse_vote_authorize( matches, default_signer_path, @@ -2217,6 +2224,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { &vote_account_pubkey, *new_identity_account, ), + CliCommand::VoteUpdateCommission { + vote_account_pubkey, + commission, + } => process_vote_update_commission(&rpc_client, config, &vote_account_pubkey, *commission), // Wallet Commands diff --git a/cli/src/vote.rs b/cli/src/vote.rs index 6c686f2bc4..4df27c2665 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -174,6 +174,37 @@ impl VoteSubCommands for App<'_, '_> { .help("Authorized withdrawer keypair"), ) ) + .subcommand( + SubCommand::with_name("vote-update-commission") + .about("Update the vote account's commission") + .arg( + Arg::with_name("vote_account_pubkey") + .index(1) + .value_name("VOTE_ACCOUNT_ADDRESS") + .takes_value(true) + .required(true) + .validator(is_valid_pubkey) + .help("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"), + ) + ) .subcommand( SubCommand::with_name("vote-account") .about("Show the contents of a vote account") @@ -328,6 +359,33 @@ pub fn parse_vote_update_validator( }) } +pub fn parse_vote_update_commission( + matches: &ArgMatches<'_>, + default_signer_path: &str, + wallet_manager: &mut Option>, +) -> Result { + let vote_account_pubkey = + pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap(); + let (authorized_withdrawer, _) = signer_of(matches, "authorized_withdrawer", wallet_manager)?; + let commission = value_t_or_exit!(matches, "commission", u8); + + let payer_provided = None; + let signer_info = generate_unique_signers( + vec![payer_provided, authorized_withdrawer], + matches, + default_signer_path, + wallet_manager, + )?; + + Ok(CliCommandInfo { + command: CliCommand::VoteUpdateCommission { + vote_account_pubkey, + commission, + }, + signers: signer_info.signers, + }) +} + pub fn parse_vote_get_account_command( matches: &ArgMatches<'_>, wallet_manager: &mut Option>, @@ -534,6 +592,33 @@ pub fn process_vote_update_validator( log_instruction_custom_error::(result, &config) } +pub fn process_vote_update_commission( + rpc_client: &RpcClient, + config: &CliConfig, + vote_account_pubkey: &Pubkey, + commission: u8, +) -> ProcessResult { + let authorized_withdrawer = config.signers[1]; + let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; + let ixs = vec![vote_instruction::update_commission( + vote_account_pubkey, + &authorized_withdrawer.pubkey(), + commission, + )]; + + let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey())); + let mut tx = Transaction::new_unsigned(message); + tx.try_sign(&config.signers, recent_blockhash)?; + check_account_for_fee( + rpc_client, + &config.signers[0].pubkey(), + &fee_calculator, + &tx.message, + )?; + let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx); + log_instruction_custom_error::(result, &config) +} + fn get_vote_account( rpc_client: &RpcClient, vote_account_pubkey: &Pubkey, @@ -855,6 +940,27 @@ mod tests { } ); + let test_update_commission = test_commands.clone().get_matches_from(vec![ + "test", + "vote-update-commission", + &pubkey_string, + "42", + &keypair_file, + ]); + assert_eq!( + parse_command(&test_update_commission, &default_keypair_file, &mut None).unwrap(), + CliCommandInfo { + command: CliCommand::VoteUpdateCommission { + vote_account_pubkey: pubkey, + commission: 42, + }, + signers: vec![ + read_keypair_file(&default_keypair_file).unwrap().into(), + Box::new(read_keypair_file(&keypair_file).unwrap()), + ], + } + ); + // Test WithdrawFromVoteAccount subcommand let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![ "test",