Add vote-update-commission
subcommand
This commit is contained in:
committed by
Trent Nelson
parent
b7fb739cd9
commit
5f0584b6e8
@ -408,6 +408,10 @@ pub enum CliCommand {
|
|||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
new_identity_account: SignerIndex,
|
new_identity_account: SignerIndex,
|
||||||
},
|
},
|
||||||
|
VoteUpdateCommission {
|
||||||
|
vote_account_pubkey: Pubkey,
|
||||||
|
commission: u8,
|
||||||
|
},
|
||||||
// Wallet Commands
|
// Wallet Commands
|
||||||
Address,
|
Address,
|
||||||
Airdrop {
|
Airdrop {
|
||||||
@ -728,6 +732,9 @@ pub fn parse_command(
|
|||||||
("vote-update-validator", Some(matches)) => {
|
("vote-update-validator", Some(matches)) => {
|
||||||
parse_vote_update_validator(matches, default_signer_path, wallet_manager)
|
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(
|
("vote-authorize-voter", Some(matches)) => parse_vote_authorize(
|
||||||
matches,
|
matches,
|
||||||
default_signer_path,
|
default_signer_path,
|
||||||
@ -2217,6 +2224,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
|||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
*new_identity_account,
|
*new_identity_account,
|
||||||
),
|
),
|
||||||
|
CliCommand::VoteUpdateCommission {
|
||||||
|
vote_account_pubkey,
|
||||||
|
commission,
|
||||||
|
} => process_vote_update_commission(&rpc_client, config, &vote_account_pubkey, *commission),
|
||||||
|
|
||||||
// Wallet Commands
|
// Wallet Commands
|
||||||
|
|
||||||
|
106
cli/src/vote.rs
106
cli/src/vote.rs
@ -174,6 +174,37 @@ impl VoteSubCommands for App<'_, '_> {
|
|||||||
.help("Authorized withdrawer keypair"),
|
.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(
|
||||||
SubCommand::with_name("vote-account")
|
SubCommand::with_name("vote-account")
|
||||||
.about("Show the contents of a 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<Arc<RemoteWalletManager>>,
|
||||||
|
) -> Result<CliCommandInfo, CliError> {
|
||||||
|
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(
|
pub fn parse_vote_get_account_command(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches<'_>,
|
||||||
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
|
||||||
@ -534,6 +592,33 @@ pub fn process_vote_update_validator(
|
|||||||
log_instruction_custom_error::<VoteError>(result, &config)
|
log_instruction_custom_error::<VoteError>(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::<VoteError>(result, &config)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_vote_account(
|
fn get_vote_account(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
vote_account_pubkey: &Pubkey,
|
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
|
// Test WithdrawFromVoteAccount subcommand
|
||||||
let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![
|
let test_withdraw_from_vote_account = test_commands.clone().get_matches_from(vec![
|
||||||
"test",
|
"test",
|
||||||
|
Reference in New Issue
Block a user