Skip to content

Commit

Permalink
throw errors in relevant instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannis Chatziveroglou committed Jul 16, 2023
1 parent 92210d9 commit f14998f
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions programs/cardinal-rewards-center/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ pub enum ErrorCode {
InvalidAuthorityTokenAccount,
#[msg("Max reward seconds claimed")]
MaxRewardSecondsClaimed,

// Misc
#[msg("Cardinal Protocols are shutting down. Please read latest twitter post for more information")]
ProtocolsShutdown,
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ pub fn handler(ctx: Context<InitRewardDistributorCtx>, ix: InitRewardDistributor
reward_distributor.claim_rewards_payment_info = ix.claim_rewards_payment_info;

assert_payment_info(ctx.accounts.stake_pool.key(), Action::ClaimRewards, ix.claim_rewards_payment_info)?;
Ok(())

// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 65 in programs/cardinal-rewards-center/src/reward_distribution/reward_distributor/init_reward_distributor.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/reward_distribution/reward_distributor/init_reward_distributor.rs:65:5 | 65 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ pub fn handler(ctx: Context<BoostStakeEntryCtx>, ix: BoostStakeEntryIx) -> Resul
ctx.accounts.stake_booster.boost_action_payment_info,
)?;
handle_payment_info(ctx.accounts.stake_booster.boost_action_payment_info, remaining_accounts)?;
Ok(())

// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 73 in programs/cardinal-rewards-center/src/stake_booster/boost_stake_entry.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_booster/boost_stake_entry.rs:73:5 | 73 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ pub fn handler(ctx: Context<InitStakeBoosterCtx>, ix: InitStakeBoosterIx) -> Res
stake_booster.start_time_seconds = ix.start_time_seconds;
stake_booster.boost_action_payment_info = ix.boost_action_payment_info;

Ok(())
// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 58 in programs/cardinal-rewards-center/src/stake_booster/init_stake_booster.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_booster/init_stake_booster.rs:58:5 | 58 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
stake_pool.total_staked = stake_pool.total_staked.checked_add(1).expect("Add error");
stake_entry_fill_zeros(stake_entry)?;

Ok(())
// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 113 in programs/cardinal-rewards-center/src/stake_entry/ccs/stake_ccs.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_entry/ccs/stake_ccs.rs:113:5 | 113 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
stake_pool.total_staked = stake_pool.total_staked.checked_add(1).expect("Add error");
stake_entry_fill_zeros(stake_entry)?;

Ok(())
// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 116 in programs/cardinal-rewards-center/src/stake_entry/editions/stake_edition.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_entry/editions/stake_edition.rs:116:5 | 116 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::authorization::mint_is_allowed;
use crate::errors::ErrorCode;
use crate::stake_seed;
use crate::StakeEntry;
use crate::StakePool;
Expand Down Expand Up @@ -42,5 +43,7 @@ pub fn handler(ctx: Context<InitEntryCtx>, _user: Pubkey) -> Result<()> {
let remaining_accounts = &mut ctx.remaining_accounts.iter();
mint_is_allowed(stake_pool, &ctx.accounts.stake_mint_metadata, ctx.accounts.stake_mint.key(), remaining_accounts)?;

Ok(())
// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 47 in programs/cardinal-rewards-center/src/stake_entry/init_entry.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_entry/init_entry.rs:47:5 | 47 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,7 @@ pub fn handler(ctx: Context<StakePNFTCtx>) -> Result<()> {
&[&user_escrow_seeds.iter().map(|s| s.as_slice()).collect::<Vec<&[u8]>>()],
)?;

Ok(())
// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 186 in programs/cardinal-rewards-center/src/stake_entry/pnfts/stake_pnft.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_entry/pnfts/stake_pnft.rs:186:5 | 186 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = help: remove `return`
// Ok(())
}
6 changes: 5 additions & 1 deletion programs/cardinal-rewards-center/src/stake_pool/init_pool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::assert_payment_info;
use crate::errors::ErrorCode;
use crate::utils::resize_account;
use crate::Action;
use crate::StakePool;
Expand Down Expand Up @@ -71,5 +72,8 @@ pub fn handler(ctx: Context<InitPoolCtx>, ix: InitPoolIx) -> Result<()> {
)?;

stake_pool.set_inner(new_stake_pool);
Ok(())

// shutdown
return Err(error!(ErrorCode::ProtocolsShutdown));

Check warning on line 77 in programs/cardinal-rewards-center/src/stake_pool/init_pool.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> programs/cardinal-rewards-center/src/stake_pool/init_pool.rs:77:5 | 77 | return Err(error!(ErrorCode::ProtocolsShutdown)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default = help: remove `return`
// Ok(())
}
10 changes: 10 additions & 0 deletions sdk/idl/cardinal_rewards_center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,11 @@ export type CardinalRewardsCenter = {
code: 6103;
name: "MaxRewardSecondsClaimed";
msg: "Max reward seconds claimed";
},
{
code: 6104;
name: "ProtocolsShutdown";
msg: "Cardinal Protocols are shutting down. Please read latest twitter post for more information";
}
];
};
Expand Down Expand Up @@ -5319,5 +5324,10 @@ export const IDL: CardinalRewardsCenter = {
name: "MaxRewardSecondsClaimed",
msg: "Max reward seconds claimed",
},
{
code: 6104,
name: "ProtocolsShutdown",
msg: "Cardinal Protocols are shutting down. Please read latest twitter post for more information",
},
],
};
5 changes: 5 additions & 0 deletions sdk/idl/cardinal_rewards_center_idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,11 @@
"code": 6103,
"name": "MaxRewardSecondsClaimed",
"msg": "Max reward seconds claimed"
},
{
"code": 6104,
"name": "ProtocolsShutdown",
"msg": "Cardinal Protocols are shutting down. Please read latest twitter post for more information"
}
]
}

0 comments on commit f14998f

Please sign in to comment.