Add tracing log macro that defaults to noop

Change-Id: I5ae1cf9e539a08aa9d820e3bf643a311b2f9080e
This commit is contained in:
Reisen 2021-06-30 20:49:08 +00:00
parent 2e4279c964
commit 18e52aafe6
2 changed files with 21 additions and 1 deletions

View File

@ -10,9 +10,10 @@ name = "solitaire"
[features] [features]
client = ["no-entrypoint"] client = ["no-entrypoint"]
no-entrypoint = []
cpi = ["no-entrypoint"] cpi = ["no-entrypoint"]
default = [] default = []
no-entrypoint = []
trace = []
[dependencies] [dependencies]
borsh = "0.8.1" borsh = "0.8.1"

View File

@ -3,6 +3,25 @@ use std::ops::{
DerefMut, DerefMut,
}; };
/// A wrapper around Solana's `msg!` macro that is a no-op by default, allows for adding traces
/// through the application that can be toggled during tests.
#[macro_export]
macro_rules! trace {
( $($arg:tt)* ) => { $crate::trace_impl!( $($arg)* ) };
}
#[cfg(feature = "trace")]
#[macro_export]
macro_rules! trace_impl {
( $($arg:tt)* ) => { solana_program::msg!( $($arg)* ) };
}
#[cfg(not(feature = "trace"))]
#[macro_export]
macro_rules! trace_impl {
( $($arg:tt)* ) => {}
}
/// This is our main codegen macro. It takes as input a list of enum-like variants mapping field /// This is our main codegen macro. It takes as input a list of enum-like variants mapping field
/// types to function calls. The generated code produces: /// types to function calls. The generated code produces:
/// ///