Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.2;
- contract Campaign{
- struct Request{
- string description;
- uint value;
- address payable recipient;
- bool complete;
- uint approvalCount;
- mapping(address=>bool) approvals;
- }
- Request[] public requests;
- address public manager;
- uint public minimumContribution;
- mapping(address=>bool) public approvers;//people who do yes or no , these are the people who contribute
- uint public approversCount;// will be incremented when they contribute
- modifier restricted(){
- require(msg.sender==manager);
- _;
- }
- constructor (uint minimum) public{
- manager=msg.sender;
- minimumContribution=minimum;
- }
- function contribute() public payable{
- require(msg.value>minimumContribution);
- approvers[msg.sender]=true;
- approversCount++;
- }
- function createRequest(string memory description,uint value,address payable recipient) public restricted{
- Request memory newRequest= Request({
- description:description,
- value:value,
- recipient:recipient,
- complete:false,
- approvalCount:0
- // approvals:false
- //:false
- });
- requests.push(newRequest);
- }
- function approveRequest(uint index) public {
- Request storage request= requests[index];
- require(approvers[msg.sender]);//he should be a contributer first
- require(!request.approvals[msg.sender]);//check wheather he has not voted before!
- request.approvals[msg.sender]=true;// double check by making if that guy is voting now in side this function set him as he
- //voted inside in this function
- request.approvalCount++;
- }
- function finalizeRequest(uint index) public{
- Request storage request=requests[index];
- require(request.approvalCount>(approversCount/2));
- require(!request.complete);
- request.recipient.transfer(request.value);
- request.complete=true;
- }
- }
Add Comment
Please, Sign In to add comment