首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >锚构建错误版本的锚-spl和锚-lang

锚构建错误版本的锚-spl和锚-lang
EN

Stack Overflow用户
提问于 2022-04-20 10:10:57
回答 5查看 2.4K关注 0票数 0

我正在使用以下锈病存储库:

https://github.com/SmartCodeBlockchainDev/Nelson-NFT-stacking

当我尝试做一个锚构建时,我会得到以下错误:

代码语言:javascript
复制
Failed to obtain package metadata: `cargo metadata` exited with an error:     Updating crates.io index
error: failed to select a version for the requirement `anchor-lang = "^0.20.1"`
candidate versions found which didn't match: 0.24.2
location searched: crates.io index
required by package `nft-staking v0.1.0 (/staking/programs/staking)`

当我将cargo.toml文件更新到这些版本(锚-朗和锚-SPL0.24.2)时,会给出lib.rs中的几个错误:

代码语言:javascript
复制
error: bump targets should not be provided with init. Please use bump without a target.
   --> programs/staking/src/lib.rs:582:9
    |
582 |         bump = vault_nonce,
    |         ^^^^

error[E0432]: unresolved import `crate`
  --> programs/staking/src/lib.rs:48:1
   |
48 | #[program]
   | ^^^^^^^^^^ could not find `__client_accounts_create_user` in the crate root
   |
   = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find attribute `error` in this scope
    --> programs/staking/src/lib.rs:1024:3
     |
1024 | #[error]
     |   ^^^^^
     |
note: `error` is imported here, but it is a function-like macro
    --> programs/staking/src/lib.rs:2:5
     |
2    | use anchor_lang::prelude::*;
     |     ^^^^^^^^^^^^^^^^^^^^^^^

error: cannot find attribute `msg` in this scope
    --> programs/staking/src/lib.rs:1026:7
     |
1026 |     #[msg("Insufficient funds to unstake.")]
     |       ^^^
     |
note: `msg` is imported here, but it is a function-like macro
    --> programs/staking/src/lib.rs:2:5
     |
2    | use anchor_lang::prelude::*;
     |     ^^^^^^^^^^^^^^^^^^^^^^^

note: `msg` is imported here, but it is a function-like macro
    --> programs/staking/src/lib.rs:2:5
     |
2    | use anchor_lang::prelude::*;
     |     ^^^^^^^^^^^^^^^^^^^^^^^

error: cannot find attribute `msg` in this scope
    --> programs/staking/src/lib.rs:1030:7
     |
1030 |     #[msg("Reward B cannot be funded - pool is single stake.")]
     |       ^^^
     |

^

代码语言:javascript
复制
note: `msg` is imported here, but it is a function-like macro
    --> programs/staking/src/lib.rs:2:5
     |
2    | use anchor_lang::prelude::*;
     |     ^^^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `program_option::COption`
 --> programs/staking/src/lib.rs:3:42
  |
3 | use anchor_lang::solana_program::{clock, program_option::COption};
  |                                          ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0599]: no function or associated item named `try_accounts` found for struct `InitializePool` in the current scope
   --> programs/staking/src/lib.rs:48:1
    |
48  | #[program]
    | ^^^^^^^^^^ function or associated item not found in `InitializePool<'_>`
...
539 | pub struct InitializePool<'info> {
    | -------------------------------- function or associated item `try_accounts` not found for this
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `try_accounts`, perhaps you need to implement it:
            candidate #1: `anchor_lang::Accounts`
    = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `InitializePool<'_>: anchor_lang::Accounts<'_>` is not satisfied
  --> programs/staking/src/lib.rs:48:1
   |
48 | #[program]
   | ^^^^^^^^^^ the trait `anchor_lang::Accounts<'_>` is not implemented for `InitializePool<'_>`
   |
note: required by `anchor_lang::context::Context::<'a, 'b, 'c, 'info, T>::new`
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/anchor-lang-0.24.2/src/context.rs:51:5
   |
51 | /     pub fn new(
52 | |         program_id: &'a Pubkey,
53 | |         accounts: &'b mut T,
54 | |         remaining_accounts: &'c [AccountInfo<'info>],
55 | |         bumps: BTreeMap<String, u8>,
56 | |     ) -> Self {
   | |_____________^
   = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `exit` found for struct `InitializePool` in the current scope
   --> programs/staking/src/lib.rs:48:1
    |
48  | #[program]
    | ^^^^^^^^^^ method not found in `InitializePool<'_>`
...
539 | pub struct InitializePool<'info> {
    | -------------------------------- method `exit` not found for this
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `exit`, perhaps you need to implement it:
            candidate #1: `anchor_lang::AccountsExit`
    = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `try_accounts` found for struct `CreateUser` in the current scope
   --> programs/staking/src/lib.rs:48:1
    |
48  | #[program]
    | ^^^^^^^^^^ function or associated item not found in `CreateUser<'_>`
...
608 | pub struct CreateUser<'info> {
    | ---------------------------- function or associated item `try_accounts` not found for this
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `try_accounts`, perhaps you need to implement it:
            candidate #1: `anchor_lang::Accounts`
    = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `CreateUser<'_>: anchor_lang::Accounts<'_>` is not satisfied
  --> programs/staking/src/lib.rs:48:1
   |
48 | #[program]
   | ^^^^^^^^^^ the trait `anchor_lang::Accounts<'_>` is not implemented for `CreateUser<'_>`
   |
note: required by `anchor_lang::context::Context::<'a, 'b, 'c, 'info, T>::new`
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/anchor-lang-0.24.2/src/context.rs:51:5
   |
51 | /     pub fn new(
52 | |         program_id: &'a Pubkey,
53 | |         accounts: &'b mut T,
54 | |         remaining_accounts: &'c [AccountInfo<'info>],
55 | |         bumps: BTreeMap<String, u8>,
56 | |     ) -> Self {
   | |_____________^
   = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `exit` found for struct `CreateUser` in the current scope
   --> programs/staking/src/lib.rs:48:1
    |
48  | #[program]
    | ^^^^^^^^^^ method not found in `CreateUser<'_>`
...
608 | pub struct CreateUser<'info> {
    | ---------------------------- method `exit` not found for this
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `exit`, perhaps you need to implement it:
            candidate #1: `anchor_lang::AccountsExit`
    = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no variant or associated item named `NotFoundCandyMachine` found for enum `anchor_lang::error::ErrorCode` in the current scope
   --> programs/staking/src/lib.rs:214:35
    |
214 |             return Err(ErrorCode::NotFoundCandyMachine.into());
    |                                   ^^^^^^^^^^^^^^^^^^^^ variant or associated item not found in `anchor_lang::error::ErrorCode`

error[E0599]: no variant or associated item named `PoolPaused` found for enum `anchor_lang::error::ErrorCode` in the current scope
   --> programs/staking/src/lib.rs:224:35
    |
224 |             return Err(ErrorCode::PoolPaused.into());
    |                                   ^^^^^^^^^^ variant or associated item not found in `anchor_lang::error::ErrorCode`

error[E0599]: no variant or associated item named `CandyNotMatch` found for enum `anchor_lang::error::ErrorCode` in the current scope
   --> programs/staking/src/lib.rs:250:35
    |
250 |             return Err(ErrorCode::CandyNotMatch.into());
    |                                   ^^^^^^^^^^^^^ variant or associated item not found in `anchor_lang::error::ErrorCode`

error[E0599]: no variant or associated item named `CandyNotMatch` found for enum `anchor_lang::error::ErrorCode` in the current scope
   --> programs/staking/src/lib.rs:331:35
    |
331 |             return Err(ErrorCode::CandyNotMatch.into());
    |                                   ^^^^^^^^^^^^^ variant or associated item not found in `anchor_lang::error::ErrorCode`

Some errors have detailed explanations: E0277, E0432, E0599.
EN

回答 5

Stack Overflow用户

发布于 2022-06-04 10:44:49

这是因为所有旧版本的锚都是按下的:https://crates.io/crates/anchor-lang/versions

您可以通过Cargo.toml中的git标记强制执行所需的版本:

代码语言:javascript
复制
anchor-lang = { git = "https://github.com/project-serum/anchor", tag = "v0.20.1" }

但是,如果较早版本的锚有漏洞,则可能存在安全问题。

票数 2
EN

Stack Overflow用户

发布于 2022-04-24 14:25:42

您必须将锚版本降级为0.21.0

如果您在windows机器上,您可以简单地使用npm i -g @project-serum/anchor-cli@^0.21.0

但是,如果您使用的是WSL或Ubuntu,则必须运行sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev

然后使用cargo install --git https://github.com/project-serum/anchor --tag v0.21.0 anchor-cli --locked从源代码构建特定版本。

请记住,必须安装cargo才能运行此命令。

如果问题仍然存在,您的~/.cargo/registry/index目录将被破坏。删除它,然后再次运行cargo update。“

要在WSL中打开它,只需在ubuntu终端中键入explorer.exe .即可。

别忘了.

票数 0
EN

Stack Overflow用户

发布于 2022-05-09 14:36:35

代码语言:javascript
复制
cargo install --git https://github.com/project-serum/anchor --tag v0.24.2 anchor-cli --locked

然后,在projects文件夹的cargo.toml中,使锚-lang=0.24.2而不是0.20.1。

我也有同样的问题,这件事对我来说很有效

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71937822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档