antegen_thread_program/state/
fiber.rs1use crate::*;
2use anchor_lang::prelude::*;
3use anchor_lang::solana_program::instruction::Instruction;
4
5pub trait FiberInstructionProcessor {
7 fn get_instruction(&self, executor: &Pubkey) -> Result<Instruction>;
10}
11
12#[account]
14#[derive(Debug, InitSpace)]
15pub struct FiberState {
16 pub thread: Pubkey,
18 pub fiber_index: u8,
20 #[max_len(1024)]
22 pub compiled_instruction: Vec<u8>,
23 pub last_executed: i64,
25 pub exec_count: u64,
27 pub priority_fee: u64,
29}
30
31impl FiberState {
32 pub fn pubkey(thread: Pubkey, fiber_index: u8) -> Pubkey {
34 Pubkey::find_program_address(&[SEED_THREAD_FIBER, thread.as_ref(), &[fiber_index]], &crate::ID).0
35 }
36}
37
38impl FiberInstructionProcessor for FiberState {
39 fn get_instruction(&self, executor: &Pubkey) -> Result<Instruction> {
40 let compiled = CompiledInstructionV0::try_from_slice(&self.compiled_instruction)?;
42 let mut instruction = decompile_instruction(&compiled)?;
44
45 for acc in instruction.accounts.iter_mut() {
47 if acc.pubkey.eq(&PAYER_PUBKEY) {
48 acc.pubkey = *executor;
49 }
50 }
51
52 Ok(instruction)
53 }
54}