antegen_fiber_program/state/
fiber.rs1use crate::constants::*;
2use crate::state::instruction::*;
3use anchor_lang::prelude::*;
4use anchor_lang::solana_program::instruction::Instruction;
5
6pub trait FiberInstructionProcessor {
8 fn get_instruction(&self, executor: &Pubkey) -> Result<Instruction>;
11}
12
13#[account]
16#[derive(Debug, InitSpace)]
17pub struct FiberState {
18 pub thread: Pubkey,
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(
35 &[SEED_THREAD_FIBER, thread.as_ref(), &[fiber_index]],
36 &crate::ID,
37 )
38 .0
39 }
40}
41
42impl FiberInstructionProcessor for FiberState {
43 fn get_instruction(&self, executor: &Pubkey) -> Result<Instruction> {
44 let compiled = CompiledInstructionV0::try_from_slice(&self.compiled_instruction)?;
46 let mut instruction = decompile_instruction(&compiled)?;
48
49 for acc in instruction.accounts.iter_mut() {
51 if acc.pubkey.eq(&PAYER_PUBKEY) {
52 acc.pubkey = *executor;
53 }
54 }
55
56 Ok(instruction)
57 }
58}