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 address constraint with non-const expressions #3216

Conversation

acheroncrypto
Copy link
Collaborator

Problem

IDL generation fails if you use non-const expressions with the address constraint:

#[derive(Accounts)]
pub struct MyIx {
    #[account(address = my_account.authority()])
    pub authority: Signer<'info>,
    pub my_account: Account<'info, MyAccount>,
}

#[account]
pub struct MyAccount {
    pub authority: Pubkey,
}

impl MyAccount {
    pub fn authority(&self) -> Pubkey {
        self.authority
    }
}

We had a similar problem in #2912, but that was only specific to field expressions and was fixed in #3034.

Summary of changes

Rather than assuming all expressions (other than field expressions) are valid for the address field (in the IDL), only assume the following expressions are valid:

  • If the last segment of the path is all uppercase (const) e.g. my_program::ID
  • Function call with no arguments (const fn) e.g. my_program::id()

For everything else, skip the address field resolution.

Copy link

vercel bot commented Aug 31, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added idl related to the IDL, either program or client side fix Bug fix PR labels Aug 31, 2024
@acheroncrypto acheroncrypto merged commit 467ae43 into coral-xyz:master Aug 31, 2024
49 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PR idl related to the IDL, either program or client side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant