solana_loader_v2_interface/
lib.rs

1//! Instructions for the non-upgradable BPF loader.
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3
4#[cfg(feature = "bincode")]
5use {
6    solana_instruction::{AccountMeta, Instruction},
7    solana_pubkey::Pubkey,
8    solana_sdk_ids::sysvar::rent,
9};
10
11#[cfg_attr(
12    feature = "serde",
13    derive(serde_derive::Deserialize, serde_derive::Serialize)
14)]
15#[derive(Debug, PartialEq, Eq, Clone)]
16pub enum LoaderInstruction {
17    /// Write program data into an account
18    ///
19    /// # Account references
20    ///   0. [WRITE, SIGNER] Account to write to
21    Write {
22        /// Offset at which to write the given bytes
23        offset: u32,
24
25        /// Serialized program data
26        #[cfg_attr(feature = "serde", serde(with = "serde_bytes"))]
27        bytes: Vec<u8>,
28    },
29
30    /// Finalize an account loaded with program data for execution
31    ///
32    /// The exact preparation steps is loader specific but on success the loader must set the executable
33    /// bit of the account.
34    ///
35    /// # Account references
36    ///   0. [WRITE, SIGNER] The account to prepare for execution
37    ///   1. [] Rent sysvar
38    Finalize,
39}
40
41#[deprecated(since = "2.2.0", note = "Use loader-v4 instead")]
42#[cfg(feature = "bincode")]
43pub fn write(
44    account_pubkey: &Pubkey,
45    program_id: &Pubkey,
46    offset: u32,
47    bytes: Vec<u8>,
48) -> Instruction {
49    let account_metas = vec![AccountMeta::new(*account_pubkey, true)];
50    Instruction::new_with_bincode(
51        *program_id,
52        &LoaderInstruction::Write { offset, bytes },
53        account_metas,
54    )
55}
56
57#[deprecated(since = "2.2.0", note = "Use loader-v4 instead")]
58#[cfg(feature = "bincode")]
59pub fn finalize(account_pubkey: &Pubkey, program_id: &Pubkey) -> Instruction {
60    let account_metas = vec![
61        AccountMeta::new(*account_pubkey, true),
62        AccountMeta::new_readonly(rent::id(), false),
63    ];
64    Instruction::new_with_bincode(*program_id, &LoaderInstruction::Finalize, account_metas)
65}