Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.24;
- contract CrowdFunding {
- //the admins who can withdraw from contract
- address[] 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;
- //crowdfunding can be closed by beneficiary anytime
- bool crowdfundClosed = false;
- event FundTransfer(address backer, uint amount, bool isContribution);
- // 4 beneficiaaries like rescue lead, commissioner etc.
- constructor(address beneficiary1,address beneficiary2, address beneficiary3, address beneficiary4) public {
- beneficiaries.push(beneficiary1);
- beneficiaries.push(beneficiary2);
- beneficiaries.push(beneficiary3);
- beneficiaries.push(beneficiary4);
- }
- 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
- }
- // 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() public {
- crowdfundClosed=true;
- }
- }
Add Comment
Please, Sign In to add comment