1
1
pragma solidity ^ 0.4.2 ;
2
2
3
- contract CurseCoin {
4
-
3
+ // SafeMath helps prevent integer overflows
4
+ import "openzeppelin-solidity/contracts/math/SafeMath.sol " ;
5
+ // Ownable helps streamline contract inheritance
6
+ import "openzeppelin-solidity/contracts/ownership/Ownable.sol " ;
7
+
8
+ // Initiates this address as the owner
9
+ contract CurseCoin is Ownable {
10
+ // adds SafeMath methods to uint256 types
11
+ using SafeMath for uint256 ;
12
+
13
+ string public name;
14
+ string public symbol;
15
+ uint256 public curseCost;
16
+
17
+ // Events are small empty functions that can be called as a signal or log.
18
+ event Curse (address _curser , address _accursed );
19
+ event Nullify (address _blessed );
20
+
21
+ mapping (address => bool ) public unfortunates;
22
+
23
+ constructor () public {
24
+ name = "CurseCoin " ;
25
+ symbol = "CC " ;
26
+ curseCost = 1 ether ;
27
+ }
28
+
29
+ // curse allows msg.sender to curse a victim if they pay the curseCost
30
+ function curse (address _victim ) public payable {
31
+ // checks that curser is sending correct amount for cursing
32
+ require ((msg .value > curseCost), "You gotta pay the troll toll " );
33
+
34
+ // first check if curse's address
35
+ require ((unfortunates[_victim] == false ), "Victim is already cursed " );
36
+
37
+ unfortunates[_victim] = true ;
38
+ emit Curse (msg .sender , _victim);
39
+ }
40
+
41
+ // nullify allows msg.sender to uncurse themself (if applicable) if they pay the curseCost
42
+ function nullify () public payable {
43
+ // checks that curser is sending correct amount for uncursing
44
+ require ((msg .value > curseCost), "You gotta pay the uncursing troll toll " );
45
+
46
+ // first check if curse's address
47
+ require ((unfortunates[msg .sender ] == true ), "You're not even cursed 🤔 " );
48
+
49
+ unfortunates[msg .sender ] = true ;
50
+ emit Nullify (msg .sender );
51
+ }
52
+
53
+ // withdraw allows the brilliant contract writers to cash out
54
+ function withdraw () public onlyOwner {
55
+ msg .sender .transfer (address (this ).balance);
56
+ }
57
+
58
+ // amICursed allows msg.sender to check if they're cursed
59
+ function amICursed () public view returns (bool ) {
60
+ return unfortunates[msg .sender ];
61
+ }
5
62
}
0 commit comments