-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrowdfundingDAPP.sol
65 lines (53 loc) · 1.71 KB
/
crowdfundingDAPP.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
pragma solidity >=0.7.0 <0.9.0;
contract Crowdfund {
address payable public beneficiaryAddress;
uint public beneficiaryTarget;
uint public endDate;
bool public ended = false;
address donorAddress;
uint donorValue;
bool public returnDonors;
uint public currentTotal;
mapping (address => uint) public donors;
constructor (
address payable _beneficiaryAddress,
uint target,
uint biddingTime
) public {
beneficiaryAddress = _beneficiaryAddress;
beneficiaryTarget = target;
endDate = block.timestamp + biddingTime;
returnDonors = false;
}
function donate () public payable {
require(block.timestamp <= endDate,
"Sorry, this fundraising session has ended.");
currentTotal += msg.value;
donors[msg.sender] = msg.value;
}
modifier beneficiary() {
require(msg.sender == beneficiaryAddress);
_;
}
function endAuction () public beneficiary {
require(block.timestamp >= endDate, "The auction has not yet ended.");
require(!ended, "The auction has already ended.");
ended = true;
if (currentTotal >= beneficiaryTarget){
beneficiaryAddress.transfer(currentTotal);
currentTotal -= currentTotal;
} else {
returnDonors = true;
}
}
function returnFunds () public returns (bool) {
require (returnDonors == true);
uint value = donors[msg.sender];
if (value > 0) {
payable(msg.sender).transfer(value);
currentTotal -= value;
return false;
}
return true;
}
}