Files
khadhroony-solana-project/crates/ksp-interface-lib/src/program_account_meta.rs
2026-08-28 05:04:10 +02:00

53 lines
1.6 KiB
Rust

// file: crates/ksp-interface-lib/src/program_account_meta.rs
// version: 1
/// Maximum number of account metas admitted by one passive Program instruction contract.
pub const MAX_PROGRAM_INSTRUCTION_ACCOUNTS: usize = 255;
/// Passive account metadata attached to one Program instruction.
///
/// Account metas preserve the caller-provided Solana account identity and the
/// signer/writable flags without applying Program-specific semantics.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ProgramAccountMeta {
pubkey: crate::Pubkey,
is_signer: bool,
is_writable: bool,
}
impl ProgramAccountMeta {
/// Creates one read-only account meta.
#[must_use]
pub const fn readonly(pubkey: crate::Pubkey, is_signer: bool) -> Self {
return Self { pubkey, is_signer, is_writable: false };
}
/// Creates one writable account meta.
#[must_use]
pub const fn writable(pubkey: crate::Pubkey, is_signer: bool) -> Self {
return Self { pubkey, is_signer, is_writable: true };
}
/// Returns whether this account must sign the containing instruction.
#[must_use]
pub const fn is_signer(&self) -> bool {
return self.is_signer;
}
/// Returns whether this account may be written by the containing instruction.
#[must_use]
pub const fn is_writable(&self) -> bool {
return self.is_writable;
}
/// Returns the canonical account address.
#[must_use]
pub const fn pubkey(&self) -> &crate::Pubkey {
return &self.pubkey;
}
}
#[cfg(test)]
#[path = "../unit_tests/program_account_meta.rs"]
mod tests;