Created
April 12, 2018 01:54
-
-
Save brianyang/d41c12a918323ee27beeaf402f9d656f to your computer and use it in GitHub Desktop.
smart contract
This file contains 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.8; | |
contract Charity { | |
address owner; | |
address boardMember1; | |
address boardMember2; | |
address recipient; | |
bool registeredYet; | |
mapping(address => bool) signatures; | |
struct Donation { | |
address donor; | |
uint value; | |
} | |
Donation[] donations; | |
function Charity() { | |
owner = msg.sender; | |
registeredYet = false; | |
} | |
function addBoardMembers(address bm1, address bm2) returns (string) { | |
if (msg.sender == owner && !registeredYet) { | |
boardMember1 = bm1; | |
boardMember2 = bm2; | |
registeredYet = true; | |
} | |
else if (registeredYet) { | |
return 'already registered'; | |
} | |
else return 'not owner'; | |
} | |
function donate() payable returns (string) { | |
donations.push(Donation(msg.sender, msg.value)); | |
} | |
function addSignature() returns (string) { | |
if (msg.sender == owner) { | |
signatures[owner] = true; | |
} | |
else if (msg.sender == boardMember2) { | |
signatures[boardMember2] = true; | |
} | |
else if (msg.sender == boardMember1) { | |
signatures[boardMember1] = true; | |
} | |
} | |
function addRecipient(address recip) returns (string) { | |
if (msg.sender == owner) { | |
recipient = recip; | |
return 'thanks'; | |
} | |
} | |
function withdraw() returns (string) { | |
if (msg.sender == boardMember1 || msg.sender == boardMember2) { | |
uint numSignatures = 0; | |
if (signatures[owner] == true || | |
signatures[boardMember2] == true || | |
signatures[boardMember1] == true) { | |
numSignatures++; | |
} | |
} | |
if (numSignatures >=2) { | |
recipient.send(this.balance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment