solana_block_decoder/instruction/
compiled_instruction.rs

1use {
2    serde_derive::{Deserialize, Serialize},
3    solana_program::short_vec,
4    solana_transaction_status::{
5        UiCompiledInstruction,
6    },
7};
8
9/// A compact encoding of an instruction.
10///
11/// A `CompiledInstruction` is a component of a multi-instruction [`Message`],
12/// which is the core of a Solana transaction. It is created during the
13/// construction of `Message`. Most users will not interact with it directly.
14///
15/// [`Message`]: crate::message::Message
16#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
17#[serde(rename_all = "camelCase")]
18pub struct CompiledInstruction {
19    /// Index into the transaction keys array indicating the program account that executes this instruction.
20    pub program_id_index: u8,
21    /// Ordered indices into the transaction keys array indicating which accounts to pass to the program.
22    #[serde(with = "short_vec")]
23    pub accounts: Vec<u8>,
24    /// The program input data.
25    #[serde(with = "short_vec")]
26    pub data: Vec<u8>,
27}
28
29impl From<UiCompiledInstruction> for CompiledInstruction {
30    fn from(ui_compiled_instruction: UiCompiledInstruction) -> Self {
31        Self {
32            program_id_index: ui_compiled_instruction.program_id_index,
33            accounts: ui_compiled_instruction.accounts,
34            data: bs58::decode(ui_compiled_instruction.data).into_vec().unwrap(),
35        }
36    }
37}
38
39impl From<CompiledInstruction> for solana_sdk::instruction::CompiledInstruction {
40    fn from(instr: CompiledInstruction) -> Self {
41        Self {
42            program_id_index: instr.program_id_index,
43            accounts: instr.accounts,
44            data: instr.data,
45        }
46    }
47}