Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lang/attribute/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ pub fn account(
#[automatically_derived]
impl #impl_gen anchor_lang::Owner for #account_name #type_gen #where_clause {
fn owner() -> Pubkey {
crate::ID
// In a doctest the ID will be in the current scope, not the crate root
#[cfg(not(doctest))]
{ crate::ID }
#[cfg(doctest)]
{ ID }
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion lang/attribute/event/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
.collect();

let ix = anchor_lang::solana_program::instruction::Instruction::new_with_bytes(
crate::ID,
// In a doctest the ID will be in the current scope, not the crate root
#[cfg(not(doctest))]
{ crate::ID },
#[cfg(doctest)]
{ ID },
&ix_data,
vec![
anchor_lang::solana_program::instruction::AccountMeta::new_readonly(
Expand Down
14 changes: 12 additions & 2 deletions lang/syn/src/codegen/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
let impl_exit = exit::generate(accs);
let bumps_struct = bumps::generate(accs);

let __client_accounts_mod = __client_accounts::generate(accs, quote!(crate::ID));
let __cpi_client_accounts_mod = __cpi_client_accounts::generate(accs, quote!(crate::ID));
let program_id = quote! {
// In a doctest the ID will be in the current scope, not the crate root
{
#[cfg(not(doctest))]
{ crate::ID }
#[cfg(doctest)]
{ ID }
}
};

let __client_accounts_mod = __client_accounts::generate(accs, program_id.clone());
let __cpi_client_accounts_mod = __cpi_client_accounts::generate(accs, program_id);

let ret = quote! {
#impl_try_accounts
Expand Down
6 changes: 5 additions & 1 deletion lang/syn/src/codegen/program/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub fn idl_accounts_and_functions() -> proc_macro2::TokenStream {
// works. Namespaces are the root of most of the problem.
impl anchor_lang::Owner for IdlAccount {
fn owner() -> Pubkey {
crate::ID
// In a doctest the ID will be in the current scope, not the crate root
#[cfg(not(doctest))]
{ crate::ID }
#[cfg(doctest)]
{ ID }
}
}

Expand Down