Commit 677c3a47 authored by Zvezdin .'s avatar Zvezdin .

Merge branch 'master' into chain

parents 35392df5 245e9209
......@@ -3,6 +3,8 @@ pragma solidity 0.4.24;
//pragma experimental ABIEncoderV2;
contract Better {
event BetWon(address indexed user, uint indexed eventID, uint betIndex, uint winnings);
struct Bet {
uint amount;
uint eventID;
......@@ -34,6 +36,8 @@ contract Better {
mapping(uint => Event) events;
mapping(address => uint) withdrawals;
address owner;
modifier onlyOwner() {
......@@ -78,7 +82,7 @@ contract Better {
number = bet.number;
}
function getEventBetById(uint eventID, uint betID) public view returns (uint amount, uint betType, uint[2] values, uint odd, address user, uint number) {
function getEventBetByID(uint eventID, uint betID) public view returns (uint amount, uint betType, uint[2] values, uint odd, address user, uint number) {
Event storage ev = events[eventID];
Bet storage bet = ev.availableBets[ev.idToIndex[betID]];
......@@ -141,6 +145,7 @@ contract Better {
bet.number = number;
}
//only if event is active
function placeBet(uint eventID, uint betID) public payable {
require(msg.value > 0);
Event storage ev = events[eventID];
......@@ -152,6 +157,29 @@ contract Better {
ev.placedBets.push(b);
}
function announceResult(uint eventID, uint betType, uint[2] values) public onlyOwner {
Event storage ev = events[eventID];
for(uint i=0; i<ev.placedBets.length; i++) {
Bet storage bet = ev.placedBets[i];
if(bet.betType == betType) {
uint winnings = bet.amount * bet.odd;
winnings /= 100; //because odd is multiplied by 100;
withdrawals[bet.user] += winnings;
BetWon(bet.user, eventID, i, winnings);
}
}
}
function withdraw(uint value) public {
require(value <= withdrawals[msg.sender]);
withdrawals[msg.sender] -= value;
msg.sender.transfer(value);
}
function closeBetType(uint eventID, uint betType) public onlyOwner {
Event storage ev = events[eventID];
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment