error macro

This commit is contained in:
Hardhat Chad
2024-08-25 20:00:51 +00:00
parent b9248befdc
commit 3a3550ced5
2 changed files with 16 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
use num_enum::IntoPrimitive;
use solana_program::program_error::ProgramError;
use ore_utils::*;
use thiserror::Error;
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
@@ -23,8 +23,4 @@ pub enum OreError {
AuthFailed = 7,
}
impl From<OreError> for ProgramError {
fn from(e: OreError) -> Self {
ProgramError::Custom(e as u32)
}
}
error!(OreError);

View File

@@ -78,10 +78,13 @@ macro_rules! account {
}
#[macro_export]
macro_rules! instruction {
macro_rules! error {
($struct_name:ident) => {
$crate::impl_to_bytes!($struct_name);
$crate::impl_instruction_from_bytes!($struct_name);
impl From<$struct_name> for solana_program::program_error::ProgramError {
fn from(e: $struct_name) -> Self {
solana_program::program_error::ProgramError::Custom(e as u32)
}
}
};
}
@@ -92,3 +95,11 @@ macro_rules! event {
$crate::impl_from_bytes!($struct_name);
};
}
#[macro_export]
macro_rules! instruction {
($struct_name:ident) => {
$crate::impl_to_bytes!($struct_name);
$crate::impl_instruction_from_bytes!($struct_name);
};
}