锚构建错误版本的锚点和锚点lang

发布于 2025-01-22 14:16:00 字数 9260 浏览 2 评论 0原文

我正在使用以下rust的存储库:

https://githbithub.com/smartcodeblockchaindev/nelson-nelson--nelson--nelson--nelson--nelson--nelson--nelson-- NFT堆叠

当我尝试进行锚定构建时,我会收到以下错误:

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文件更新为这些版本时(adnawor-lang and锚式SPL 0.24.2),它给了我几个错误在lib.rs:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^》

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.")]
     |       ^^^
     |

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.

I'm using the following repository of rust:

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

when I try to do an anchor build I get the following error:

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)`

And when I update the cargo.toml file to those versions (anchor-lang and anchor-spl 0.24.2) it gives me several errors in lib.rs:

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.")]
     |       ^^^
     |

^^^^^^^^^^^^^^^^^^^^^^^

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.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风轻花落早 2025-01-29 14:16:00

这是因为所有较旧版本的锚都被拉紧:
https://crates.io/crates/crates/anchor-lang/versions

您可以强迫cargo.toml中的git标签所需版本:

anchor-lang = { git = "https://github.com/project-serum/anchor", tag = "v0.20.1" }

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

It's because all older versions of the anchor are yanked:
https://crates.io/crates/anchor-lang/versions

You can force required version by git tag in your Cargo.toml:

anchor-lang = { git = "https://github.com/project-serum/anchor", tag = "v0.20.1" }

But there can be security issues if older versions of the anchor have vulnerabilities.

陌伤浅笑 2025-01-29 14:16:00
cargo install --git https://github.com/project-serum/anchor --tag v0.24.2 anchor-cli --locked

然后在项目文件夹的货物中,使您的锚点= 0.24.2
相反0.20.1

我遇到了同样的问题,这对我有用

cargo install --git https://github.com/project-serum/anchor --tag v0.24.2 anchor-cli --locked

Then in the cargo.toml of the projects folder, make your anchor-lang=0.24.2
instead 0.20.1

I was having the same issue and this worked for me

风轻花落早 2025-01-29 14:16:00

您必须将锚版版本降级到0.21.0

如果您在Windows计算机上,则只需使用npm I -G @project-serum/anchor-cli @^0.21.0

,但是如果您在WSL或Ubuntu上sudo apt-get升级&amp; amp; amp; sudo apt-get install -y pkg-config build-espential libudev-dev

然后使用cargo install-git https://github.com/project.com/project-serum/anchor--标签v0.21.0锚cli-locked

必须安装货物以运行此命令

请记住,如果问题持续下去,则 ,您的〜/.cargo/.cargo/.cargo/index < /代码>目录已损坏。删除并运行货物更新。“

对于WSL打开它,只需在Ubuntu终端中键入explorer.exe。

请不要忘记。代码>

You have to downgrade the anchor version to 0.21.0

If you are on a windows machine, you can simply use npm i -g @project-serum/anchor-cli@^0.21.0

But if you are on WSL or Ubuntu you have to run sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev

Then build specific version from source using cargo install --git https://github.com/project-serum/anchor --tag v0.21.0 anchor-cli --locked

Remember you should have to cargo installed to run this command

If the problem persists,your ~/.cargo/registry/index directory is corrupted. Delete it and run cargo update again."

For opening it in WSL, just type explorer.exe . in the ubuntu terminal

Don't forget the .

心碎无痕… 2025-01-29 14:16:00

不建议您删除您的 .cargo/registry/index ,如果您不小心降级或升级: 货物安装,它可能会破坏您的货物=“ https://github.com/project-serum/anchor” rel =“ nofollow noreferrer”> https://github.com/project-serum/anchor/anchor -tag v0.21.0.21.0 Anchor-Cli- -locked 然后将您要的版本指定。

It is no advisable to delete your .cargo/registry/index it can break your cargo if you are not careful just downgrade or upgrade with: cargo install --git https://github.com/project-serum/anchor --tag v0.21.0 anchor-cli --locked then specify to the version you want.

伏妖词 2025-01-29 14:16:00

对于我的Mac,以下命令对我有用。它还应该在Windows上的Ubuntu和WSL 2上使用。

cargo install --git https://github.com/project-serum/anchor --tag v0.21.0 anchor-cli --locked --force

For my Mac the following command worked for me. It should also work on Ubuntu and wsl 2 on windows.

cargo install --git https://github.com/project-serum/anchor --tag v0.21.0 anchor-cli --locked --force
最近可好 2025-01-29 14:16:00

这对我有用
我卸载了锚CLI,并使用这样的货物重新安装了0.27.0版本;

货物卸载锚-CLI

然后

货物安装锚-CLI - Version 0.27.0

This Worked for me
I uninstall the anchor cli and reinstall the version 0.27.0 using cargo like this;

cargo uninstall anchor-cli

and then

cargo install anchor-cli --version 0.27.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文