forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiddingContract.sol
More file actions
62 lines (49 loc) · 1.9 KB
/
BiddingContract.sol
File metadata and controls
62 lines (49 loc) · 1.9 KB
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
pragma solidity ^0.4.0;
contract BiddingContract {
address public originalOwner;
address public newOwner;
uint256 public secondsToEnd;
uint256 public createdTime;
string public description;
uint public basePrice;
address public highestBidder;
uint public highestPrice;
bool public bidDidFinish = false;
event Status(string _msg, address user, uint256 time);
function BiddingContract(string _description, uint _basePrice, uint256 _secondsToEnd) {
originalOwner = msg.sender;
description = _description;
basePrice = _basePrice;
secondsToEnd = _secondsToEnd;
createdTime = block.timestamp;
Status('Bid Created For Item:', msg.sender, block.timestamp);
Status(description, msg.sender, block.timestamp);
}
function bid() payable {
if(block.timestamp > (createdTime + secondsToEnd)) {
checkIfBidEnded();
} else {
if(msg.value > highestPrice && msg.value > basePrice && bidDidFinish == false) {
highestBidder.transfer(highestPrice);
highestBidder = msg.sender;
highestPrice = msg.value;
Status('New Highest Bidder, Old Bidder had his money back', msg.sender, block.timestamp);
} else {
Status('This Bid is not possible. Out of Time or Price not High Enought', msg.sender, block.timestamp);
revert();
}
}
}
function checkIfBidEnded() {
if(block.timestamp > (createdTime + secondsToEnd)) {
originalOwner.transfer(this.balance);
newOwner = highestBidder;
bidDidFinish = true;
Status('Item new Owner:', newOwner, block.timestamp);
Status('Bid Did End!', msg.sender, block.timestamp);
Status('Checking if bid Ended..', msg.sender, block.timestamp);
} else {
revert();
}
}
}