lang: Add debug-log feature flag (#240)

This commit is contained in:
Lucio M. Tato 2021-05-05 02:24:08 -03:00 committed by GitHub
parent 6f89079332
commit 71873a77a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -21,6 +21,8 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
let name = &s.ident;
let ty = &s.raw_field.ty;
quote! {
#[cfg(feature = "debug-log")]
::solana_program::log::sol_log(stringify!(#name));
let #name: #ty = anchor_lang::Accounts::try_accounts(program_id, accounts)?;
}
}
@ -38,9 +40,13 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream {
let name = &f.typed_ident();
match f.is_init {
false => quote! {
#[cfg(feature = "debug-log")]
::solana_program::log::sol_log(stringify!(#name));
let #name = anchor_lang::Accounts::try_accounts(program_id, accounts)?;
},
true => quote! {
#[cfg(feature = "debug-log")]
::solana_program::log::sol_log(stringify!(#name));
let #name = anchor_lang::AccountsInit::try_accounts_init(program_id, accounts)?;
},
}