在将我的结构移动到pub mod xyz {.}之后,我的锈蚀代码:
#[state]
#[derive(Default)]
#[derive(Copy)]//index as pid
pub struct Ppool {
pub alloc_point: u64,
}
#[state]
pub struct Counter {
pub authority: Pubkey,
pub count: u64,
pub pool_array: [Ppool; 20],
}
impl Counter {
pub fn new(ctx: Context<Auth>) -> Result<Self> {
Ok(Self {
authority: *ctx.accounts.authority.key,
count: 0,
pool_array: [
Ppool {
alloc_point: 0,
}; 20],
})
}我的Rust程序可以编译,但是Anchor没有错误地运行:
await program.state.rpc.new({
accounts: {
authority: provider.wallet.publicKey,
},
});TypeError:无法读取未定义的属性rpc
我从本教程Basic1:https://project-serum.github.io/anchor/tutorials/tutorial-1.html#defining-a-program中了解到,“如果您希望将自己的类型作为指令处理程序的输入传递,那么必须在与#程序模块相同的src/lib.rs文件中定义它,这样IDL解析器就可以获取它。”
此外,如果我将Ppool结构移出mod之外,Rust将编译,但是Anchor会说"Error:用户定义的类型未提供“.所以我认为Ppool结构应该留在国防部内部
但是在将我的Ppool结构移动到mod之后,我的Ppool结构就不能有#状态.见以下错误:
error[E0277]: the trait bound Ppool: Clone is not satisfied
--> programs/basic-4/src/lib.rs:11:14
|
11 | #[derive(Copy)]//index as pid
| ^^^^ the trait Clone is not implemented for Ppool
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound Ppool: anchor_lang::AnchorDeserialize is not satisfied
--> programs/basic-4/src/lib.rs:16:5
|
16 | #[state]
| ^^^^^^^^ the trait anchor_lang::AnchorDeserialize is not implemented for Ppool
|
= note: required because of the requirements on the impl of anchor_lang::AnchorDeserialize for [Ppool; 20]
= help: see issue #48214
= help: add #![feature(trivial_bounds)] to the crate attributes to enable
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound Ppool: anchor_lang::AnchorSerialize is not satisfied
--> programs/basic-4/src/lib.rs:16:5
|
16 | #[state]
| ^^^^^^^^ the trait anchor_lang::AnchorSerialize is not implemented for Ppool
|
= note: required because of the requirements on the impl of anchor_lang::AnchorSerialize for [Ppool; 20]
= help: see issue #48214
= help: add #![feature(trivial_bounds)] to the crate attributes to enable
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)在mod中,我应该为我的Ppool结构添加什么样的宏?
发布于 2021-09-15 09:38:03
通过将数组放入结构数组来解决.请参阅Anchor repo >test>零副本
https://stackoverflow.com/questions/68774356
复制相似问题