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

Non account struct parsed as account in IDL #2441

Closed
RuvendeGroote opened this issue Mar 22, 2023 · 1 comment
Closed

Non account struct parsed as account in IDL #2441

RuvendeGroote opened this issue Mar 22, 2023 · 1 comment
Labels
bug Something isn't working idl related to the IDL, either program or client side

Comments

@RuvendeGroote
Copy link
Contributor

Hi,

It might be a fringe case but if you have a struct with the account annotation and also a struct deriving AnchorSerialize, AnchorDeserialize bearing the same name, both struct definitions will end up as accounts in the IDL

use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod bug {
    use super::*;

    pub fn initialize(_: Context<Initialize>) -> Result<()> {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    pub something: Account<'info, Something>,
}

#[account]
pub struct Something {
    pub first: u64,
}

mod other {
    use anchor_lang::prelude::*;

    #[derive(AnchorDeserialize, AnchorSerialize)]
    pub struct Something {
        pub second: u64,
    }
}

running anchor build (using anchor 0.27.0) will result in following idl:

{
  "version": "0.1.0",
  "name": "bug",
  "instructions": [],
  "accounts": [
    {
      "name": "Something",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "second",
            "type": "u64"
          }
        ]
      }
    },
    {
      "name": "Something",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "first",
            "type": "u64"
          }
        ]
      }
    }
  ]
}
@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
@acheroncrypto acheroncrypto added bug Something isn't working idl related to the IDL, either program or client side labels Mar 10, 2024
@acheroncrypto
Copy link
Collaborator

Fixed in #2824.

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

No branches or pull requests

2 participants