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 Build Fails with instruction args not found in scope when using args in seeds #3209

Open
ChewingGlass opened this issue Aug 29, 2024 · 1 comment
Labels
idl related to the IDL, either program or client side

Comments

@ChewingGlass
Copy link
Contributor

ChewingGlass commented Aug 29, 2024

Consider the following instruction:

use anchor_lang::{prelude::*, solana_program::hash::hash};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
pub struct InitializeThingWithNameArgs {
  pub name: String
}

#[account]
#[derive(InitSpace)
pub struct NameThing {
  #[max_len(200)]
  pub name: String
}

#[derive(Accounts)]
#[instruction(args: InitializeThingWithNameArgs)]
pub struct InitializeThingWithName<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,
    #[account(
        init,
        payer = payer,
        space = 8 + NameThing::INIT_SPACE,
        seeds = [
            "name".as_bytes(),
            &hash(&args.name.as_bytes()[..]).to_bytes()
        ],
        bump
    )]
    pub name_pda: Box<Account<'info, NameThing>>,
}

Compiling this will fail with:

error[E0425]: cannot find value `args` in this scope
   |
68 |             &hash(&args.name.as_bytes()[..]).to_bytes()
   |                    ^^^^ not found in this scope
Error: Building IDL failed

Seems like you can't use args inside a function inside seeds when building IDL with resolution?

The following does seem to work:

fn hash_name(name: &str) -> [u8; 32] {
    hash(name.as_bytes()).to_bytes()
}

seeds = [
            "name".as_bytes(),
            &hash_name(args.name.as_str())
 ]
@acheroncrypto acheroncrypto added the idl related to the IDL, either program or client side label Aug 29, 2024
@acheroncrypto
Copy link
Collaborator

Yeah, how would we include the resolution info of that seed in the IDL? Similar problem as #2903

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idl related to the IDL, either program or client side
Projects
None yet
Development

No branches or pull requests

3 participants
@ChewingGlass @acheroncrypto and others