-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToothFairy.sol
More file actions
67 lines (54 loc) · 1.39 KB
/
ToothFairy.sol
File metadata and controls
67 lines (54 loc) · 1.39 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
pragma solidity ^0.4.0;
contract ToothFairy {
address child = 0x249A17f2587b9103A3780D67c9B1C6AFcCBe004F; // Replace Child Address Here
address mother = 0x18D82F0710e4d70ac8d07a7dEC65f005A4a230AC; // Replace Mother Address Here
address toothFairy;
bool toothPaid = false;
enum ToothState { Mouth, WaitingFallenAproval, Fallen }
ToothState public toothState = ToothState.Mouth;
function ToothFairy() payable {
toothFairy = msg.sender;
}
function toothFall() onlyChild {
if(toothState == ToothState.Mouth) {
toothState = ToothState.WaitingFallenAproval;
} else {
revert();
}
}
function motherApproves() onlyMother {
if(toothState == ToothState.WaitingFallenAproval) {
toothState = ToothState.Fallen;
payToChild();
} else {
revert();
}
}
function payToChild() {
if(toothState == ToothState.Fallen && toothPaid == false) {
child.transfer(this.balance);
toothPaid = true;
}
}
modifier onlyChild {
if (msg.sender != child) {
revert();
} else {
_;
}
}
modifier onlyFairy {
if (msg.sender != toothFairy) {
revert();
} else {
_;
}
}
modifier onlyMother {
if (msg.sender != mother) {
revert();
} else {
_;
}
}
}