Files
solana/sdk/src/compute_budget.rs

59 lines
1.6 KiB
Rust
Raw Normal View History

2021-07-16 00:31:22 -07:00
#![cfg(feature = "full")]
use {
crate::instruction::Instruction,
2022-02-11 16:23:16 -08:00
borsh::{BorshDeserialize, BorshSerialize},
2021-07-16 00:31:22 -07:00
};
crate::declare_id!("ComputeBudget111111111111111111111111111111");
/// Compute Budget Instructions
#[derive(
2022-02-11 16:23:16 -08:00
AbiExample,
AbiEnumVisitor,
2021-07-16 00:31:22 -07:00
BorshDeserialize,
2022-02-11 16:23:16 -08:00
BorshSerialize,
2021-07-16 00:31:22 -07:00
Clone,
2022-02-11 16:23:16 -08:00
Debug,
Deserialize,
2021-07-16 00:31:22 -07:00
PartialEq,
2022-02-11 16:23:16 -08:00
Serialize,
2021-07-16 00:31:22 -07:00
)]
pub enum ComputeBudgetInstruction {
/// Request a specific maximum number of compute units the transaction is
2022-02-11 16:23:16 -08:00
/// allowed to consume and an additional fee to pay.
RequestUnits {
/// Units to request
units: u32,
/// Additional fee to add
additional_fee: u32,
},
/// Request a specific transaction-wide program heap region size in bytes.
/// The value requested must be a multiple of 1024. This new heap region
/// size applies to each program executed, including all calls to CPIs.
RequestHeapFrame(u32),
2021-07-16 00:31:22 -07:00
}
2021-07-22 10:18:51 -07:00
impl ComputeBudgetInstruction {
/// Create a `ComputeBudgetInstruction::RequestUnits` `Instruction`
2022-02-11 16:23:16 -08:00
pub fn request_units(units: u32, additional_fee: u32) -> Instruction {
Instruction::new_with_borsh(
id(),
&ComputeBudgetInstruction::RequestUnits {
units,
additional_fee,
},
vec![],
)
2021-07-22 10:18:51 -07:00
}
/// Create a `ComputeBudgetInstruction::RequestHeapFrame` `Instruction`
pub fn request_heap_frame(bytes: u32) -> Instruction {
Instruction::new_with_borsh(
id(),
&ComputeBudgetInstruction::RequestHeapFrame(bytes),
vec![],
)
}
2021-07-16 00:31:22 -07:00
}