-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIPL_Auction.sol
97 lines (58 loc) · 2.03 KB
/
IPL_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
pragma solidity >=0.4.9 <0.6.0;
contract IPL_Auction{
string public playerName;
address public player;
uint public bidAmount;
uint public minBid;
address public highestBidder;
uint public auctionEnd_time;
string public bidderName;
bool ended;
mapping (address => uint) returnPrev_bid;
event HighestBidIncreased(address bidder, uint amount);
event AuctionEnded(address winner, uint amount);
constructor(address _player, uint _biddingTime, string memory _playerName,uint _minBid) public{
player =_player;
auctionEnd_time = now + _biddingTime;
playerName = _playerName;
minBid=_minBid;
}
function bid (address _highestBidder,uint _bidAmount,string memory _bidderName) public {
/// highestBidder = _highestBidder;
///bidAmount = _bidAmount;
highestBidder = _highestBidder;
bidAmount = _bidAmount;
bidderName=_bidderName;
require (now <= auctionEnd_time);
require (bidAmount > minBid);
///bid func only works when bid is greater than the previous bid
if (bidAmount != 0){
returnPrev_bid[highestBidder] += bidAmount;
minBid=bidAmount;
///bidAAmount is mappped to the bidder who will get their refund again
}
///highestBidder = msg.sender;
///bidAmount = msg.value;
emit HighestBidIncreased(highestBidder,bidAmount);
}
function withdraw () public returns (bool){
uint amount = returnPrev_bid[highestBidder];
if(amount >0){
returnPrev_bid[highestBidder] = 0;
/// if (!highestBidder.send(amount)){
///if amouunt send not equal to "amount" then this performed
/// returnPrev_bid[highestBidder] = amount;
/// return false;
/// }
}
return true;
}
function auctionEnd() public {
require (now >= auctionEnd_time);
require(!ended); ///ended is not called above and not being false
ended=true;
emit AuctionEnded(highestBidder, bidAmount);
///amount transferred to player
/// player.transfer(bidAmount);
}
}