diff --git a/contracts/DadiAuction.sol b/contracts/DadiAuction.sol new file mode 100644 index 000000000..df07ef2f7 --- /dev/null +++ b/contracts/DadiAuction.sol @@ -0,0 +1,58 @@ +pragma solidity ^0.4.18; + +contract DadiAuction { + address owner; + uint validTime; + + mapping(uint => address) winners; + mapping(uint => uint) timeValidity; + uint numberOfWinners; + uint256 actualBid; + + constructor() public { + owner = msg.sender; + validTime = now; + } + + function bid() public payable { + if (validTime > now) { //if it's not a new auction + if (msg.value > actualBid) //if higher bidder + { + winners[numberOfWinners].send(actualBid); + winners[numberOfWinners] = msg.sender; //set the winner + actualBid = msg.value; //set the new value to be win + } + } + else + { + numberOfWinners ++; //increase index + validTime = now + 15 seconds; //set 15 sec time for auction + timeValidity[numberOfWinners] = validTime; //set it on the list + actualBid = msg.value; //set the current winning value + winners[numberOfWinners] = msg.sender; //set sender to winner + } + } + + function controller() public view returns (address) { + if (timeValidity[numberOfWinners] < now){ //if the latest auction is not ongoing, return latest value + return winners[numberOfWinners]; + } + else + { + if (numberOfWinners > 1) + { + return winners[numberOfWinners - 1]; //return previous winner + } + } + } + + function total() public view returns(uint256){ + require (msg.sender == owner); + return(address(this).balance); + } + + function withdraw() public { + require (msg.sender == owner); + msg.sender.transfer(address(this).balance); + } +} \ No newline at end of file diff --git a/dadi b/dadi new file mode 160000 index 000000000..b1d62dcc3 --- /dev/null +++ b/dadi @@ -0,0 +1 @@ +Subproject commit b1d62dcc323b1e2c2b7cae9eef61fa1c6293fc6f