lang: Add anchor-debug feature flag for logging (#253)

This commit is contained in:
Stanisław Drozd 2021-05-07 20:47:21 +02:00 committed by GitHub
parent 5d8cad6ce9
commit d08ec0326e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 45 additions and 3 deletions

View File

@ -14,6 +14,7 @@ incremented for features.
## Features
* client: Adds support for state instructions ([#248](https://github.com/project-serum/anchor/pull/248)).
* lang: Add `anchor-debug` feature flag for logging ([#253](https://github.com/project-serum/anchor/pull/253)).
* ts: Add support for u16 ([#255](https://github.com/project-serum/anchor/pull/255)).
## Breaking

View File

@ -10,6 +10,17 @@ description = "Solana Sealevel eDSL"
[features]
derive = []
default = []
anchor-debug = [
"anchor-attribute-access-control/anchor-debug",
"anchor-attribute-account/anchor-debug",
"anchor-attribute-error/anchor-debug",
"anchor-attribute-event/anchor-debug",
"anchor-attribute-interface/anchor-debug",
"anchor-attribute-program/anchor-debug",
"anchor-attribute-program/anchor-debug",
"anchor-attribute-state/anchor-debug",
"anchor-derive-accounts/anchor-debug"
]
[dependencies]
anchor-attribute-access-control = { path = "./attribute/access-control", version = "0.4.5" }

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,9 @@ edition = "2018"
[lib]
proc-macro = true
[features]
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -10,6 +10,10 @@ edition = "2018"
[lib]
proc-macro = true
[features]
default = []
anchor-debug = ["anchor-syn/anchor-debug"]
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"

View File

@ -11,6 +11,7 @@ edition = "2018"
idl = []
hash = []
default = []
anchor-debug = []
[dependencies]
proc-macro2 = "1.0"

View File

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

View File

@ -67,6 +67,10 @@ pub fn generate(program: Program) -> proc_macro2::TokenStream {
/// program, where execution begins.
#[cfg(not(feature = "no-entrypoint"))]
fn entry(program_id: &Pubkey, accounts: &[AccountInfo], ix_data: &[u8]) -> ProgramResult {
#[cfg(feature = "anchor-debug")]
{
msg!("anchor-debug is active");
}
if ix_data.len() < 8 {
return Err(ProgramError::Custom(99));
}