约束说明的另一种方式

发布于 2025-02-09 02:30:14 字数 1149 浏览 2 评论 0原文

我知道最常见和建议的方法是单独的“初始化”和“更新”指令,然后将它们包装在客户端的单个交易中。然而, 我想知道是否有任何方法可以实现该程序的逻辑。

这是代码,我获得了2个功能,具有完全相同数量的必需帐户和函数参数,唯一的区别是它们的逻辑来初始化和更新状态。我以为我会收到运行的时间错误,但是我会得到绝对的失败。

谁能给我解释获得BorshioError和任何其他解决方案?

指令(1):进程onirectize_deposit

fn process(...)->ProgramResult{  

 {
   Logic...
 }

 //calling update_deposit ix 
 crate::processor::update_deposit::process(program_id, accounts, update_idx, amount)?;

 Ok(())
}

指令(2):

fn process(program_id, accounts, update_idx, amount)->ProgramResult{

    ...

    let registrar: Registrar = Registrar::try_from_slice(&registrar_info.try_borrow_data()?)?;

    // this failed to serialize the data 
    let mut depositor: Depositor = Voter::try_from_slice(&depositor_info.try_borrow_mut_data()?)?;
}

锚框架中的process update_deposit初始想法源代码

I know the most common and recommended way is separate "initialize" and "update" instructions and pack them inside the single transaction in the client-side. However,
I am wondering is there any way to achieve the kind of logic on the program.

Here's the code, I got the 2 function with exactly same amount of required accounts and function argument, only difference is their logic for initializing and updating the state. I thought I will receive a run time error, but I got deserialization failure instead.

Can anyone gives me an explanation for getting BorshIoError and any further solutions ?

instruction (1): process initialize_deposit

fn process(...)->ProgramResult{  

 {
   Logic...
 }

 //calling update_deposit ix 
 crate::processor::update_deposit::process(program_id, accounts, update_idx, amount)?;

 Ok(())
}

instruction (2): process update_deposit

fn process(program_id, accounts, update_idx, amount)->ProgramResult{

    ...

    let registrar: Registrar = Registrar::try_from_slice(®istrar_info.try_borrow_data()?)?;

    // this failed to serialize the data 
    let mut depositor: Depositor = Voter::try_from_slice(&depositor_info.try_borrow_mut_data()?)?;
}

Initial idea in Anchor framework source code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文