Skip to content

Commit

Permalink
idl: Fix using full path types with Program (#3228)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 5, 2024
1 parent 51b21ce commit 18e9134
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
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

0 comments on commit 18e9134

Please sign in to comment.