将Solana PDA互相连接
我正在使用Solana PDA来构建类似哈希图的结构,将用户的钱包地址作为种子之一。 PDA称为mynodes,并包含一些针对用户的数据,包括应计奖励。
现在,我正在尝试建立一个推荐系统。我有一个用户的mynodes pda,我想在第一个PDA中存储另一个用户的PDA的地址。因此,一个用户的PDA将指向另一个用户的PDA,其“推荐人”或“会员”。我需要该连接才能为推荐人和正在转介的奖励正确处理会员奖励。
但是,当试图用锚定构建帐户结构时,我会遇到问题。
#[account]
pub struct MyNodes {
xyz: u32,
abc: u32,
etc: u64,
aff_account: Account<MyNodes>,
}
但这给了我的编译错误:
BPF SDK: /Users/bb/solana/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /Users/bb/app/nodestore/programs/nodeshop/Cargo.toml
workspace: /Users/bb/app/nodestore/Cargo.toml
Compiling nodeshop v0.1.0 (/Users/bb/app/nodestore/programs/nodeshop)
error[E0106]: missing lifetime specifier
--> programs/nodeshop/src/lib.rs:129:26
|
129 | aff_account: Account<MyNodes>,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
123 ~ pub struct MyNodes<'a> {
128 | last_unclaimed: u64,
...
error[E0106]: missing lifetime specifier
--> programs/nodeshop/src/lib.rs:129:26
|
129 | aff_account: Account<MyNodes>,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
122 ~ #[account]<'a>
123 | pub struct MyNodes {
...
For more information about this error, try `rustc --explain E0106`.
error: could not compile `nodeshop` due to 3 previous errors
编译器建议都没有用。将导致新的错误。
如何使用锚将PDA互相链接?
I'm using Solana PDAs to build a hashmap-like structure, using users' wallet addresses as one of the seeds. The PDA is called MyNodes, and contains some data specific to the user, including accrued rewards.
Now I'm trying to build a referral system. I have a user's MyNodes PDA, and I want to store the address of another user's PDA inside that first PDA. So one user's PDA will point to another user's PDA, its "referrer" or "affiliate". I need that connection in order to handle affiliate rewards properly both for the referrer and for the one that is being referred.
However, when trying to build the account struct with anchor, I'm running into problems.
#[account]
pub struct MyNodes {
xyz: u32,
abc: u32,
etc: u64,
aff_account: Account<MyNodes>,
}
But it's giving my compile errors:
BPF SDK: /Users/bb/solana/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package: /Users/bb/app/nodestore/programs/nodeshop/Cargo.toml
workspace: /Users/bb/app/nodestore/Cargo.toml
Compiling nodeshop v0.1.0 (/Users/bb/app/nodestore/programs/nodeshop)
error[E0106]: missing lifetime specifier
--> programs/nodeshop/src/lib.rs:129:26
|
129 | aff_account: Account<MyNodes>,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
123 ~ pub struct MyNodes<'a> {
128 | last_unclaimed: u64,
...
error[E0106]: missing lifetime specifier
--> programs/nodeshop/src/lib.rs:129:26
|
129 | aff_account: Account<MyNodes>,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
122 ~ #[account]<'a>
123 | pub struct MyNodes {
...
For more information about this error, try `rustc --explain E0106`.
error: could not compile `nodeshop` due to 3 previous errors
None of the compiler suggestions work. Will result in new errors.
How can I properly link PDAs to each other using Anchor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以存储其他PDA的Pubkey,
并通过说明中的Pubkey访问数据
you can store Pubkey of other PDA,
and pass the Pubkey in instruction to access data