daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.24;
  2.  
  3.  
  4.  
  5. contract CrowdFunding {
  6.  
  7.     //the admins who can withdraw from contract
  8.     address[] public beneficiaries;
  9.     //amount raised in total
  10.     uint public amountRaised;
  11.     //total amt that can be withdrawed by authorities
  12.     uint public withdrawableAmount;
  13.     //who contributed how much in tragedy
  14.     mapping(address => uint256) public balanceOf;
  15.     //city contribution how much in which city
  16.     mapping( string  => uint256)  cityContribution;
  17.     //crowdfunding can be closed by beneficiary anytime
  18.     bool crowdfundClosed = false;
  19.  
  20.  
  21.     event FundTransfer(address backer, uint amount, bool isContribution);
  22.  
  23. // 4 beneficiaaries like rescue lead, commissioner etc.
  24.     constructor(address beneficiary1,address beneficiary2, address beneficiary3, address beneficiary4) public {
  25.         beneficiaries.push(beneficiary1);
  26.         beneficiaries.push(beneficiary2);
  27.         beneficiaries.push(beneficiary3);
  28.         beneficiaries.push(beneficiary4);
  29.     }
  30.  
  31.     modifier can_withdraw() {
  32.         if (msg.sender != beneficiaries[0]||msg.sender != beneficiaries[1]||
  33.         msg.sender != beneficiaries[2]||msg.sender != beneficiaries[3]) {
  34.                 revert();
  35.                 }
  36.            
  37.  
  38.         _; // continue executing rest of method body
  39.     }
  40.  
  41.    
  42.  
  43.  
  44.    // anyone can add donation to tragedy for fund raising
  45.     function addDonation(string city) public payable {
  46.         require(!crowdfundClosed,"Crowdfunding is closed");
  47.         uint amount = msg.value;
  48.         balanceOf[msg.sender] += amount;
  49.         cityContribution[city]+=amount;
  50.         amountRaised += amount;
  51.         withdrawableAmount+=amount;
  52.         emit FundTransfer(msg.sender, amount, true);
  53.  
  54.  
  55.     }
  56.  
  57.     //withdraw funds
  58.     function Withdrawal(uint amt) can_withdraw public {  
  59.         assert(withdrawableAmount<=amountRaised);
  60.         require(withdrawableAmount>amt,"lesser funds are available");
  61.         msg.sender.transfer(amt);
  62.         withdrawableAmount-=amt;
  63.         emit FundTransfer(msg.sender, amt, false);
  64.  
  65.     }
  66.  
  67.     //crowdfunding is stopped
  68.     function stopFunding() public  {
  69.         crowdfundClosed=true;
  70.     }
  71.  
  72.  
  73.    
  74.  
  75.  
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top