forked from blockchainsllc/DAO
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathSampleOffer.sol
156 lines (132 loc) · 4.14 KB
/
SampleOffer.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
This file is part of the DAO.
The DAO is free software: you can redistribute it and/or modify
it under the terms of the GNU lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The DAO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.
You should have received a copy of the GNU lesser General Public License
along with the DAO. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Sample Proposal from a Contractor to the DAO.
Feel free to use as a template for your own proposal.
*/
import "./DAO.sol";
contract SampleOffer {
uint public totalCosts;
uint public oneTimeCosts;
uint public dailyCosts;
address public contractor;
bytes32 public hashOfTheTerms;
uint public minDailyCosts;
uint public paidOut;
uint public dateOfSignature;
DAO public client; // address of DAO
bool public promiseValid;
uint public rewardDivisor;
uint public deploymentReward;
modifier callingRestriction {
if (promiseValid) {
if (msg.sender != address(client))
throw;
} else if (msg.sender != contractor) {
throw;
}
_
}
modifier onlyClient {
if (msg.sender != address(client))
throw;
_
}
function SampleOffer(
address _contractor,
bytes32 _hashOfTheTerms,
uint _totalCosts,
uint _oneTimeCosts,
uint _minDailyCosts
) {
contractor = _contractor;
hashOfTheTerms = _hashOfTheTerms;
totalCosts = _totalCosts;
oneTimeCosts = _oneTimeCosts;
minDailyCosts = _minDailyCosts;
dailyCosts = _minDailyCosts;
}
function sign() {
if (msg.value < totalCosts || dateOfSignature != 0)
throw;
if (!contractor.send(oneTimeCosts))
throw;
client = DAO(msg.sender);
dateOfSignature = now;
promiseValid = true;
}
function setDailyCosts(uint _dailyCosts) onlyClient {
if (dailyCosts >= minDailyCosts)
dailyCosts = _dailyCosts;
}
// "fire the contractor"
function returnRemainingMoney() onlyClient {
if (client.receiveEther.value(this.balance)())
promiseValid = false;
}
function getDailyPayment() {
if (msg.sender != contractor)
throw;
uint amount = (now - dateOfSignature) / (1 days) * dailyCosts - paidOut;
if (contractor.send(amount))
paidOut += amount;
}
function setRewardDivisor(uint _rewardDivisor) callingRestriction {
if (_rewardDivisor < 20)
throw; // 5% is the default max reward
rewardDivisor = _rewardDivisor;
}
function setDeploymentFee(uint _deploymentReward) callingRestriction {
if (deploymentReward > 10 ether)
throw; // TODO, set a max defined by Curator, or ideally oracle (set in euro)
deploymentReward = _deploymentReward;
}
function updateClientAddress(DAO _newClient) callingRestriction {
client = _newClient;
}
// interface for Ethereum Computer
function payOneTimeReward() returns(bool) {
if (msg.value < deploymentReward)
throw;
if (promiseValid) {
if (client.DAOrewardAccount().call.value(msg.value)()) {
return true;
} else {
throw;
}
} else {
if (contractor.send(msg.value)) {
return true;
} else {
throw;
}
}
}
// pay reward
function payReward() returns(bool) {
if (promiseValid) {
if (client.DAOrewardAccount().call.value(msg.value)()) {
return true;
} else {
throw;
}
} else {
if (contractor.send(msg.value)) {
return true;
} else {
throw;
}
}
}
}