1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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(())
}