Last active
October 21, 2018 09:23
-
-
Save iamjaspreetsingh/909798ae08f921f1cfad0d6175585f98 to your computer and use it in GitHub Desktop.
made benificiaries of fixed size
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.24; | |
contract CrowdFunding { | |
//the admins who can withdraw from contract | |
address[4] public beneficiaries; | |
//amount raised in total | |
uint public amountRaised; | |
//total amt that can be withdrawed by authorities | |
uint public withdrawableAmount; | |
//who contributed how much in tragedy | |
mapping(address => uint256) public balanceOf; | |
//city contribution how much in which city | |
mapping( string => uint256) cityContribution; | |
//crowdsale can be closed by beneficiary anytime | |
bool crowdfundClosed = false; | |
event FundTransfer(address backer, uint amount, bool isContribution); | |
// 4 beneficiaries like rescue lead, commissioner etc. | |
constructor(address beneficiary1,address beneficiary2, address beneficiary3) public { | |
beneficiaries[0]=msg.sender; | |
beneficiaries[1]=beneficiary1; | |
beneficiaries[2]=beneficiary2; | |
beneficiaries[3]=beneficiary3; | |
} | |
modifier can_withdraw() { | |
if (msg.sender != beneficiaries[0]||msg.sender != beneficiaries[1]|| | |
msg.sender != beneficiaries[2]||msg.sender != beneficiaries[3]) { | |
revert(); | |
} | |
_; // continue executing rest of method body | |
} | |
modifier isOwner() { | |
if (msg.sender != beneficiaries[0]) { | |
revert(); | |
} | |
_; // continue executing rest of method body | |
} | |
// anyone can add donation to tragedy for fund raising | |
function addDonation(string city) public payable { | |
require(!crowdfundClosed,"Crowdfunding is closed"); | |
uint amount = msg.value; | |
balanceOf[msg.sender] += amount; | |
cityContribution[city]+=amount; | |
amountRaised += amount; | |
withdrawableAmount+=amount; | |
emit FundTransfer(msg.sender, amount, true); | |
} | |
//withdraw funds | |
function Withdrawal(uint amt) can_withdraw public { | |
assert(withdrawableAmount<=amountRaised); | |
require(withdrawableAmount>amt,"lesser funds are available"); | |
msg.sender.transfer(amt); | |
withdrawableAmount-=amt; | |
emit FundTransfer(msg.sender, amt, false); | |
} | |
//crowdfunding is stopped | |
function stopFunding() isOwner public { | |
crowdfundClosed=true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment