pub mod system;
use crate::prelude::*;
pub use star_frame_proc::StarFrameProgram;
pub trait StarFrameProgram {
type InstructionSet: InstructionSet;
type AccountDiscriminant: Pod + Eq;
const ID: Pubkey;
#[inline]
#[must_use]
fn handle_error(error: Error) -> ProgramError {
error.log();
error.into()
}
#[allow(clippy::inline_always)]
#[inline(always)]
fn entrypoint(
program_id: &'static pinocchio::pubkey::Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let program_id = bytemuck::cast_ref(program_id);
Self::InstructionSet::dispatch(program_id, accounts, instruction_data)
.map_err(Self::handle_error)
}
}
#[macro_export]
macro_rules! program_setup {
($program:ty) => {
#[allow(dead_code)]
pub type StarFrameDeclaredProgram = $program;
#[doc = r" The const program ID."]
pub const ID: $crate::prelude::Pubkey = <$program as $crate::program::StarFrameProgram>::ID;
#[doc = r" Returns `true` if given pubkey is the program ID."]
pub fn check_id(id: &$crate::prelude::Pubkey) -> bool {
id == &ID
}
#[doc = r" Returns the program ID."]
pub const fn id() -> $crate::prelude::Pubkey {
ID
}
#[test]
fn test_id() {
assert!(check_id(&id()));
}
};
}