daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.5.2;
  2.  
  3. contract Campaign{
  4.     struct Request{
  5.         string description;
  6.         uint value;
  7.         address payable recipient;
  8.         bool complete;
  9.         uint approvalCount;
  10.         mapping(address=>bool) approvals;
  11.     }
  12.    
  13.     Request[] public requests;
  14.     address public manager;
  15.     uint public minimumContribution;
  16.     mapping(address=>bool) public approvers;//people who do yes or no , these are the people who contribute
  17.     uint public approversCount;// will be incremented when they contribute
  18.    
  19.     modifier restricted(){
  20.         require(msg.sender==manager);
  21.         _;
  22.     }
  23.    
  24.     constructor (uint minimum) public{
  25.         manager=msg.sender;
  26.         minimumContribution=minimum;
  27.        
  28.     }
  29.    
  30.     function contribute() public payable{
  31.         require(msg.value>minimumContribution);
  32.        
  33.         approvers[msg.sender]=true;
  34.         approversCount++;
  35.     }
  36.    
  37.     function createRequest(string memory description,uint value,address payable recipient) public restricted{
  38.         Request memory newRequest= Request({
  39.             description:description,
  40.             value:value,
  41.             recipient:recipient,
  42.             complete:false,
  43.             approvalCount:0
  44.            // approvals:false
  45.             //:false
  46.         });
  47.        
  48.         requests.push(newRequest);
  49.     }
  50.    
  51.     function approveRequest(uint index) public {
  52.         Request storage request= requests[index];
  53.        
  54.         require(approvers[msg.sender]);//he should be a contributer first
  55.         require(!request.approvals[msg.sender]);//check wheather he has not voted before!
  56.        
  57.         request.approvals[msg.sender]=true;// double check by making if that guy is voting now in side this function set him as he
  58.         //voted inside in this function
  59.        
  60.         request.approvalCount++;
  61.        
  62.     }
  63.    
  64.     function finalizeRequest(uint index) public{
  65.         Request storage request=requests[index];
  66.        
  67.         require(request.approvalCount>(approversCount/2));
  68.        
  69.        
  70.         require(!request.complete);
  71.         request.recipient.transfer(request.value);
  72.         request.complete=true;
  73.        
  74.     }
  75.    
  76.    
  77. }
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