Skip to content

Instantly share code, notes, and snippets.

@joeb000
Created January 17, 2018 19:14
Show Gist options
  • Save joeb000/1bb7275b280fc985279616f5abee85d3 to your computer and use it in GitHub Desktop.
Save joeb000/1bb7275b280fc985279616f5abee85d3 to your computer and use it in GitHub Desktop.
Friends Smart contract
contract Friends {
address public owner;
mapping (address => Friend) public friends;
uint defaultPayout = .1 ether;
struct Friend {
bool isFriend;
bool hasWithdrawn;
}
modifier onlyOwner {
require(msg.sender==owner);
_;
}
function Friends() {
owner = msg.sender;
}
function deposit() payable {
}
function addFriend(address _f) onlyOwner {
friends[_f].isFriend = true;
}
function withdraw() {
require (friends[msg.sender].isFriend && !friends[msg.sender].hasWithdrawn);
friends[msg.sender].hasWithdrawn = true;
msg.sender.send(defaultPayout);
}
function ownerWithdrawAll() onlyOwner {
owner.send(this.balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment