I am working with a course on coatings with the Solana Spotify Project and studying on YouTube. Please tell me the code produces such errors, but everything is written correctly and clearly. I don't know where I forgot.
use anchor_lang::prelude::*;
use anchor_lang::solana_program::entrypoint::ProgramResult;
use anchor_spl::token::{self,Token};
use std::mem::size_of;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("11111111111111111111111111111111");
#[program]
mod spotify_clone {
use super::*;
pub fn accept_payment(ctx: Context<PayerContext>, data: u64) -> ProgramResult {
let payer_wallet = &mut ctx.accounts.payer_wallet;
payer_wallet.wallet = ctx.accounts.authority.key();
let ix = anchor_lang::solana_program::system_instruction::transfer(
&ctx.accounts.authority.key(),
&ctx.accounts.receiver.key(),
100000000,
);
anchor_lang::solana_program::program::invoke(
&ix,
&[
ctx.accounts.authority.to_account_info(),
ctx.accounts.receiver.to_account_info(),
],
)
}
}
#[derive(Accounts)]
pub struct PayerContext<'info> {
#[account(
init,
seeds = [b"payer".as_ref(), authority.key().as_ref()],
bump,
payer = authority,
space = size_of::<PayerAccount>() + 8,
)]
pub payer_wallet: Account<'info, PayerAccount>,
//Specific param to object
#[account(mut)]
pub receiver: AccountInfo<'info>,
//Specific param to object
//Authority[this is signer who paid transaction fee]
#[account(mut)]
pub authority: Signer<'info>,
pub system_programm: UncheckedAccount <'info>,
//Token Programm
#[account(constraint = token_program.key == &token::ID)]
pub token_program: Program<'info, Token>,
//Clock to the Save Your Time
pub clock: Sysvar<'info,Clock>,
}
#[account]
pub struct PayerAccount{
pub wallet: Pubkey,
}
Error appears here. The main problem in the code i think is here:
pub payer_wallet: Account<'info, PayerAccount>,
Code of error E0277:
error[E0277]: the trait bound `PayerContext<'_>: anchor_lang::Accounts<'_>` is not satisfied
--> /src/lib.rs:10:1
|
10 | #[program]
| ^^^^^^^^^^ the trait `anchor_lang::Accounts<'_>` is not implemented for `PayerContext<'_>`
|
note: required by `anchor_lang::context::Context::<'a, 'b, 'c, 'info, T>::new`
Second error E0432:
error[E0432]: unresolved import `crate`
--> /src/lib.rs:10:1
|
10 | #[program]
| ^^^^^^^^^^ could not find `__client_accounts_payer_context` in the crate root
|
= note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)
Third error E0599:
error[E0599]: no method named `exit` found for struct `PayerContext` in the current scope
--> /src/lib.rs:10:1
|
10 | #[program]
| ^^^^^^^^^^ method not found in `PayerContext<'_>`
...
34 | pub struct PayerContext<'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)