-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract1.sol
92 lines (62 loc) · 2.52 KB
/
contract1.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pragma solidity ^0.4.19;
import "./Ownable.sol";
contract Iddaa is Ownable {
struct Gambler {
address _address; // voter address
uint bet; // ether amount of the voter
uint ratio; // ratio for the total amount of bets
}
mapping(uint => Gambler) public up_gamblers;
mapping(uint => Gambler) public down_gamblers;
uint up_count = 0;
uint down_count = 0;
uint up_ratio_count = 0;
uint down_ratio_count = 0;
//Minimum price to vote for any
uint private minVotePrice = 0.2 ether;
uint private paidForUp = 0;
uint private paidForDown = 0;
constructor() payable public {
}
function voteUp() external payable{
Gambler memory g;
g._address=msg.sender;
g.bet=msg.value;
g.ratio=g.bet/minVotePrice;
paidForUp+=g.bet;
up_gamblers[up_count]=g;
up_count++;
up_ratio_count +=g.ratio;
}
function voteDown() external payable{
Gambler memory g;
g._address=msg.sender;
g.bet=msg.value;
g.ratio=g.bet/minVotePrice;
paidForDown+=g.bet;
down_gamblers[down_count]=g;
down_count++;
down_ratio_count +=g.ratio;
}
function withdrawToOwner() private onlyOwner {
owner.transfer(address(this).balance/4);
}
function giveRewards(string winner) external payable onlyOwner{
withdrawToOwner();
uint totalReward = 3*(paidForDown + paidForUp)/4;
uint i;
uint paymentForUnit;
if(keccak256(winner) == keccak256("up")){
paymentForUnit = totalReward/up_ratio_count;
for( i=0; i<up_count; i++){
up_gamblers[i]._address.transfer(paymentForUnit * up_gamblers[i].ratio);
}
}
else if (keccak256(winner) == keccak256("down")){
paymentForUnit = totalReward/down_ratio_count;
for( i=0; i<down_count; i++){
down_gamblers[i]._address.transfer(paymentForUnit * down_gamblers[i].ratio);
}
}
}
}