function AuctionNft(string memory _name) public payable {
MyNft storage nft = fetchNft[_name];
// bidders storage _bidders = bidderslist[msg.sender]
require(nft.isAuctionable, "This nft is not listed for auction yet");
require(block.timestamp <= timer,"Auction for this NFt has been ended");
require(msg.value >= minBid, "Minimum Bid is not met");
address currentBidder = msg.sender;
bidders storage prevbidder = previousBidder[currentBidder];
prevbidder.Address = msg.sender;
prevbidder.bidAmount = 0;
address payable recipient = payable(nft.owner);
require(msg.value > currentBid, "Bid is lower than the previous bid");
currentBid = msg.value * 1 ether;
if (block.timestamp > timer) {
recipient.transfer(currentBid);
nft.owner = currentBidder;
nft.isOnSale = false;
nft.isAuctionable = false;
}
}
In the above code I'm trying to create a function to Auction the Nft, however, when placing the bids if the current bid is higher than the previous bid what I want is to transfer the bid placed by the previous bidder back to its account.
For that reason, I want to store the address and msg. value of the previous bidder, however, I'm unable to think of any proper logic on how should I do it!!!.
I've created a struct object prevbidder having variable address and amount where I wanna save previous bidder's address and msg.value.
Please help me in understanding how can I store the address and msg.value of the previous bidder.