Доброго дня. Бьюсь над задачей. Надо сделать PDA, отправить на него солы чтобы потом любой желающий смог эти солы перевести себе на кошелек.
Задача учебная и упрощенная
Вот код
use anchor_lang::prelude::*;
use anchor_spl::token::{transfer, Token, Transfer};
declare_id!("3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG");
#[program]
pub mod spl_store {
use super::*;
pub fn initial_store(ctx: Context<InitialStore>) -> Result<()> {
let signer = &ctx.accounts.signer;
let store = &mut ctx.accounts.store;
store.authority = signer.key();
Ok(())
}
pub fn withdraw(ctx: Context<Withdraw>, bump: u8) -> Result<()> {
let store = &ctx.accounts.store;
let vault = &ctx.accounts.store_vault;
let destination = &ctx.accounts.destination;
let store_key = &store.key();
let seeds = ["vault".as_bytes(), store_key.as_ref(), &[bump]];
let signer = [&seeds[..]];
msg!("kek");
let cpi_context = CpiContext::new_with_signer(
ctx.accounts.system_program.to_account_info(),
Transfer {
from: vault.to_account_info(),
to: destination.clone(),
authority: vault.to_account_info(),
},
&signer,
);
transfer(cpi_context, 100000)?;
// let ix = anchor_lang::solana_program::system_instruction::transfer(
// &vault.key(),
// destination.key,
// 100000,
// );
// msg!("kek2");
// anchor_lang::solana_program::program::invoke_signed(
// &ix,
// &[vault.to_account_info(), destination.clone()],
// &signer,
// )?;
Ok(())
}
}
#[derive(Accounts)]
pub struct InitialStore<'info> {
#[account(mut)]
pub signer: Signer<'info>,
#[account(init, payer = signer, space = 8 + 32)]
pub store: Account<'info, Store>,
#[account(init, seeds = ["vault".as_bytes(), store.key().as_ref()], bump, payer = signer, space = 8)]
pub store_vault: Account<'info, StoreVault>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Withdraw<'info> {
pub store: Account<'info, Store>,
#[account(mut, seeds = ["vault".as_bytes(), store.key().as_ref()], bump)]
pub store_vault: Account<'info, StoreVault>,
#[account(mut)]
pub destination: AccountInfo<'info>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
}
#[account]
pub struct Store {
pub authority: Pubkey,
}
#[account]
pub struct StoreVault {}
И логи, которые я получал
[
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG invoke [1]',
'Program log: Instruction: Withdraw',
'Program log: kek',
'Unknown program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG consumed 6919 of 200000 compute units',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG failed: An account required by the instruction is missing'
]
[
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG invoke [1]',
'Program log: Instruction: Withdraw',
'Program log: AnchorError caused by account: token_program. Error Code: AccountNotEnoughKeys. Error Number: 3005. Error Message: Not enough account keys given to the instruction.',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG consumed 4963 of 200000 compute units',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG failed: custom program error: 0xbbd'
]
[
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG invoke [1]',
'Program log: Instruction: Withdraw',
'Program log: kek',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
'Program log: Instruction: Transfer',
'Program log: Error: InvalidAccountData',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1172 of 192603 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG consumed 8569 of 200000 compute units',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG failed: invalid account data for instruction'
]
[
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG invoke [1]',
'Program log: Instruction: Withdraw',
'Program log: kek',
'Program log: kek2',
'Program 11111111111111111111111111111111 invoke [2]',
'Transfer: `from` must not carry data',
'Program 11111111111111111111111111111111 failed: invalid program argument',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG consumed 6734 of 200000 compute units',
'Program 3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG failed: invalid program argument'
]
Что я делаю не так?