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

generate_cpi_crate proc macro panicked #83

Open
ClaudeZsb opened this issue Jul 11, 2024 · 3 comments
Open

generate_cpi_crate proc macro panicked #83

ClaudeZsb opened this issue Jul 11, 2024 · 3 comments

Comments

@ClaudeZsb
Copy link

Just a newbie to rust and solana.

I'm finding ways to let my program interact with other programs. While there is interface in solidity and you only need to know the address that you wanna call and apply the appropriate interface to that address, I may need IDL to do the similar thing in solana.

I've read the guide of anchor for cross program invocation. Just really don't like it. It means you have to clone other program's source code into your project. Then I found IDL to work like an interface that could solve the problem of source code. And then I found this tool for generating rust code from the IDL json file. So I'm trying to split the examples in anchor guide puppet and puppet-master into two seperate repos. And I'm trying to use anchor-gen within puppet-master repo in order to invoke puppet. But I ran into this error

puppet within puppet-master repo

anchor_gen::generate_cpi_crate!("idl.json");

declare_id!("9ceHBqVGkYRNJ2uRZG3xvbuU4BQbRKESSs8Q3sWQ74Z9");

image

what i'm using

[dependencies]
anchor-gen = "0.3.1"
anchor-lang = "0.30.1"

puppet idl json

{
  "address": "9ceHBqVGkYRNJ2uRZG3xvbuU4BQbRKESSs8Q3sWQ74Z9",
  "metadata": {
    "name": "hello_anchor",
    "version": "0.1.0",
    "spec": "0.1.0",
    "description": "Created with Anchor"
  },
  "instructions": [
    {
      "name": "initialize",
      "discriminator": [
        175,
        175,
        109,
        31,
        13,
        152,
        155,
        237
      ],
      "accounts": [
        {
          "name": "new_account",
          "writable": true,
          "signer": true
        },
        {
          "name": "signer",
          "writable": true,
          "signer": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "data",
          "type": "u64"
        }
      ]
    },
    {
      "name": "set",
      "discriminator": [
        198,
        51,
        53,
        241,
        116,
        29,
        126,
        194
      ],
      "accounts": [
        {
          "name": "new_account",
          "writable": true
        }
      ],
      "args": [
        {
          "name": "data",
          "type": "u64"
        }
      ]
    },
    {
      "name": "sol_transfer",
      "discriminator": [
        135,
        254,
        247,
        202,
        217,
        48,
        184,
        165
      ],
      "accounts": [
        {
          "name": "from",
          "writable": true,
          "signer": true
        },
        {
          "name": "to",
          "writable": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "lamport",
          "type": "u64"
        }
      ]
    }
  ],
  "accounts": [
    {
      "name": "NewAccount",
      "discriminator": [
        176,
        95,
        4,
        118,
        91,
        177,
        125,
        232
      ]
    }
  ],
  "types": [
    {
      "name": "NewAccount",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "data",
            "type": "u64"
          }
        ]
      }
    }
  ]
}
@CanvasL
Copy link

CanvasL commented Dec 16, 2024

Same error, have you solved?

@hongshu7
Copy link

hongshu7 commented Jan 2, 2025

Same error, no one solved it?

@kotsmile
Copy link

kotsmile commented Jan 5, 2025

@hongshu7 @CanvasL
SUGGESTION: use language models (Claude or ChatGPT) works much better

this lib uses another version of IDL as i understood, you need manually add or replace two fields
"writable" -> "isMut"
"signer" -> "isSigner"
if you dont have "writable" or "signer" fields just add them with false value

also you need to move name and version fields from metadata to root of JSON

But even with this modification lib generates pretty dummy types with unimplemented blocks, i think this lib is useless

use anchor_lang::prelude::*;
pub mod typedefs {
    #![doc = r" User-defined types."]
    use super::*;
}
pub mod state {
    #![doc = r" Structs of accounts which hold state."]
    use super::*;
}
pub mod ix_accounts {
    #![doc = r" Accounts used in instructions."]
    use super::*;
    #[derive(Accounts)]
    pub struct RefundNative<'info> {
        #[account(mut)]
        pub sender: Signer<'info>,
        #[account(mut)]
        pub recipient: AccountInfo<'info>,
        pub system_program: AccountInfo<'info>,
    }
    #[derive(Accounts)]
    pub struct RefundTokens<'info> {
        pub authority: Signer<'info>,
        #[account(mut)]
        pub source_token_account: AccountInfo<'info>,
        #[account(mut)]
        pub destination_token_account: AccountInfo<'info>,
        pub spl_token_program: AccountInfo<'info>,
    }
}
use ix_accounts::*;
pub use state::*;
pub use typedefs::*;
#[program]
pub mod refund_program {
    #![doc = " Anchor CPI crate generated from refund_program v0.1.0 using [anchor-gen](https://crates.io/crates/anchor-gen) v0.3.1."]
    use super::*;
    pub fn refund_native(_ctx: Context<RefundNative>, _left_tokens: u64) -> Result<()> {
        unimplemented!("This program is a wrapper for CPI.")
    }
    pub fn refund_tokens(_ctx: Context<RefundTokens>, _left_tokens: u64) -> Result<()> {
        unimplemented!("This program is a wrapper for CPI.")
    }
}

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

No branches or pull requests

4 participants