Created
December 17, 2017 13:58
-
-
Save kidwai/b74173f22c1b1df73e9b053b214e4fac to your computer and use it in GitHub Desktop.
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.18; | |
contract CharityChallenge { | |
address public charity; | |
// Milestones correspond to notable levels of funds raised, | |
// in terms the number of meals afforded for the 96 homeless | |
// youths (at ~ $3/meal and $700/eth) | |
// We will need the exchange rate to connect to meal prices. | |
uint public eth_usd; | |
uint[5] public milestones = [ | |
2100, // 1 week | |
8400, // 1 month | |
25200, // 3 months | |
50400, // 6 months | |
100800 // 1 year | |
]; | |
uint public end_block; | |
function CharityChallenge( | |
address _charity, | |
uint _eth_usd, | |
uint _duration | |
) public { | |
charity = _charity; | |
eth_usd = _eth_usd; | |
end_block = block.number + _duration; | |
} | |
struct Donor { | |
address addr; | |
string message; | |
uint8[3] rgb; | |
} | |
Donor[100] public leaderboard; | |
mapping (address => uint) public donations; | |
function claim (uint i, string message, uint8[3] rgb) public { | |
require (i < leaderboard.length); | |
if (donations[leaderboard[i].addr] < donations[msg.sender]) { | |
leaderboard[i] = Donor({ | |
addr: msg.sender, | |
message: message, | |
rgb: rgb | |
}); | |
Stamp(msg.sender, i); | |
} | |
} | |
function () payable public { | |
require (block.number < end_block); | |
charity.transfer(msg.value); | |
donations[msg.sender] += msg.value; | |
Donation(msg.sender, msg.value); | |
} | |
event Donation (address indexed from, uint amount); | |
event Stamp (address indexed from, uint index); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment