@@ -11,6 +11,36 @@ contract CrowdFunding
1111 uint public goal;
1212 uint public raisedAmount;
1313
14+ struct Request
15+ {
16+ string description;
17+ address payable recipient;
18+ uint value;
19+ bool completed;
20+ uint noOfVoters;
21+ mapping (address => bool ) voters;
22+ }
23+
24+ mapping (uint => Request) public requests;
25+ uint public numRequestes;
26+
27+ modifier onlyAdmin {
28+ require (msg .sender == admin,"Only admin can call this function " );
29+ _;
30+ }
31+
32+ function createRequest (string memory _description , address payable _recipient , uint _value ) public onlyAdmin
33+ {
34+ Request storage newRequest = requests[numRequestes];
35+ numRequestes++ ;
36+
37+ newRequest.description = _description;
38+ newRequest.recipient = _recipient;
39+ newRequest.value = _value;
40+ newRequest.completed = false ;
41+ newRequest.noOfVoters = 0 ;
42+ }
43+
1444 constructor (uint _goal , uint _deadline )
1545 {
1646 goal = _goal;
@@ -41,4 +71,18 @@ contract CrowdFunding
4171 {
4272 return address (this ).balance;
4373 }
74+
75+ function getrefund () public
76+ {
77+ require (block .timestamp > deadline && raisedAmount < goal);
78+ require (contributors[msg .sender ] > 0 , " You have not donated any cash " );
79+
80+ address payable recipient = payable (msg .sender );
81+ uint value = contributors[msg .sender ];
82+ recipient.transfer (value);
83+
84+ // the above line can be writen like below
85+ //payable(msg.sender).transfer(contributors[msg.sender]);
86+ contributors[msg .sender ] = 0 ;
87+ }
4488}
0 commit comments