Instantly share code, notes, and snippets.

Embed
What would you like to do?
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