diff --git a/cross-chain/solana/programs/tbtc/src/processor/admin/remove_guardian.rs b/cross-chain/solana/programs/tbtc/src/processor/admin/remove_guardian.rs index cd3bbe301..06f45c3f6 100644 --- a/cross-chain/solana/programs/tbtc/src/processor/admin/remove_guardian.rs +++ b/cross-chain/solana/programs/tbtc/src/processor/admin/remove_guardian.rs @@ -43,18 +43,21 @@ pub struct RemoveGuardian<'info> { pub fn remove_guardian(ctx: Context) -> Result<()> { let guardians: &mut Vec<_> = &mut ctx.accounts.guardians; let removed = ctx.accounts.guardian.key(); - match guardians.iter().position(|&guardian| guardian == removed) { - Some(index) => { - // Remove pubkey to guardians account. - guardians.swap_remove(index); - // Update config. - ctx.accounts.config.num_guardians -= 1; + // It is safe to unwrap because the key we are removing is guaranteed to exist since there is + // a guardian info account for it. + let index = guardians + .iter() + .position(|&guardian| guardian == removed) + .unwrap(); - emit!(crate::event::GuardianRemoved { guardian: removed }); + // Remove pubkey to guardians account. + guardians.swap_remove(index); - Ok(()) - } - None => err!(TbtcError::GuardianNonexistent), - } + // Update config. + ctx.accounts.config.num_guardians -= 1; + + emit!(crate::event::GuardianRemoved { guardian: removed }); + + Ok(()) } diff --git a/cross-chain/solana/programs/tbtc/src/processor/admin/remove_minter.rs b/cross-chain/solana/programs/tbtc/src/processor/admin/remove_minter.rs index 6f6eeaf50..a506bb1d5 100644 --- a/cross-chain/solana/programs/tbtc/src/processor/admin/remove_minter.rs +++ b/cross-chain/solana/programs/tbtc/src/processor/admin/remove_minter.rs @@ -45,18 +45,21 @@ pub struct RemoveMinter<'info> { pub fn remove_minter(ctx: Context) -> Result<()> { let minters: &mut Vec<_> = &mut ctx.accounts.minters; let removed = ctx.accounts.minter.key(); - match minters.iter().position(|&minter| minter == removed) { - Some(index) => { - // Remove pubkey to minters account. - minters.swap_remove(index); - // Update config. - ctx.accounts.config.num_minters -= 1; + // It is safe to unwrap because the key we are removing is guaranteed to exist since there is + // a minter info account for it. + let index = minters + .iter() + .position(|&minter| minter == removed) + .unwrap(); - emit!(crate::event::MinterRemoved { minter: removed }); + // Remove pubkey to minters account. + minters.swap_remove(index); - Ok(()) - } - None => err!(TbtcError::GuardianNonexistent), - } + // Update config. + ctx.accounts.config.num_minters -= 1; + + emit!(crate::event::MinterRemoved { minter: removed }); + + Ok(()) }