devol_accounts_kit/instructions_data/as_transaction_instruction/
start_next_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::worker_account::WorkerAccount;
9use crate::dvl_client::dvl_client::DvlClient;
10use crate::instructions_data::as_transaction_instruction::as_transaction_instruction::AsTransactionInstruction;
11use crate::instructions_data::dvl_instruction_data::DvlInstructionData;
12use crate::instructions_data::start_next_pool::InstructionStartNextPool;
13
14pub struct StartNextPoolTransactionParams {
15 pub worker_id: u32,
16}
17
18#[async_trait]
19impl AsTransactionInstruction for InstructionStartNextPool {
20 type DvlTransactionInstructionParams = StartNextPoolTransactionParams;
21
22 async fn as_transaction_instruction(
23 &self,
24 client: &DvlClient,
25 signer: &Pubkey,
26 transaction_params: Self::DvlTransactionInstructionParams,
27 ) -> Result<Box<Instruction>, Box<dyn Error>> {
28 let data = self.to_vec_le();
29 let root_acc_key = client.account_public_key::<RootAccount>(()).await?;
30 let worker_acc_key = client.account_public_key::<WorkerAccount>(DvlIndexParam { id: transaction_params.worker_id }).await?;
31 let pools_trace_key = client.account_public_key::<PoolsTraceAccount>(DvlIndexParam { id: transaction_params.worker_id }).await?;
32 let account_metas = Vec::from([
33 AccountMeta {
34 pubkey: *signer,
35 is_signer: true,
36 is_writable: false,
37 },
38 AccountMeta {
39 pubkey: *root_acc_key,
40 is_signer: false,
41 is_writable: false,
42 },
43 AccountMeta {
44 pubkey: *worker_acc_key,
45 is_signer: false,
46 is_writable: true,
47 },
48 AccountMeta {
49 pubkey: *pools_trace_key,
50 is_signer: false,
51 is_writable: true,
52 },
53 ]);
54 Ok(Box::from(Instruction::new_with_bytes(
55 client.program_id,
56 &*data,
57 account_metas,
58 )))
59 }
60}