-
-
Save tomw1808/ef21d73b4eaf06618a3ccd67ea6152a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.25 <0.6.0; | |
contract OptionsContract { | |
address payable owner; | |
address payable player; | |
uint public endTime; | |
bool public started; | |
bool public isAgainstBet; | |
address payable public winner; | |
constructor() public payable { | |
owner = msg.sender; | |
} | |
function betOver10Degree() public payable { | |
require(!started); | |
started = true; | |
player = msg.sender; | |
endTime = now + 10 seconds; | |
isAgainstBet = true; | |
} | |
function betUnder10Degree() public payable { | |
require(!started); | |
started = true; | |
player = msg.sender; | |
endTime = now + 10 seconds; | |
isAgainstBet = false; | |
} | |
function determineWinner(uint _temp) public { | |
require(now >= endTime); | |
//here we need to find a way to retrieve the weather at endTime. How can we? We can't escape the sandbox... | |
require(msg.sender == 0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB); | |
if(_temp > 10) { | |
if(isAgainstBet) { | |
winner = player; | |
} else { | |
winner = owner; | |
} | |
} else { | |
if(isAgainstBet) { | |
winner = owner; | |
} else { | |
winner = player; | |
} | |
} | |
} | |
function withdraw() public { | |
require(winner != address(0x0)); | |
winner.transfer(address(this).balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment