solana_message/
compiled_instruction.rs1#[cfg(feature = "serde")]
2use serde_derive::{Deserialize, Serialize};
3#[cfg(feature = "frozen-abi")]
4use solana_frozen_abi_macro::AbiExample;
5use {solana_address::Address, solana_sanitize::Sanitize};
6
7#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
15#[cfg_attr(
16 feature = "serde",
17 derive(Deserialize, Serialize),
18 serde(rename_all = "camelCase")
19)]
20#[derive(Debug, PartialEq, Eq, Clone)]
21pub struct CompiledInstruction {
22 pub program_id_index: u8,
24 #[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
26 pub accounts: Vec<u8>,
27 #[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
29 pub data: Vec<u8>,
30}
31
32impl Sanitize for CompiledInstruction {}
33
34impl CompiledInstruction {
35 #[cfg(feature = "bincode")]
36 pub fn new<T: serde::Serialize>(program_ids_index: u8, data: &T, accounts: Vec<u8>) -> Self {
37 let data = bincode::serialize(data).unwrap();
38 Self {
39 program_id_index: program_ids_index,
40 accounts,
41 data,
42 }
43 }
44
45 pub fn new_from_raw_parts(program_id_index: u8, data: Vec<u8>, accounts: Vec<u8>) -> Self {
46 Self {
47 program_id_index,
48 accounts,
49 data,
50 }
51 }
52
53 pub fn program_id<'a>(&self, program_ids: &'a [Address]) -> &'a Address {
54 &program_ids[self.program_id_index as usize]
55 }
56}