-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2array3.11luke
103 lines (86 loc) · 2.83 KB
/
2array3.11luke
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
pragma solidity ^0.5.1;
contract flowFundr{
uint totalMoneyDonated;
uint target;
uint beginning; //must change when in next stage
uint end; //must change when in next stage
uint duration;
address payable projectOwner; // person that is fundraising for the project.
uint stage; //stage in flow
uint finalStage;
uint[2][] flow;
//to notify front end, some need params
//not implemented yet
event investmentReceived();
event fundraisingStage();
event projectLive();
event moveToNextStage();
event failedStage();
event investorsRefunded();
event projectComplete();
struct Investment{
uint amountDonated;
address investor;
}
/*if using 2d array need to declare sort of like this?
public static void main(String[] args) {
int[][] foo = new int[][] {
new int[] { 1, 2, 3 },
new int[] { 1, 2, 3, 4},
};
*/
constructor (uint[2][] memory _flow) public{ //with 2d array reference is backwards.[0][0] is first timestamp, [1][0] is second timestamp, [0][1] is first goal value
flow = _flow;
uint initialDuration = _flow[0][0];//first in flow should be initial fundraising period and goal
duration = initialDuration;
target = _flow[0][1];
stage = 0;
finalStage = _flow[1].length;//may be wrong way to reference
beginning = now;
end = beginning + duration;
}
Investment[] investments;
modifier overLimit{
require(totalMoneyDonated+msg.value <= target);
_;
}
modifier overDeadline
{
require(now < end && now >= beginning);
_;
}
function moneyTracker() public payable overLimit overDeadline{
Investment memory i = Investment(msg.value,msg.sender);
investments.push(i);
totalMoneyDonated += msg.value;
}
function transfer(uint amount, address payable a) public
{
a.transfer(amount);
}
function checkConditionMet() public view returns (bool)
{
return now < end && totalMoneyDonated==target;
}
function nextStage() public
{
if(checkConditionMet()) {
transfer(totalMoneyDonated, projectOwner);
stage++;
if(stage < finalStage){ //check to make sure indexing makes sense. else statement?
duration = flow[stage][0];//sets new duration
target = flow[stage][1];//sets new target
}
}
else refundBackInvestors();
}
function refundBackInvestors() public
{
for(uint i =0; i<investments.length; i++)
{
Investment memory inv = investments[i];
address payable donor = address(uint160(inv.investor));
transfer(inv.amountDonated,donor);
}
}
}