-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path35_Auction.sol
More file actions
26 lines (22 loc) · 837 Bytes
/
Copy path35_Auction.sol
File metadata and controls
26 lines (22 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Auction {
address public highestBidder;
uint public highestBid;
mapping(address=>uint) public refunds;
address public owner;
constructor() { owner = msg.sender; }
function bid() external payable {
require(msg.value > highestBid, "low");
if (highestBidder != address(0)) refunds[highestBidder] += highestBid;
highestBidder = msg.sender;
highestBid = msg.value;
}
function withdrawRefund() external {
uint amt = refunds[msg.sender];
require(amt > 0, "no funds");
refunds[msg.sender] = 0;
(bool ok,) = payable(msg.sender).call{value: amt}(""); require(ok);
}
function finalize() external { require(msg.sender == owner); payable(owner).transfer(highestBid); }
}