Skip to content

Instantly share code, notes, and snippets.

@iamjaspreetsingh
Last active October 21, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamjaspreetsingh/909798ae08f921f1cfad0d6175585f98 to your computer and use it in GitHub Desktop.
Save iamjaspreetsingh/909798ae08f921f1cfad0d6175585f98 to your computer and use it in GitHub Desktop.
made benificiaries of fixed size
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