python 使用anchor idl 问题分析
这两天在网上找了一个anchor idl,发给一个搞机器人的,发现他都调用不了。老是出什么
solders.SerdeJSONError: data did not match any variant of untagged enum IdlAccountItem at line
在下面代码地方就出错了
idl = Idl.from_json(content)
激发了我的好奇心,我不是去年搞pumpfun的idl就给anchorpy修复了2个bug给搞定了吗,怎么还有?
所以深入分析了一番这个问题,其实也很简单,主要和anchor几个版本的升级变更有关系,就是版本升级了,关键字的名字改变了。 直接看看代码 https://github.com/kevinheavey/anchorpy-core/blob/main/src/idl.rs
impl IdlAccount {
#[new]
pub fn new(
name: String,
is_mut: bool,
is_signer: bool,
is_optional: Option<bool>,
docs: Option<Vec<String>>,
pda: Option<IdlPda>,
relations: Vec<String>,
) -> Self
再看看能解析的代码是怎么写的 https://github.com/kevinheavey/anchorpy-idl/blob/main/src/idl.rs
impl IdlInstructionAccount {
#[new]
pub fn new(
name: String,
docs: Vec<String>,
writable: bool,
signer: bool,
optional: bool,
address: Option<String>,
pda: Option<IdlPda>,
relations: Vec<String>,
) -> Self
怎么改你懂了吧 ?
当然这可能只是其中一个问题,其他问题可以评论出来。
anchor 0.30.1的解析在anchorpy-idl 里面,anchorpy-idl 文档是这么写的
Python bindings for Anchor Rust IDL code. This is the successor for [`anchorpy-core`](https://github.com/kevinheavey/anchorpy-core). It lives in a separate repo as a separate package because the Anchor v0.30 IDL is not backwards compatible, so separating the packages is cleaner in case we ever need to make changes to older IDL code.
目前anchorpy里面支持的还是比较老的版本[anchorpy-core
]
,我看作者也没有升级的计划,python 搞solana的这个领域,一共两个包都这个哥们写的,要想支持估计得给这个哥们打赏。
给我点赞,看看有几个用户,值得搞搞吗?
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!