-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_RatonPerez.sol
62 lines (54 loc) · 1.37 KB
/
12_RatonPerez.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
pragma solidity ^0.6.2;
contract RatonPerez {
address mother = 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C; // Replace by mother adress
address payable child = 0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB; // Replace by child adress
address toothFairy;
bool toothPaid = false;
enum ToothState {Mouth, WaitingFallenAproval, Fallen}
ToothState public toothState = ToothState.Mouth;
constructor() payable public {
toothFairy = msg.sender;
}
modifier onlyChild {
if (msg.sender != child) {
revert();
} else {
_;
}
}
modifier onlyFairy {
if (msg.sender != toothFairy) {
revert();
} else {
_;
}
}
modifier onlyMother {
if (msg.sender != mother) {
revert();
} else {
_;
}
}
function toothFall() onlyChild public {
if(toothState == ToothState.Mouth) {
toothState = ToothState.WaitingFallenAproval;
} else {
revert();
}
}
function motherApproves() onlyMother public {
if(toothState == ToothState.WaitingFallenAproval) {
toothState = ToothState.Fallen;
payToChild();
} else {
revert();
}
}
function payToChild() payable public{
if(toothState == ToothState.Fallen && toothPaid == false) {
child.transfer(address(this).balance);
toothPaid = true;
}
}
}