Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Cli: Support checked stake and vote operations (#18449)
Browse files Browse the repository at this point in the history
* Refactor VoteAuthorize to use SignerIndex and support vote-authorize-*-checked

* Add checked bool const and use in command parsing

* Add create-stake-account-checked handling

* Add stake-set-lockup-checked handling

* Remove unnecessary mut

* Add stake-authorized-checked handling
  • Loading branch information
CriesofCarrots authored Jul 15, 2021
1 parent abe5a0a commit aeb30fa
Show file tree
Hide file tree
Showing 5 changed files with 1,445 additions and 149 deletions.
61 changes: 50 additions & 11 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ use solana_sdk::{
message::Message,
pubkey::Pubkey,
signature::{Signature, Signer, SignerError},
stake::{
self,
instruction::LockupArgs,
state::{Lockup, StakeAuthorize},
},
stake::{self, instruction::LockupArgs, state::Lockup},
system_instruction::{self, SystemError},
system_program,
transaction::{Transaction, TransactionError},
Expand All @@ -64,6 +60,7 @@ use thiserror::Error;

pub const DEFAULT_RPC_TIMEOUT_SECONDS: &str = "30";
pub const DEFAULT_CONFIRM_TX_TIMEOUT_SECONDS: &str = "5";
const CHECKED: bool = true;

#[derive(Debug, PartialEq)]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -199,6 +196,7 @@ pub enum CliCommand {
seed: Option<String>,
staker: Option<Pubkey>,
withdrawer: Option<Pubkey>,
withdrawer_signer: Option<SignerIndex>,
lockup: Lockup,
amount: SpendAmount,
sign_only: bool,
Expand Down Expand Up @@ -272,7 +270,7 @@ pub enum CliCommand {
},
StakeAuthorize {
stake_account_pubkey: Pubkey,
new_authorizations: Vec<(StakeAuthorize, Pubkey, SignerIndex)>,
new_authorizations: Vec<StakeAuthorizationIndexed>,
sign_only: bool,
dump_transaction_message: bool,
blockhash_query: BlockhashQuery,
Expand All @@ -287,6 +285,7 @@ pub enum CliCommand {
stake_account_pubkey: Pubkey,
lockup: LockupArgs,
custodian: SignerIndex,
new_custodian_signer: Option<SignerIndex>,
sign_only: bool,
dump_transaction_message: bool,
blockhash_query: BlockhashQuery,
Expand Down Expand Up @@ -344,6 +343,8 @@ pub enum CliCommand {
new_authorized_pubkey: Pubkey,
vote_authorize: VoteAuthorize,
memo: Option<String>,
authorized: SignerIndex,
new_authorized: Option<SignerIndex>,
},
VoteUpdateValidator {
vote_account_pubkey: Pubkey,
Expand Down Expand Up @@ -720,7 +721,10 @@ pub fn parse_command(
}
// Stake Commands
("create-stake-account", Some(matches)) => {
parse_create_stake_account(matches, default_signer, wallet_manager)
parse_create_stake_account(matches, default_signer, wallet_manager, !CHECKED)
}
("create-stake-account-checked", Some(matches)) => {
parse_create_stake_account(matches, default_signer, wallet_manager, CHECKED)
}
("delegate-stake", Some(matches)) => {
parse_stake_delegate_stake(matches, default_signer, wallet_manager)
Expand All @@ -738,10 +742,16 @@ pub fn parse_command(
parse_merge_stake(matches, default_signer, wallet_manager)
}
("stake-authorize", Some(matches)) => {
parse_stake_authorize(matches, default_signer, wallet_manager)
parse_stake_authorize(matches, default_signer, wallet_manager, !CHECKED)
}
("stake-authorize-checked", Some(matches)) => {
parse_stake_authorize(matches, default_signer, wallet_manager, CHECKED)
}
("stake-set-lockup", Some(matches)) => {
parse_stake_set_lockup(matches, default_signer, wallet_manager)
parse_stake_set_lockup(matches, default_signer, wallet_manager, !CHECKED)
}
("stake-set-lockup-checked", Some(matches)) => {
parse_stake_set_lockup(matches, default_signer, wallet_manager, CHECKED)
}
("stake-account", Some(matches)) => parse_show_stake_account(matches, wallet_manager),
("stake-history", Some(matches)) => parse_show_stake_history(matches),
Expand All @@ -768,12 +778,28 @@ pub fn parse_command(
default_signer,
wallet_manager,
VoteAuthorize::Voter,
!CHECKED,
),
("vote-authorize-withdrawer", Some(matches)) => parse_vote_authorize(
matches,
default_signer,
wallet_manager,
VoteAuthorize::Withdrawer,
!CHECKED,
),
("vote-authorize-voter-checked", Some(matches)) => parse_vote_authorize(
matches,
default_signer,
wallet_manager,
VoteAuthorize::Voter,
CHECKED,
),
("vote-authorize-withdrawer-checked", Some(matches)) => parse_vote_authorize(
matches,
default_signer,
wallet_manager,
VoteAuthorize::Withdrawer,
CHECKED,
),
("vote-account", Some(matches)) => parse_vote_get_account_command(matches, wallet_manager),
("withdraw-from-vote-account", Some(matches)) => {
Expand Down Expand Up @@ -1534,6 +1560,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
seed,
staker,
withdrawer,
withdrawer_signer,
lockup,
amount,
sign_only,
Expand All @@ -1551,6 +1578,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
seed,
staker,
withdrawer,
*withdrawer_signer,
lockup,
*amount,
*sign_only,
Expand Down Expand Up @@ -1712,8 +1740,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
),
CliCommand::StakeSetLockup {
stake_account_pubkey,
mut lockup,
lockup,
custodian,
new_custodian_signer,
sign_only,
dump_transaction_message,
blockhash_query,
Expand All @@ -1725,7 +1754,8 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
&rpc_client,
config,
stake_account_pubkey,
&mut lockup,
lockup,
*new_custodian_signer,
*custodian,
*sign_only,
*dump_transaction_message,
Expand Down Expand Up @@ -1839,12 +1869,16 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
new_authorized_pubkey,
vote_authorize,
memo,
authorized,
new_authorized,
} => process_vote_authorize(
&rpc_client,
config,
vote_account_pubkey,
new_authorized_pubkey,
*vote_authorize,
*authorized,
*new_authorized,
memo.as_ref(),
),
CliCommand::VoteUpdateValidator {
Expand Down Expand Up @@ -2648,6 +2682,8 @@ mod tests {
new_authorized_pubkey,
vote_authorize: VoteAuthorize::Voter,
memo: None,
authorized: 0,
new_authorized: None,
};
let result = process_command(&config);
assert!(result.is_ok());
Expand All @@ -2671,6 +2707,7 @@ mod tests {
seed: None,
staker: None,
withdrawer: None,
withdrawer_signer: None,
lockup: Lockup {
epoch: 0,
unix_timestamp: 0,
Expand Down Expand Up @@ -2843,6 +2880,8 @@ mod tests {
new_authorized_pubkey: bob_pubkey,
vote_authorize: VoteAuthorize::Voter,
memo: None,
authorized: 0,
new_authorized: None,
};
assert!(process_command(&config).is_err());

Expand Down
Loading

0 comments on commit aeb30fa

Please sign in to comment.