为什么错误:签名验证失败



我正在使用Anchor框架编写一个Solana程序。

我似乎无法摆脱测试时出现的签名错误。

指令账户验证:

#[derive(Accounts)]
pub struct InitializeAuction2<'info> {
/// State of our auction program (up to you)
#[account(
init,
payer = signer,
space = 8 + BoyncAuction::AUCTION_SIZE, 
)]
pub state: Account<'info, BoyncAuction>,
#[account(mut)]
pub signer: Signer<'info>,
system_program: Program<'info, System>,
rent: Sysvar<'info, Rent>,
}

指令处理程序:}

pub fn initialize2(ctx: Context<InitializeAuction2>, app_idx: i64, amount: u64) -> Result<()> {
msg!("[BoyncProgram] Initializing new Boync Auction State");
let auction_state = &mut ctx.accounts.state;
auction_state.end_auction_at = app_idx; // App index is UnixTimestamp
auction_state.authority = ctx.accounts.signer.key().clone();
auction_state.state = AuctionState::create();
Ok(())
}

测试:

const mint = /* previously created mint account */
const user1 = new anchor.web3.Keypair();
const uid = new anchor.BN(parseInt((Date.now() / 1000).toString()));
const uidBuffer = uid.toBuffer("le", 8);

let [auctionStatePubKey, auctionStateBump] =
await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("auction"),
user1.toBuffer(),
mint.toBuffer(),
uidBuffer,
],
program.programId
);
const tx1 = await program.methods
.initialize2(uid, amount)
.accounts({
state: auctionStatePubKey,
signer: user1.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
})
.signers([user1])
.rpc();
...

我希望我没有错过任何东西。如果上下文不够,请告诉我。无论如何,我不能提交这个程序调用事务。它失败了:

Error: Signature verification failed
at Transaction.serialize (node_modules/@project-serum/anchor/node_modules/@solana/web3.js/src/transaction.ts:586:13)
at Provider.send (node_modules/@project-serum/anchor/src/provider.ts:116:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:25:23)

我试着制作signer: provider.wallet.publickey,没有成功。

我们非常感谢任何帮助以及为什么会发生这种情况。

这只是一个未知数,但由于您没有将state指定为PDA,Anchor可能也希望该帐户提供签名。尝试将您的指令定义更改为:

#[derive(Accounts)]
pub struct InitializeAuction2<'info> {
/// State of our auction program (up to you)
#[account(
init,
payer = signer,
space = 8 + BoyncAuction::AUCTION_SIZE,
seeds = [b"auction", signer.key().as_ref(), mint.key().as_ref(), 8u64.to_le_bytes()], bump
)]
pub state: Account<'info, BoyncAuction>,
#[account(mut)]
pub signer: Signer<'info>,
system_program: Program<'info, System>,
rent: Sysvar<'info, Rent>,
}

您可能还需要传递薄荷和凹凸种子数据。

相关内容

  • 没有找到相关文章

最新更新