-
Notifications
You must be signed in to change notification settings - Fork 0
/
Farmer's Auction.sol
75 lines (56 loc) · 1.77 KB
/
Farmer's Auction.sol
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma solidity >=0.4.22 <0.6.0;
contract Auction {
address payable public farmer;
uint public auctionEndTime;
address public highestBidder;
uint public highestBid;
uint MSP;
string productname;
// mapping(address => uint) pendingReturns;
bool ended;
event HighestBidIncreased(address bidder, uint amount);
event AuctionEnded(address winner, uint amount);
constructor(
uint _biddingTime,
address payable _beneficiary,
uint _MSP,
string memory _productname
) public {
farmer = _beneficiary;
auctionEndTime = now + _biddingTime;
highestBid=_MSP;
productname=_productname;
}
function bid(uint k) public {
require(
now <= auctionEndTime,
"Auction already ended."
);
require(
k > highestBid,
"There already is a higher bid."
);
highestBidder = msg.sender;
highestBid = k;
emit HighestBidIncreased(msg.sender, highestBid);
}
/// Withdraw a bid that was overbid.
// function withdraw() public returns (bool) {
// uint amount = pendingReturns[msg.sender];
// if (amount > 0) {
// pendingReturns[msg.sender] = 0;
// if (!msg.sender.send(amount)) {
// pendingReturns[msg.sender] = amount;
// return false;
// }
// }
// return true;
// }
function auctionSTATUS() public {
require(now >= auctionEndTime, "Auction not yet ended.");
require(!ended, "Auction has already ended.");
ended = true;
emit AuctionEnded(highestBidder, highestBid);
// beneficiary.transfer(highestBid);
}
}