Skip to content

Commit 4e21bd2

Browse files
committed
clean up the unwraps
1 parent 68e0938 commit 4e21bd2

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

program/src/processor.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,23 +532,23 @@ impl Processor {
532532
// relocate lamports, copy data, and close the original account
533533
if split_lamports == source_lamport_balance {
534534
let mut destination_stake_state = source_stake_state;
535-
let delegation = match &mut destination_stake_state {
536-
StakeStateV2::Stake(meta, stake, _) => {
537-
*meta = option_dest_meta.unwrap();
535+
let delegation = match (&mut destination_stake_state, option_dest_meta) {
536+
(StakeStateV2::Stake(meta, stake, _), Some(dest_meta)) => {
537+
*meta = dest_meta;
538538

539539
if is_active_or_activating {
540540
stake.delegation.stake
541541
} else {
542542
0
543543
}
544544
}
545-
StakeStateV2::Initialized(meta) => {
546-
*meta = option_dest_meta.unwrap();
545+
(StakeStateV2::Initialized(meta), Some(dest_meta)) => {
546+
*meta = dest_meta;
547547

548548
0
549549
}
550-
StakeStateV2::Uninitialized => 0,
551-
StakeStateV2::RewardsPool => unreachable!(),
550+
(StakeStateV2::Uninitialized, None) => 0,
551+
_ => unreachable!(),
552552
};
553553

554554
if destination_lamport_balance
@@ -579,12 +579,13 @@ impl Processor {
579579
// special case: if stake is fully inactive, we only care that both accounts meet rent-exemption
580580
if !is_active_or_activating {
581581
let mut destination_stake_state = source_stake_state;
582-
match &mut destination_stake_state {
583-
StakeStateV2::Stake(meta, _, _) | StakeStateV2::Initialized(meta) => {
584-
*meta = option_dest_meta.unwrap();
582+
match (&mut destination_stake_state, option_dest_meta) {
583+
(StakeStateV2::Stake(meta, _, _), Some(dest_meta))
584+
| (StakeStateV2::Initialized(meta), Some(dest_meta)) => {
585+
*meta = dest_meta;
585586
}
586-
StakeStateV2::Uninitialized => (),
587-
StakeStateV2::RewardsPool => unreachable!(),
587+
(StakeStateV2::Uninitialized, None) => (),
588+
_ => unreachable!(),
588589
}
589590

590591
let post_source_lamports = source_lamport_balance.saturating_sub(split_lamports);
@@ -614,8 +615,8 @@ impl Processor {
614615
// * source meets rent exemption less its remaining delegation
615616
// * source and destination both meet the minimum delegation
616617
// destination delegation is matched 1:1 by split lamports. in other words, free source lamports are never split
617-
match source_stake_state {
618-
StakeStateV2::Stake(source_meta, mut source_stake, stake_flags) => {
618+
match (source_stake_state, option_dest_meta) {
619+
(StakeStateV2::Stake(source_meta, mut source_stake, stake_flags), Some(dest_meta)) => {
619620
if destination_lamport_balance < destination_rent_exempt_reserve {
620621
return Err(ProgramError::InsufficientFunds);
621622
}
@@ -650,7 +651,7 @@ impl Processor {
650651

651652
set_stake_state(
652653
destination_stake_account_info,
653-
&StakeStateV2::Stake(option_dest_meta.unwrap(), dest_stake, stake_flags),
654+
&StakeStateV2::Stake(dest_meta, dest_stake, stake_flags),
654655
)?;
655656

656657
relocate_lamports(

0 commit comments

Comments
 (0)