-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crowdfunding.sol
77 lines (76 loc) · 2.31 KB
/
Crowdfunding.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pragma solidity ^0.8.14;
contract crowdfund
{
mapping(address=>uint) public contributers;
address public manager;
uint public mincontribution;
uint public deadline;
uint public target;
uint public amount_raised;
uint public noofcontibuters;
uint request_id=0;
struct request
{
string description;
address payable receiptent;
uint amount;
bool issatisfied;
uint noofvoters;
mapping(address=>bool) voters;
}
mapping(uint=>request)requests;
uint public noofreqs;
constructor (uint t,uint d)
{
target=t;
deadline=block.timestamp+d;
mincontribution=100 wei;
manager=msg.sender;
}
function send_ether() public payable
{require(block.timestamp<deadline);
require(msg.value>=100 wei);
if(contributers[msg.sender]==0)
{
noofcontibuters+=1;
}
amount_raised+=msg.value;
contributers[msg.sender]+=msg.value;
}
function refund() public payable
{
require(block.timestamp>deadline && amount_raised<target);
require(contributers[msg.sender]>0);
address payable ad=payable(msg.sender);
ad.transfer(contributers[msg.sender]);
contributers[msg.sender]=0;
}
modifier onlyman(address f)
{
require(f==manager);
_;
}
function make_request(string memory des,address pd,uint a) public onlyman(msg.sender) {
request_id+=1;
requests[request_id].description=des;
requests[request_id].receiptent=payable(pd);
requests[request_id].amount=a;
requests[request_id].issatisfied=false;
requests[request_id].noofvoters=0;
}
function voteRequest(uint req_no) public
{
require(contributers[msg.sender]>0);
require(requests[req_no].voters[msg.sender]==false);
requests[req_no].noofvoters+=1;
requests[req_no].voters[msg.sender]=true;
}
function make_payment(uint reqno) public payable
{
require(amount_raised>target);
require(requests[reqno].issatisfied==false);
require(requests[reqno].noofvoters>(noofcontibuters/2));
requests[reqno].receiptent.transfer(requests[reqno].amount);
requests[reqno].issatisfied=true;
}
}