Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idl: Fix using full path types with Program #3228

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Remove `arrayref` dependency ([#3201](https://github.com/coral-xyz/anchor/pull/3201)).
- cli: Fix template code shouldn't escape ([#3210](https://github.com/coral-xyz/anchor/pull/3210)).
- idl: Fix using `address` constraint with non-const expressions ([#3216](https://github.com/coral-xyz/anchor/pull/3216)).
- idl: Fix using full path types with `Program` ([#3228](https://github.com/coral-xyz/anchor/pull/3228)).

### Breaking

Expand Down
16 changes: 5 additions & 11 deletions lang/syn/src/idl/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,12 @@ pub fn gen_idl_build_impl_accounts_struct(accounts: &AccountsStruct) -> TokenStr

fn get_address(acc: &Field) -> TokenStream {
match &acc.ty {
Ty::Program(ty) => ty
.account_type_path
.path
.segments
.last()
.map(|seg| &seg.ident)
.map(|ident| quote! { Some(#ident::id().to_string()) })
.unwrap_or_else(|| quote! { None }),
Ty::Sysvar(_) => {
Ty::Program(_) | Ty::Sysvar(_) => {
let ty = acc.account_ty();
let sysvar_id_trait = quote!(anchor_lang::solana_program::sysvar::SysvarId);
quote! { Some(<#ty as #sysvar_id_trait>::id().to_string()) }
let id_trait = matches!(acc.ty, Ty::Program(_))
.then(|| quote!(anchor_lang::Id))
.unwrap_or_else(|| quote!(anchor_lang::solana_program::sysvar::SysvarId));
quote! { Some(<#ty as #id_trait>::id().to_string()) }
}
_ => acc
.constraints
Expand Down
1 change: 1 addition & 0 deletions tests/idl/programs/new-idl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ pub struct AccountAndEventFieldAccount {
pub struct FullPath<'info> {
#[account(zero)]
pub account: Account<'info, FullPathAccount>,
pub external_program: Program<'info, external::program::External>,
}

#[account]
Expand Down
Loading