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

Feat: constants declared in impl blocks in seeds #2128

Merged

Conversation

stegaBOB
Copy link
Contributor

Problem:

As of now, constants declared in impl blocks, such as the impl block for an account struct, are not parsed in the seeds constraint field.

WARNING: unexpected seed category for var: SeedPath("CollectionPDA :: PREFIX", [])

A common pattern I've used is to declare the space and the seeds constant for a specific PDA account as a constant impl of the account struct. This PR fixes adds the necessary parsing to make this work.

IDL behavior with this PR:

...
{
  "name": "collectionPda",
  "isMut": true,
  "isSigner": false,
  "pda": {
    "seeds": [
      {
        "kind": "const",
        "type": "string",
        "value": "collection"
      },
      {
        "kind": "account",
        "type": "publicKey",
        "account": "CandyMachine",
        "path": "candy_machine"
      }
    ]
  }
},
...

The above JSON was generated with the following constraints:

seeds = [CollectionPDA::PREFIX.as_ref(), candy_machine.to_account_info().key.as_ref()],

where CollectionPDA prefix is defined as below:

impl CollectionPDA {
    pub const PREFIX: &'static str = "collection";
}

The changes in this PR only impact IDL generation with seeds, and don't touch any other logic.

@vercel
Copy link

vercel bot commented Aug 14, 2022

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

A member of the Team first needs to authorize it.

@armaniferrante armaniferrante merged commit 290b2aa into coral-xyz:master Aug 14, 2022
@stegaBOB stegaBOB deleted the stegaBOB/feat/impl-const-seeds branch August 14, 2022 19:04
yf-castel pushed a commit to castle-finance/anchor that referenced this pull request Aug 15, 2022
yf-castel pushed a commit to castle-finance/anchor that referenced this pull request Aug 15, 2022
Henry-E pushed a commit to Henry-E/anchor that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants