0

我正在使用 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)

Solana 计划的相关信息是:

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>,
}

任何帮助表示赞赏。谢谢你。

4

1 回答 1

0

poolOwner: owner.key.PublicKey->poolOwner: owner.key.publicKey

您只需要将 publicKey 中的“P”小写。您也不应该需要提供signers参数,因为锚点会自动生成。

于 2022-02-17T15:41:27.787 回答