Created
May 17, 2021 07:35
-
-
Save SibghatUllah1997/a5f00630bb637517dfc4946a0416ad48 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.26+commit.4563c3fc.js&optimize=true&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^ 0.4.25; | |
contract FundRaising { | |
mapping(address=>uint) public contributions; | |
uint public totalContributors; | |
uint public minimumContribution; | |
uint public deadline; | |
uint public goal; | |
uint public raisedAmount = 0 ; | |
address public admin; | |
struct Request { | |
string description; | |
uint value; | |
address recipient; | |
bool completed; | |
uint numberOfVoters; | |
mapping(address=>bool) voters; | |
} | |
Request[] public requests; | |
constructor(uint _deadline,uint _goal) public{ | |
minimumContribution = 1000000; | |
deadline=block.number + _deadline; | |
goal=_goal; | |
admin = msg.sender; | |
} | |
modifier onlyAdmin { | |
require(msg.sender == admin); | |
_; | |
} | |
function contribute() public payable { | |
require(msg.value > minimumContribution,"the minimum contribution should be 1000000"); | |
require(block.number < deadline); | |
if(contributions[msg.sender] == 0) | |
{ | |
totalContributors++; | |
} | |
contributions[msg.sender] += msg.value; | |
raisedAmount+=msg.value; | |
} | |
function getBalance() public view returns(uint) | |
{ | |
return address(this).balance; | |
} | |
function getRefund() public { | |
require(block.number > deadline); | |
require(raisedAmount < goal); | |
require(contributions[msg.sender] > 0); | |
msg.sender.transfer(contributions[msg.sender]); | |
contributions[msg.sender] = 0; | |
} | |
function createSpendingRequest(string _description, address _recipient, uint _value) public onlyAdmin{ | |
Request memory newRequest = Request( | |
{ | |
description:_description, | |
value:_value, | |
recipient:_recipient, | |
numberOfVoters:0, | |
completed:false | |
} | |
); | |
requests.push(newRequest); | |
} | |
function voteForRequest(uint index) public { | |
Request storage thisRequest = requests[index]; | |
require(contributions[msg.sender] > 0); | |
require(thisRequest.voters[msg.sender] == false); | |
thisRequest.voters[msg.sender] = true; | |
thisRequest.numberOfVoters++; | |
} | |
function makePayment(uint index) public onlyAdmin { | |
Request storage thisRequest = requests[index]; | |
require(thisRequest.completed == false); | |
require(thisRequest.numberOfVoters > totalContributors / 2);//more than 50% voted | |
thisRequest.recipient.transfer(thisRequest.value); | |
thisRequest.completed = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment