Skip to content

Commit

Permalink
loggable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Oct 18, 2024
1 parent f996ae0 commit f3bb2c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use solana_program::log::sol_log;
10 changes: 10 additions & 0 deletions lib/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ macro_rules! event {
($struct_name:ident) => {
$crate::impl_to_bytes!($struct_name);
$crate::impl_from_bytes!($struct_name);

impl $crate::Loggable for $struct_name {
fn log(&self) {
solana_program::log::sol_log_data(&[self.to_bytes()]);
}

fn log_return(&self) {
solana_program::program::set_return_data(self.to_bytes());
}
}
};
}

Expand Down
5 changes: 5 additions & 0 deletions lib/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub trait CloseAccount<'a, 'info> {
fn close(&'a self, to: &'a AccountInfo<'info>) -> Result<(), ProgramError>;
}

pub trait Loggable {
fn log(&self);
fn log_return(&self);
}

pub trait ProgramOwner {
fn owner() -> Pubkey;
}
Expand Down

0 comments on commit f3bb2c6

Please sign in to comment.