devol_accounts_kit/instructions_data/as_transaction_instruction/
fin_pool.rs1use std::error::Error;
2use async_trait::async_trait;
3use solana_program::instruction::{AccountMeta, Instruction};
4use solana_program::pubkey::Pubkey;
5use crate::account_readers::dvl_readable::DvlIndexParam;
6use crate::accounts::root::root_account::RootAccount;
7use crate::accounts::worker::pools_trace::pools_trace_account::PoolsTraceAccount;
8use crate::accounts::worker::tasks_trace::tasks_trace_account::TasksTraceAccount;
9use crate::accounts::worker::worker_account::WorkerAccount;
10use crate::dvl_client::dvl_client::DvlClient;
11use crate::instructions_data::as_transaction_instruction::as_transaction_instruction::AsTransactionInstruction;
12use crate::instructions_data::dvl_instruction_data::DvlInstructionData;
13use crate::instructions_data::fin_pool::InstructionFinPool;
14
15pub struct FinPoolTransactionParams {
16 pub worker_id: u32,
17}
18
19#[async_trait]
20impl AsTransactionInstruction for InstructionFinPool {
21 type DvlTransactionInstructionParams = FinPoolTransactionParams;
22
23 async fn as_transaction_instruction(
24 &self,
25 client: &DvlClient,
26 signer: &Pubkey,
27 transaction_params: Self::DvlTransactionInstructionParams,
28 ) -> Result<Box<Instruction>, Box<dyn Error>> {
29 let data = self.to_vec_le();
30 let root_acc_key = client.account_public_key::<RootAccount>(()).await?;
31 let worker_acc_key = client.account_public_key::<WorkerAccount>(DvlIndexParam { id: transaction_params.worker_id }).await?;
32 let pools_trace_key = client.account_public_key::<PoolsTraceAccount>(DvlIndexParam { id: transaction_params.worker_id }).await?;
33 let tasks_trace_key = client.account_public_key::<TasksTraceAccount>(DvlIndexParam { id: transaction_params.worker_id }).await?;
34 let account_metas = Vec::from([
35 AccountMeta {
36 pubkey: *signer,
37 is_signer: true,
38 is_writable: false,
39 },
40 AccountMeta {
41 pubkey: *root_acc_key,
42 is_signer: false,
43 is_writable: false,
44 },
45 AccountMeta {
46 pubkey: *worker_acc_key,
47 is_signer: false,
48 is_writable: true,
49 },
50 AccountMeta {
51 pubkey: *tasks_trace_key,
52 is_signer: false,
53 is_writable: true,
54 },
55 AccountMeta {
56 pubkey: *pools_trace_key,
57 is_signer: false,
58 is_writable: true,
59 },
60 ]);
61 Ok(Box::from(Instruction::new_with_bytes(
62 client.program_id,
63 &*data,
64 account_metas,
65 )))
66 }
67}