miclockwork_network_program/jobs/stake_delegations/
job.rs1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use miclockwork_utils::thread::ThreadResponse;
3
4use crate::state::*;
5
6#[derive(Accounts)]
7pub struct StakeDelegationsJob<'info> {
8 #[account(address = Config::pubkey())]
9 pub config: Account<'info, Config>,
10
11 #[account(
12 address = Registry::pubkey(),
13 constraint = registry.locked
14 )]
15 pub registry: Account<'info, Registry>,
16
17 #[account(address = config.epoch_thread)]
18 pub thread: Signer<'info>,
19}
20
21pub fn handler(ctx: Context<StakeDelegationsJob>) -> Result<ThreadResponse> {
22 let config = &ctx.accounts.config;
23 let registry = &ctx.accounts.registry;
24 let thread = &ctx.accounts.thread;
25
26 Ok(ThreadResponse {
27 dynamic_instruction: if registry.total_workers.gt(&0) {
28 Some(
29 Instruction {
30 program_id: crate::ID,
31 accounts: crate::accounts::StakeDelegationsProcessWorker {
32 config: config.key(),
33 registry: registry.key(),
34 thread: thread.key(),
35 worker: Worker::pubkey(0),
36 }
37 .to_account_metas(Some(true)),
38 data: crate::instruction::StakeDelegationsProcessWorker {}.data(),
39 }
40 .into(),
41 )
42 } else {
43 None
44 },
45 close_to: None,
46 trigger: None,
47 })
48}