Created
January 5, 2018 00:43
-
-
Save jasonyunjoonpark/7e99282bdf0462563d76199075571246 to your computer and use it in GitHub Desktop.
Smart contract between mom and child to pay child when the child confirms that his tooth has fallen out. The mom can confirm the validity through the contract and the contract will pay the child.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract ToothFairy { | |
address owner ; | |
address mom = 0xd2dE66A09F48A96b8cd429951ca70F79715beBCc; | |
address child = 0x80bFb3c5C9386e687936868A79f2e626F38a4AC2; | |
bool paymentStatusToChild = false; | |
enum ToothStatus {Mouth, WaitingForApproval, Fallen} | |
ToothStatus public toothStatus; | |
function ToothFairy() public payable { | |
owner = msg.sender; | |
} | |
function () public payable { | |
} | |
function kill() public onlyOwner { | |
selfdestruct(owner); | |
} | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
modifier onlyChild { | |
require(msg.sender == child); | |
_; | |
} | |
modifier onlyMom { | |
require(msg.sender == mom); | |
_; | |
} | |
function checkTooth() public onlyChild { | |
require(toothStatus == ToothStatus.Mouth); | |
toothStatus = ToothStatus.Fallen; | |
} | |
function momApproved() public onlyMom { | |
require(toothStatus == ToothStatus.Fallen && paymentStatusToChild == false); | |
child.transfer(this.balance); | |
paymentStatusToChild = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment