-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectBase.sol
73 lines (57 loc) · 2.12 KB
/
ProjectBase.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
// SPDX-License-Identifier: NO_MORE_WARNINGS
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
abstract contract ProjectBase {
event ProjectStarted(address project);
event ProjectCompleted(address project);
address payable public founder;
string public name;
string public description;
uint public requestedBudget;
uint public totalReceivedFunds;
bool public projectStarted;
bool public projectCompleted;
mapping (address => uint) receivedFunds;
constructor(string memory _name, string memory _description, uint _requestedBudget, address payable _founder) {
name = _name;
description = _description;
requestedBudget = _requestedBudget;
founder = _founder;
}
modifier isFounder(){
require(founder == msg.sender, "Only the founder can access this function.");
_;
}
modifier hasFunds(){
require(receivedFunds[msg.sender] > 0, "You do not have any releseable funds left.");
_;
}
modifier projectRunning(){
isProjectRunning();
_;
}
function isProjectRunning() internal virtual view {
require(projectStarted, "Project not started yet.");
require(!projectCompleted, "The project is already completed.");
}
function fundProject() public virtual payable {
require(!projectCompleted, "The project is already completed.");
totalReceivedFunds += msg.value;
receivedFunds[msg.sender] += msg.value;
if(!projectStarted && requestedBudget <= totalReceivedFunds){
projectStarted = true;
emit ProjectStarted(address(this));
}
}
function releseableContributedFunds() public virtual returns (uint);
function requestFundsBack() public virtual hasFunds {
uint rem = releseableContributedFunds();
msg.sender.transfer(rem);
receivedFunds[msg.sender] = 0;
totalReceivedFunds -= rem;
}
function completeProject() internal isFounder {
projectCompleted = true;
emit ProjectCompleted(address(this));
}
}