Skip to content

Instantly share code, notes, and snippets.

@brianyang
Created April 12, 2018 01:54
Show Gist options
  • Save brianyang/d41c12a918323ee27beeaf402f9d656f to your computer and use it in GitHub Desktop.
Save brianyang/d41c12a918323ee27beeaf402f9d656f to your computer and use it in GitHub Desktop.
smart contract
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