I've recently started to play around with solidity and have a question regarding my dapp. Basically, it's the betting site where people can guess the weather forecast (cloudy, sunny, etc) on a specific date. Ex: weather in seattle on March 10th, 2018. Let's say 5 people have bet (0.1 ether each) and one person guessed it right. The winner gets all the money from the rest of 4 people. Now, based on this scenario I assume each person has to send ether to contract address when he/she bets,
function setBettingInfo (string _forecast, string _date) payable returns (bool success) {
// ... codes
address(this).transfer(msg.value); // send betting price to contract address
}
and the winners will be evenly distributed with ether from the contract address on March 11th, 2018 when the dapp calls a forecast api to find out what the weather was like on March 10th. Sending ethers winners, I'm trying to use
function transfer(string _forecast, string _date) returns (bool success) {
// ... code to get the winners
// Distribute ethers to winners
for (uint i = 0; i < winners.length; i++) {
if (contractBalance[address(this)] < value) throw;
contractBalance[address(this)] -= value;
winners.account.transfer(value);
}
return true;
}
Just wondering if this is a correct approach.
- send betting price to contract address
- pull result from forecast api and access contract method to find out winners
- calculate and evenly distribute ethers from contract to those winner accounts
Help is appreciated!