我正在使用Anchor学习Solana全栈。我在签署交易时遇到了一个问题,将Sol发送到我正在制作的程序所拥有的PDA。我无法为具有正确签名的函数调用rpc。以下是我的代码:
await program.rpc.payPool(pool.data.name, new BN(payment), {
accounts: {
pool: pool.publicKey,
poolOwner: owner.key.PublicKey,
user: adder.key.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [
adder.key,
// I need to put another signature here I think
],
});
我得到的错误是,我认为这与改变事务的问题有关。
Error: Invalid arguments: poolOwner not provided.
at ~/learnsolana/node_modules/@project-serum/anchor/dist/cjs/program/common.js:39:23
at Array.forEach (<anonymous>)
at validateAccounts (node_modules/@project-serum/anchor/dist/cjs/program/common.js:33:16)
at ix (node_modules/@project-serum/anchor/dist/cjs/program/namespace/instruction.js:34:46)
at txFn (node_modules/@project-serum/anchor/dist/cjs/program/namespace/transaction.js:16:20)
at Object.rpc [as payPool] (node_modules/@project-serum/anchor/dist/cjs/program/namespace/rpc.js:28:24)
at payPool (tests/learnsolana.js:70:23)
at Context.<anonymous> (tests/learnsolana.js:117:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
索拉纳项目的相关信息是:
pub fn pay_pool(ctx: Context<PayPool>, _pool_name: String, payment: u64,) ->
ProgramResult {
let user = &ctx.accounts.user;
let pool = &mut ctx.accounts.pool;
if pool.payers.len() >= pool.capacity as usize {
return Err(PoolError::PayersFull.into());
}
pool.payers.push(*user.to_account_info().key);
invoke(
&transfer(
user.to_account_info().key,
pool.to_account_info().key,
payment,
),
&[
user.to_account_info(),
pool.to_account_info(),
ctx.accounts.system_program.to_account_info(),
],
)?;
Ok(())
}
#[derive(Accounts)]
#[instruction(pool_name: String, payment: u64)]
pub struct PayPool<'info>{
#[account(mut, has_one=pool_owner @ PoolError::WrongPoolOwner, seeds=[b"pool", pool_owner.to_account_info().key.as_ref(), name_seed(&pool_name)], bump=pool.bump)]
pub pool: Account<'info, Pool>,
pub pool_owner: AccountInfo<'info>,
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct Pool {
pub pool_owner: Pubkey,
pub bump: u8,
pub capacity: u16,
pub name: String,
pub payers: Vec<Pubkey>,
}
感谢您的帮助。非常感谢。
poolOwner: owner.key.PublicKey
->poolOwner: owner.key.publicKey
你只需要把";P〃;在publicKey中。您也不需要提供signers
参数,因为锚点将自动生成该参数。