Last active
February 21, 2019 14:04
-
-
Save ankitbrahmbhatt1997/c518117e2387917015fac696d38c0710 to your computer and use it in GitHub Desktop.
A payable function for contribution
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
function contribute() public payable { | |
//CONDITIONS FOR EXECUTING THE REST OF THE FUNCTION | |
require(msg.value > minimumContribution); | |
require(block.number < deadline); | |
// CHECKING WHETHER THIS IS THE FIRST TIME THAT APERSON IS CONTRIBUTING TO THIS CAMPAIGN | |
if(contributions[msg.sender] == 0) | |
{ | |
// IF ITS HIS FIRST CONTRIBUTION WE NEED TO INCREMENT THE totalContributors STORAGE VARIABLE BY 1 | |
totalContributors++; | |
} | |
// IF ITS NOT HIS/HER FIRST TIME CONTRIBUTING THEN WE SIMPLY ADD THE AMOUNT SENT TO HIS/HER PREVIOUS CONTRIBUTION | |
// AND THEN ALSO ADD THE AMOUNT SENT TO THE raisedAmount STORAGE VARIABLE | |
contributions[msg.sender] += msg.value; | |
raisedAmount+=msg.value; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment