Skip to content

Instantly share code, notes, and snippets.

@tomw1808
Created November 30, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomw1808/ef21d73b4eaf06618a3ccd67ea6152a4 to your computer and use it in GitHub Desktop.
Save tomw1808/ef21d73b4eaf06618a3ccd67ea6152a4 to your computer and use it in GitHub Desktop.
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