use {
crate::state::{Webhook, SEED_WEBHOOK},
anchor_lang::{prelude::*, system_program},
};
static TIMEOUT_THRESHOLD: u64 = 100; #[derive(Accounts)]
#[instruction()]
pub struct WebhookRespond<'info> {
#[account(mut)]
pub ack_authority: Signer<'info>,
#[account(
mut,
seeds = [
SEED_WEBHOOK,
webhook.authority.as_ref(),
],
bump,
)]
pub webhook: Account<'info, Webhook>,
#[account(address = system_program::ID)]
pub system_program: Program<'info, System>,
#[account()]
pub worker: SystemAccount<'info>,
}
pub fn handler<'info>(ctx: Context<WebhookRespond>) -> Result<()> {
let webhook = &mut ctx.accounts.webhook;
let worker = &mut ctx.accounts.worker;
let current_slot = Clock::get().unwrap().slot;
let is_authorized_worker = webhook.workers.contains(&worker.key());
let is_within_execution_window =
current_slot < webhook.created_at.checked_add(TIMEOUT_THRESHOLD).unwrap();
if is_authorized_worker && is_within_execution_window {
} else {
}
Ok(())
}