failed: custom program error: 0x7d0'
pub fn bid(ctx: Context<Bid>, price: u64) -> Result<()> {
let auction = &ctx.accounts.auction;
let bidder = &mut ctx.accounts.bidder;
//
// Check bidder's balance against auction's price.
//
if price < auction.price {
return Err(error!(MarketError::InsufficientMoney));
}
if (Clock::get()?.unix_timestamp as u128) > auction.end_time {
return Err(error!(MarketError::AuctionEnded));
}
//if refund_receiver exist return the money
if auction.refund_receiver != Pubkey::default() {
**ctx.accounts.auction.to_account_info().try_borrow_mut_lamports()? -= auction.price;
**ctx.accounts.refund_receiver.try_borrow_mut_lamports()? += auction.price;
}
// Transfer bid price to auction account
anchor_lang::solana_program::program::invoke(
&anchor_lang::solana_program::system_instruction::transfer(
&bidder.to_account_info().key(),
&auction.to_account_info().key(),
price
),
&[
bidder.to_account_info(),
auction.to_account_info(),
ctx.accounts.system_program.to_account_info()
]
)?;
//update the auction info
let auction = &mut ctx.accounts.auction;
auction.refund_receiver = ctx.accounts.bidder.key();
auction.price = price;
Ok(())
}
this is my function..
#[derive(Accounts)]
pub struct Bid<'info> {
#[account(
mut,
seeds = [
b"auction",
mint_key.key.as_ref(),
],
bump,
has_one = creator
)]
pub auction: Account<'info, Auction>,
/// CHECK: This account's address is only used.
pub mint_key: AccountInfo<'info>,
/// CHECK: This account's address is only used.
pub creator: AccountInfo<'info>,
#[account(mut)]
pub bidder: Signer<'info>,
/// CHECK: This account's address is only used.
#[account(mut)]
pub refund_receiver: AccountInfo<'info>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
pub associated_token_program: Program<'info, AssociatedToken>,
}
this is the context i am providing.
await program.methods.bid(
new BN(price)
).accounts({
auction: auctionAccount,
mintKey: mintKey,
creator: ownerKey,
bidder: bidder.key.publicKey,
refundReceiver: auction.refundReceiver,
}).rpc();
and this is how i am calling the program.. I am unable to figure out where the code is going wrong..!!!?? if there is a better way to do it plss suggest...
let auction = &ctx.accounts.auction;
->let auction = &mut ctx.accounts.auction;