Skip to content
Prev Previous commit
Next Next commit
Use match statement instead
  • Loading branch information
CriesofCarrots committed Mar 15, 2024
commit 31f642aa34e13b1f5daa1245d316bc43675509cd
28 changes: 14 additions & 14 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,22 +1981,22 @@ pub fn process_split_stake(

let rent_exempt_reserve = if !sign_only {
let check_stake_account = |account: Account| -> Result<(), CliError> {
if account.owner == stake::program::id() {
Err(CliError::BadParameter(format!(
match account.owner {
owner if owner == stake::program::id() => Err(CliError::BadParameter(format!(
"Stake account {split_stake_account_address} already exists"
)))
} else if account.owner == system_program::id() {
if !account.data.is_empty() {
Err(CliError::BadParameter(format!(
"Account {split_stake_account_address} has data and cannot be used to split stake"
)))
} else {
// if `stake_account`'s owner is the system_program and its data is
// empty, `stake_account` is allowed to receive the stake split
Ok(())
))),
owner if owner == system_program::id() => {
if !account.data.is_empty() {
Err(CliError::BadParameter(format!(
"Account {split_stake_account_address} has data and cannot be used to split stake"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we should spruce up these error messages to be a little more normie-friendly? maybe in follow up

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll make a follow-up. If you have recommended verbiage, please do share.

)))
} else {
// if `stake_account`'s owner is the system_program and its data is
// empty, `stake_account` is allowed to receive the stake split
Ok(())
}
}
} else {
Err(CliError::BadParameter(format!(
_ => Err(CliError::BadParameter(format!(
"Account {split_stake_account_address} already exists and cannot be used to split stake"
)))
}
Expand Down