Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7906

InvalidSecpSignature Error while Using switchboard-xyz/sb-on-demand in Token Lottery App

$
0
0

I'm new to blockchain development, particularly in Solana. I'm following the Solana Developer Bootcamp 2024 tutorial on YouTube. I'm stuck on the final project and can't figure out why the revealWinner test function is throwing an error.

Test function

 const revealSignature = await anchor.web3.sendAndConfirmTransaction(   provider.connection,   revealTx,   [wallet.payer],   { skipPreflight: true } );

Error

 Program logged: "AnchorError occurred. Error Code: InvalidSecpSignature.Error Number: 6016. Error Message: InvalidSecpSignature."> Program consumed: 104970 of 400000 compute units> Program returned error: "custom program error: 0x1780"

I've also tried running the code directly from the Bootcamp Repository, but I'm encountering the same issue.

Could anyone help me debug this or point me in the right direction?

lib.rc

pub fn reveal_winner(ctx: Context<RevealWinner>) -> Result<()> {        let clock: Clock = Clock::get()?;        let token_lottery = &mut ctx.accounts.token_lottery;        if ctx.accounts.payer.key() != token_lottery.authority {            return Err(ErrorCode::NotAuthorized.into());        }        if ctx.accounts.randomness_account.key() != token_lottery.randomness_account {            return Err(ErrorCode::IncorrectRandomnessAccount.into());        }        if clock.slot < token_lottery.end_time {            return Err(ErrorCode::LotteryNotCompleted.into());        }        require!(!token_lottery.winner_chosen, ErrorCode::WinnerChosen);        let randomness_data =            RandomnessAccountData::parse(ctx.accounts.randomness_account.data.borrow()).unwrap();        let reveal_random_value = randomness_data.get_value(&clock).map_err(|_| ErrorCode::RandomnessNotResolved)?;        let winner = reveal_random_value[0] as u64 % token_lottery.total_tickets;        msg!("Winner is {}", winner);        token_lottery.winner = winner;        token_lottery.winner_chosen = true;        Ok(())    }...#[derive(Accounts)]pub struct RevealWinner<'info> {    #[account(mut)]    pub payer: Signer<'info>,    #[account(        mut,        seeds = [b"token_lottery".as_ref()],        bump,    )]    pub token_lottery: Account<'info, TokenLottery>,    /// CHECK: The account's data is validated manually within the handler.    pub randomness_account: UncheckedAccount<'info>,}

token_lottery.spec.ts

const queue = new anchor.web3.PublicKey("A43DyUGA7s8eXPxqEjJY6EBu1KKbNgfxF8h17VAHn13w");    const queueAccount = new sb.Queue(switchboardProgram, queue);    try {      await queueAccount.loadData();    } catch (err) {      console.log("Queue account not found");      process.exit(1);    }    const [randomness, ix] = await sb.Randomness.create(switchboardProgram, rngKp, queue);    const createRandomnessTx = await sb.asV0Tx({      connection: connection,      ixs: [ix],      payer: wallet.publicKey,      signers: [wallet.payer, rngKp],      computeUnitPrice: 75_000,      computeUnitLimitMultiple: 1.3,    });    const blockhashContext = await connection.getLatestBlockhashAndContext();    const createRandomnessSignature = await connection.sendTransaction(createRandomnessTx);    await connection.confirmTransaction({      signature: createRandomnessSignature,      blockhash: blockhashContext.value.blockhash,      lastValidBlockHeight: blockhashContext.value.lastValidBlockHeight    });    console.log("Transaction Signature for randomness account creation: ",      createRandomnessSignature    );    let confirmed = false;    while (!confirmed) {      try {        const confirmedRandomness = await provider.connection.getSignatureStatuses([createRandomnessSignature]);        const randomnessStatuts = confirmedRandomness.value[0];        if (randomnessStatuts?.confirmations != null && randomnessStatuts?.confirmationStatus === "confirmed") {          confirmed = true        }      } catch (err) {        console.log("Error while confirming transaction", err);      }    }    const sbCommitIx = await randomness.commitIx(queue);    const commitix = await program.methods.commitRandomness().accounts({      randomnessAccount: randomness.pubkey,    }).instruction();    const commitComputIx = anchor.web3.ComputeBudgetProgram.setComputeUnitLimit({      units: 100000,    });    const commitPriorityIx = anchor.web3.ComputeBudgetProgram.setComputeUnitPrice({      microLamports: 1,    });    const commitBlockhashWithContext = await provider.connection.getLatestBlockhash();    const commitTx = new anchor.web3.Transaction({      feePayer: provider.wallet.publicKey,      blockhash: commitBlockhashWithContext.blockhash,      lastValidBlockHeight: commitBlockhashWithContext.lastValidBlockHeight,    })      .add(commitComputIx)      .add(commitPriorityIx)      .add(sbCommitIx)      .add(commitix);    const commitSignature = await anchor.web3.sendAndConfirmTransaction(connection, commitTx, [wallet.payer], { skipPreflight: true });    const sbRevealIx = await randomness.revealIx();    const revealWinnerIx = await program.methods.revealWinner().accounts({      randomnessAccount: randomness.pubkey,    }).instruction();    const revealBlockWithContex = await provider.connection.getLatestBlockhash();    const revealTx = new anchor.web3.Transaction({      feePayer: provider.wallet.publicKey,      blockhash: revealBlockWithContex.blockhash,      lastValidBlockHeight: revealBlockWithContex.lastValidBlockHeight,    }).add(sbRevealIx).add(revealWinnerIx);    let currentSlot = 0;    while (currentSlot < endSlot) {      const slot = await provider.connection.getSlot();      if (slot > currentSlot) {        currentSlot = slot;        console.log("Current slot", currentSlot);      }    }    const revealSignature = await anchor.web3.sendAndConfirmTransaction(      provider.connection,      revealTx,      [wallet.payer],      { skipPreflight: true }    );    console.log("Transaction Signature revealTx", revealSignature);  }, 300000);

Viewing all articles
Browse latest Browse all 7906

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>