-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfu.sol
More file actions
154 lines (138 loc) · 4.1 KB
/
Copy pathfu.sol
File metadata and controls
154 lines (138 loc) · 4.1 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
pragma solidity ^0.4.18;
contract GoodFortune {
address public owner;
struct Lucky {
uint btc;
uint eth;
uint eos;
uint qtum;
uint hnc;
}
struct Sponsor {
address spo;
string msg;
uint amount;
}
mapping (address => Lucky) public happyNewYear;
Sponsor[] public sponsors;
address[] public awareders;
uint public ticketPrice;
uint public reward;
event PayEvent(address payer, uint amount);
event AwaredEvent(address payer, uint amount);
event SponsorEvent(address payer, uint amount, string massage);
event SentLuckyEvent(address sender, address reciver, uint luckyType);
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function GoodFortune() public {
owner = msg.sender;
ticketPrice = 10**16;
reward = 5*10**17;
}
function clearBalance() onlyOwner public {
msg.sender.transfer(this.balance);
}
function () payable public {
payHelp(msg.sender);
}
function payHelp(address add) payable public {
require(msg.value >= ticketPrice);
require(msg.value % ticketPrice == 0);
require(msg.value / ticketPrice < 6);
var amount = msg.value;
var num = amount / ticketPrice;
for (uint p = 0; p < num; p++) {
getLucky(add, p);
}
PayEvent(add, msg.value);
}
function sponsor(string massage) payable public {
sponsorHelp(msg.sender, massage);
}
function sponsorHelp(address add, string massage) payable public {
Sponsor memory spo = Sponsor({spo:add,amount:msg.value,msg:massage});
sponsors.push(spo);
SponsorEvent(add, msg.value, massage);
}
function getLucky(address add, uint index) private {
uint random = (uint(block.blockhash(block.number-1)) - uint(add)) - index;
Lucky storage lucky = happyNewYear[add];
if (random % 43 == 0) {
lucky.hnc++;
} else {
lucky.btc++;
}
if (random % 17 == 0) {
lucky.qtum++;
} else {
lucky.btc++;
}
if (random % 5 == 0) {
lucky.eos++;
} else {
lucky.btc++;
}
if (random % 3 == 0) {
lucky.eth++;
} else {
lucky.btc++;
}
if (random % 2 == 0) {
lucky.btc++;
} else {
lucky.eth++;
}
}
function sentLucky(address reciver, uint luckyType) public {
require(luckyType >= 0 && luckyType <= 4);
Lucky storage lucky = happyNewYear[msg.sender];
Lucky storage luckyReciver = happyNewYear[reciver];
if (luckyType == 0) {
require(lucky.btc > 0);
lucky.btc--;
luckyReciver.btc++;
} else if (luckyType == 1) {
require(lucky.eth > 0);
lucky.eth--;
luckyReciver.eth++;
} else if (luckyType == 2) {
require(lucky.eos > 0);
lucky.eos--;
luckyReciver.eos++;
} else if (luckyType == 3) {
require(lucky.qtum > 0);
lucky.qtum--;
luckyReciver.qtum++;
} else if (luckyType == 4) {
require(lucky.hnc > 0);
lucky.hnc--;
luckyReciver.hnc++;
} else {
require(false);
}
SentLuckyEvent(msg.sender, reciver, luckyType);
}
function synthesize() public {
synthesizeHelp(msg.sender);
}
function synthesizeHelp(address add) public {
Lucky storage lucky = happyNewYear[add];
require(lucky.btc > 0 && lucky.eth > 0 && lucky.eos > 0 && lucky.qtum > 0 && lucky.hnc > 0);
require(this.balance >= reward);
lucky.btc--;
lucky.eth--;
lucky.eos--;
lucky.qtum--;
lucky.hnc--;
add.transfer(reward);
awareders.push(add);
AwaredEvent(add, reward);
}
function changeOwner(address _newOwner) onlyOwner public {
if (_newOwner != address(0)) {
owner = _newOwner;
}
}
}