约束说明的另一种方式
我知道最常见和建议的方法是单独的“初始化”和“更新”指令,然后将它们包装在客户端的单个交易中。然而, 我想知道是否有任何方法可以实现该程序的逻辑。
这是代码,我获得了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(®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()?)?;
}
锚框架中的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论