Created
July 20, 2022 08:56
-
-
Save Khanisic/5d069575addc0716ce09d4e849027be1 to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.15; | |
contract Kickstarter{ | |
uint public minimumContribution; | |
address public mananger; | |
struct Request{ | |
string title; | |
uint fundsRequired; | |
address receiver; | |
uint approvalCount; | |
bool complete; | |
} | |
mapping ( address => bool ) public contributers; | |
uint public countOfContributers; | |
Request[] public requestsArray; | |
function createRequest ( string memory _title , uint _funds , address _receiver ) public{ | |
requestsArray.push( Request( _title, _funds, _receiver, 0 , false ) ); | |
} | |
modifier onlyOwner(){ | |
require(msg.sender == mananger); | |
_; | |
} | |
constructor(){ | |
mananger = msg.sender; | |
} | |
mapping ( address => mapping( uint => bool )) approvalsOfAllRequests; | |
function setMinimumContriibution ( uint _minContri ) public onlyOwner{ | |
minimumContribution = _minContri; | |
} | |
function contribute() public payable{ | |
require( msg.value > minimumContribution ); | |
if(contributers[msg.sender] == false){ | |
contributers[msg.sender] = true; | |
countOfContributers++; | |
} | |
} | |
function approveRequest( uint idOfRequestToApprove ) public { | |
Request storage requestToApprove = requestsArray[idOfRequestToApprove]; | |
// if the sender is a contributer | |
require( contributers[msg.sender] == true ); | |
// if the sender is an approver of request of this index | |
require( approvalsOfAllRequests[msg.sender][idOfRequestToApprove] == false ); | |
approvalsOfAllRequests[msg.sender][idOfRequestToApprove] = true; | |
requestToApprove.approvalCount++; | |
} | |
function finaliseRequest( uint idOfRequestToApprove) public onlyOwner { | |
Request storage requestToApprove = requestsArray[idOfRequestToApprove]; | |
require ( requestToApprove.approvalCount > ( countOfContributers / 2 ) ); | |
require( requestToApprove.complete == false ); | |
require ( address(this).balance > requestToApprove.fundsRequired ); | |
requestToApprove.complete == true; | |
payable( requestToApprove.receiver ).transfer(requestToApprove.fundsRequired); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment