105 lines
4.2 KiB
Rust
105 lines
4.2 KiB
Rust
|
//! Upgradeable loader instruction definitions
|
||
|
|
||
|
#[repr(u8)]
|
||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||
|
pub enum UpgradeableLoaderInstruction {
|
||
|
/// Initialize a Buffer account.
|
||
|
///
|
||
|
/// A Buffer account is an intermediary that once fully populated is used
|
||
|
/// with the `DeployWithMaxDataLen` instruction to populate the program's
|
||
|
/// ProgramData account.
|
||
|
///
|
||
|
/// The `InitializeBuffer` instruction requires no signers and MUST be
|
||
|
/// included within the same Transaction as the system program's
|
||
|
/// `CreateAccount` instruction that creates the account being initialized.
|
||
|
/// Otherwise another party may initialize the account.
|
||
|
///
|
||
|
/// # Account references
|
||
|
/// 0. [writable] source account to initialize.
|
||
|
InitializeBuffer,
|
||
|
|
||
|
/// Write program data into a Buffer account.
|
||
|
///
|
||
|
/// # Account references
|
||
|
/// 0. [writable, signer] Buffer account to write program data to.
|
||
|
Write {
|
||
|
/// Offset at which to write the given bytes.
|
||
|
offset: u32,
|
||
|
/// Serialized program data
|
||
|
#[serde(with = "serde_bytes")]
|
||
|
bytes: Vec<u8>,
|
||
|
},
|
||
|
|
||
|
/// Deploy an executable program.
|
||
|
///
|
||
|
/// A program consists of a Program and ProgramData account pair.
|
||
|
/// - The Program account's address will serve as the program id any
|
||
|
/// instructions that execute this program.
|
||
|
/// - The ProgramData account will remain mutable by the loader only and
|
||
|
/// holds the program data and authority information. The ProgramData
|
||
|
/// account's address is derived from the Program account's address and
|
||
|
/// created by the DeployWithMaxDataLen instruction.
|
||
|
///
|
||
|
/// The ProgramData address is derived from the Program account's address as
|
||
|
/// follows:
|
||
|
///
|
||
|
/// `let (program_data_address, _) = Pubkey::find_program_address(
|
||
|
/// &[program_address],
|
||
|
/// &bpf_loader_upgradeable::id()
|
||
|
/// );`
|
||
|
///
|
||
|
/// The `DeployWithMaxDataLen` instruction does not require the ProgramData
|
||
|
/// account be a signer and therefore MUST be included within the same
|
||
|
/// Transaction as the system program's `CreateAccount` instruction that
|
||
|
/// creates the Program account. Otherwise another party may initialize
|
||
|
/// the account.
|
||
|
///
|
||
|
/// # Account references
|
||
|
/// 0. [Signer] The payer account that will pay to create the ProgramData
|
||
|
/// account.
|
||
|
/// 1. [writable] The uninitialized ProgramData account.
|
||
|
/// 2. [writable] The uninitialized Program account.
|
||
|
/// 3. [writable] The Buffer account where the program data has been
|
||
|
/// written.
|
||
|
/// 4. [] Rent sysvar.
|
||
|
/// 5. [] Clock sysvar.
|
||
|
/// 6. [] System program (`solana_sdk::system_program::id()`).
|
||
|
/// 7. [] The program's authority, optional, if omitted then the program
|
||
|
/// will no longer upgradeable.
|
||
|
DeployWithMaxDataLen {
|
||
|
/// Maximum length that the program can be upgraded to.
|
||
|
max_data_len: usize,
|
||
|
},
|
||
|
|
||
|
/// Upgrade a program.
|
||
|
///
|
||
|
/// A program can be updated as long as the program's authority has not been
|
||
|
/// set to `None`.
|
||
|
///
|
||
|
/// The Buffer account must contain sufficient lamports to fund the
|
||
|
/// ProgramData account to be rent-exempt, any additional lamports left over
|
||
|
/// will be transferred to the spill, account leaving the Buffer account
|
||
|
/// balance at zero.
|
||
|
///
|
||
|
/// # Account references
|
||
|
/// 0. [writable] The ProgramData account.
|
||
|
/// 1. [] The Program account.
|
||
|
/// 2. [Writable] The Buffer account where the program data has been
|
||
|
/// written.
|
||
|
/// 3. [writable] The spill account.
|
||
|
/// 4. [] Rent sysvar.
|
||
|
/// 5. [] Clock sysvar.
|
||
|
/// 6. [signer] The program's authority.
|
||
|
Upgrade,
|
||
|
|
||
|
/// Set a new authority that is allowed to upgrade the program. To
|
||
|
/// permanently disable program updates omit the new authority.
|
||
|
///
|
||
|
/// # Account references
|
||
|
/// 0. `[writable]` The ProgramData account to change the authority of.
|
||
|
/// 1. `[signer]` The current authority.
|
||
|
/// 2. `[]` The new authority, optional, if omitted then the program will
|
||
|
/// not be upgradeable.
|
||
|
SetAuthority,
|
||
|
}
|