Copy contract Dex {
bool private _paused;
function setPaused(bool paused) external {
if (msg.sender != owner) {
revert NotOwner();
}
_paused = paused;
}
}
Copy #[account]
pub struct Config {
pub authority: Pubkey,
pub paused: bool,
}
#[derive(Accounts)]
pub struct SetPaused<'info> {
pub signer: Signer<'info>,
#[account(mut, constraint = config.authority == signer.key() @ ErrorCode::Unauthorized)]
pub config: Account<'info, Config>
}
pub fn set_paused(Context<SetPaused, bool paused) -> Result<()> {
ctx.accounts.config.paused = paused;
}
Copy #[account]
pub struct Config {
pub authority: Pubkey,
pub paused: bool,
}
#[derive(Accounts)]
pub struct SetPaused<'info> {
pub signer: Signer<'info>,
#[account(mut, constraint = config.authority == signer.key() @ ErrorCode::Unauthorized)]
pub config: Account<'info, Config>
}
pub fn set_paused(Context<SetPaused, bool paused) -> Result<()> {
require!(ctx.accounts.config.authority == ctx.accounts.signer.key(), ErrorCode::Unauthorized);
ctx.accounts.config.paused = paused;
}
Copy #[account]
pub struct Config {
pub authority: Pubkey,
pub paused: bool,
}
#[derive(Accounts)]
pub struct SetPaused<'info> {
pub authority: Signer<'info>,
#[account(mut, has_one = authority) @ ErrorCode::Unauthorized)]
pub config: Account<'info, Config>
}
pub fn set_paused(Context<SetPaused, bool paused) -> Result<()> {
ctx.accounts.config.paused = paused;
}