5

我有一个使用 Serum Anchor(在 Solana 上)的简单合约,将代币从一方转移到另一方。它目前正在失败:

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account

以下片段的完整代码:https ://gist.github.com/h4rkl/700400f515ab0736fd6d9318d44b2dca

我正在为交易设置 4 个帐户:

  let mint = null; // key for token mint
  let god = null; // main program account to pay from and sign
  let creatorAcc = anchor.web3.Keypair.generate(); // account to pay to
  let creatorTokenAcc = null; // token account for payment

我将它们设置如下:

const [_mint, _god] = await serumCmn.createMintAndVault(
      program.provider,
      new anchor.BN(MINT_TOKENS),
      undefined,
      MINT_DECIMALS
    );
    mint = _mint;
    god = _god;

    creatorTokenAcc =await serumCmn.createTokenAccount(
      program.provider,
      mint,
      creatorAcc.publicKey
    );

然后我用以下方法付款:

const INTERACTION_FEE = 200000000000000;
await program.rpc.interaction(new anchor.BN(INTERACTION_FEE), {
      accounts: {
        from: god,
        to: creatorTokenAcc,
        owner: program.provider.wallet.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
      },
    });

在该方法触发我的交互过程的合同中如下:

pub fn interaction(ctx: Context<Interaction>, interaction_fee: u64) -> ProgramResult {
        let cpi_accounts = Transfer {
            from: ctx.accounts.from.to_account_info().clone(),
            to: ctx.accounts.to.to_account_info().clone(),
            authority: ctx.accounts.owner.clone(),
        };
        let cpi_program = ctx.accounts.token_program.clone();
        let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
        token::transfer(cpi_ctx, interaction_fee)?;
       
        Ok(())
    }

我已经pub struct使用以下参数设置了交互:

#[derive(Accounts)]
pub struct Interaction<'info> {
    #[account(mut, has_one = owner)]
    from: CpiAccount<'info, TokenAccount>,
    #[account("from.mint == to.mint")]
    to: CpiAccount<'info, TokenAccount>,
    #[account(signer)]
    owner: AccountInfo<'info>,
    token_program: AccountInfo<'info>,
}

据我所知,参数是正确的,并且该god帐户拥有钱包作为付款人并且是签名人。为什么会失败,我错过了什么?我完全没有想法。

4

1 回答 1

2

传奇的 Armani Ferrante在这里回答:

您的 to帐户未标记为可变。

于 2021-08-19T02:30:33.777 回答