solana_sdk/
compute_budget.rs1#![cfg(feature = "full")]
4
5#[cfg(feature = "borsh")]
6use {
7 crate::instruction::Instruction,
8 borsh::{BorshDeserialize, BorshSerialize},
9};
10
11crate::declare_id!("ComputeBudget111111111111111111111111111111");
12
13#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))]
15#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
16#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
17pub enum ComputeBudgetInstruction {
18 Unused, RequestHeapFrame(u32),
24 SetComputeUnitLimit(u32),
26 SetComputeUnitPrice(u64),
29 SetLoadedAccountsDataSizeLimit(u32),
31}
32
33impl ComputeBudgetInstruction {
34 #[cfg(feature = "borsh")]
35 pub fn request_heap_frame(bytes: u32) -> Instruction {
37 Instruction::new_with_borsh(id(), &Self::RequestHeapFrame(bytes), vec![])
38 }
39
40 #[cfg(feature = "borsh")]
41 pub fn set_compute_unit_limit(units: u32) -> Instruction {
43 Instruction::new_with_borsh(id(), &Self::SetComputeUnitLimit(units), vec![])
44 }
45
46 #[cfg(feature = "borsh")]
47 pub fn set_compute_unit_price(micro_lamports: u64) -> Instruction {
49 Instruction::new_with_borsh(id(), &Self::SetComputeUnitPrice(micro_lamports), vec![])
50 }
51
52 #[cfg(all(feature = "dev-context-only-utils", feature = "borsh"))]
55 pub fn pack(self) -> Result<Vec<u8>, borsh::io::Error> {
56 borsh::to_vec(&self)
57 }
58
59 #[cfg(feature = "borsh")]
60 pub fn set_loaded_accounts_data_size_limit(bytes: u32) -> Instruction {
62 Instruction::new_with_borsh(id(), &Self::SetLoadedAccountsDataSizeLimit(bytes), vec![])
63 }
64}