gemachain_program/
loader_upgradeable_instruction.rs

1//! Upgradeable loader instruction definitions
2
3#[repr(u8)]
4#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
5pub enum UpgradeableLoaderInstruction {
6    /// Initialize a Buffer account.
7    ///
8    /// A Buffer account is an intermediary that once fully populated is used
9    /// with the `DeployWithMaxDataLen` instruction to populate the program's
10    /// ProgramData account.
11    ///
12    /// The `InitializeBuffer` instruction requires no signers and MUST be
13    /// included within the same Transaction as the system program's
14    /// `CreateAccount` instruction that creates the account being initialized.
15    /// Otherwise another party may initialize the account.
16    ///
17    /// # Account references
18    ///   0. `[writable]` source account to initialize.
19    ///   1. `[]` Buffer authority, optional, if omitted then the buffer will be
20    ///      immutable.
21    InitializeBuffer,
22
23    /// Write program data into a Buffer account.
24    ///
25    /// # Account references
26    ///   0. `[writable]` Buffer account to write program data to.
27    ///   1. `[signer]` Buffer authority
28    Write {
29        /// Offset at which to write the given bytes.
30        offset: u32,
31        /// Serialized program data
32        #[serde(with = "serde_bytes")]
33        bytes: Vec<u8>,
34    },
35
36    /// Deploy an executable program.
37    ///
38    /// A program consists of a Program and ProgramData account pair.
39    ///   - The Program account's address will serve as the program id for any
40    ///     instructions that execute this program.
41    ///   - The ProgramData account will remain mutable by the loader only and
42    ///     holds the program data and authority information.  The ProgramData
43    ///     account's address is derived from the Program account's address and
44    ///     created by the DeployWithMaxDataLen instruction.
45    ///
46    /// The ProgramData address is derived from the Program account's address as
47    /// follows:
48    ///
49    /// ```
50    /// # use gemachain_program::pubkey::Pubkey;
51    /// # use gemachain_program::bpf_loader_upgradeable;
52    /// # let program_address = &[];
53    /// let (program_data_address, _) = Pubkey::find_program_address(
54    ///      &[program_address],
55    ///      &bpf_loader_upgradeable::id()
56    ///  );
57    /// ```
58    ///
59    /// The `DeployWithMaxDataLen` instruction does not require the ProgramData
60    /// account be a signer and therefore MUST be included within the same
61    /// Transaction as the system program's `CreateAccount` instruction that
62    /// creates the Program account. Otherwise another party may initialize the
63    /// account.
64    ///
65    /// # Account references
66    ///   0. `[signer]` The payer account that will pay to create the ProgramData
67    ///      account.
68    ///   1. `[writable]` The uninitialized ProgramData account.
69    ///   2. `[writable]` The uninitialized Program account.
70    ///   3. `[writable]` The Buffer account where the program data has been
71    ///      written.  The buffer account's authority must match the program's
72    ///      authority
73    ///   4. `[]` Rent sysvar.
74    ///   5. `[]` Clock sysvar.
75    ///   6. `[]` System program (`gemachain_sdk::system_program::id()`).
76    ///   7. `[signer]` The program's authority
77    DeployWithMaxDataLen {
78        /// Maximum length that the program can be upgraded to.
79        max_data_len: usize,
80    },
81
82    /// Upgrade a program.
83    ///
84    /// A program can be updated as long as the program's authority has not been
85    /// set to `None`.
86    ///
87    /// The Buffer account must contain sufficient carats to fund the
88    /// ProgramData account to be rent-exempt, any additional carats left over
89    /// will be transferred to the spill account, leaving the Buffer account
90    /// balance at zero.
91    ///
92    /// # Account references
93    ///   0. `[writable]` The ProgramData account.
94    ///   1. `[writable]` The Program account.
95    ///   2. `[writable]` The Buffer account where the program data has been
96    ///      written.  The buffer account's authority must match the program's
97    ///      authority
98    ///   3. `[writable]` The spill account.
99    ///   4. `[]` Rent sysvar.
100    ///   5. `[]` Clock sysvar.
101    ///   6. `[signer]` The program's authority.
102    Upgrade,
103
104    /// Set a new authority that is allowed to write the buffer or upgrade the
105    /// program.  To permanently make the buffer immutable or disable program
106    /// updates omit the new authority.
107    ///
108    /// # Account references
109    ///   0. `[writable]` The Buffer or ProgramData account to change the
110    ///      authority of.
111    ///   1. `[signer]` The current authority.
112    ///   2. `[]` The new authority, optional, if omitted then the program will
113    ///      not be upgradeable.
114    SetAuthority,
115
116    /// Closes an account owned by the upgradeable loader of all carats and
117    /// withdraws all the carats
118    ///
119    /// # Account references
120    ///   0. `[writable]` The account to close, if closing a program must be the
121    ///      ProgramData account.
122    ///   1. `[writable]` The account to deposit the closed account's carats.
123    ///   2. `[signer]` The account's authority, Optional, required for
124    ///      initialized accounts.
125    ///   3. `[writable]` The associated Program account if the account to close
126    ///      is a ProgramData account.
127    Close,
128}