forked from blockchainsllc/DAO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SampleOffer.sol
129 lines (106 loc) · 3.65 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
/*
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 dailyWithdrawLimit;
address public contractor;
bytes32 public IPFSHashOfTheProposalDocument;
uint public minDailyWithdrawLimit;
uint public paidOut;
uint public dateOfSignature;
DAO public client; // address of DAO
bool public isContractValid;
uint public rewardDivisor;
uint public deploymentReward;
modifier onlyClient {
if (msg.sender != address(client))
throw;
_
}
function SampleOffer(
address _contractor,
address _client,
bytes32 _IPFSHashOfTheProposalDocument,
uint _totalCosts,
uint _oneTimeCosts,
uint _minDailyWithdrawLimit
) {
contractor = _contractor;
client = DAO(_client);
IPFSHashOfTheProposalDocument = _IPFSHashOfTheProposalDocument;
totalCosts = _totalCosts;
oneTimeCosts = _oneTimeCosts;
minDailyWithdrawLimit = _minDailyWithdrawLimit;
dailyWithdrawLimit = _minDailyWithdrawLimit;
}
function sign() {
if (msg.sender != address(client) // no good samaritans give us money
|| msg.value != totalCosts // no under/over payment
|| dateOfSignature != 0) // don't sign twice
throw;
if (!contractor.send(oneTimeCosts))
throw;
dateOfSignature = now;
isContractValid = true;
}
function setDailyWithdrawLimit(uint _dailyWithdrawLimit) onlyClient {
if (_dailyWithdrawLimit >= minDailyWithdrawLimit)
dailyWithdrawLimit = _dailyWithdrawLimit;
}
// "fire the contractor"
function returnRemainingEther() onlyClient {
if (client.DAOrewardAccount().call.value(this.balance)())
isContractValid = false;
}
function getDailyPayment() {
if (msg.sender != contractor)
throw;
uint amount = (now - dateOfSignature + 1 days) / (1 days) * dailyWithdrawLimit - paidOut;
if (contractor.send(amount))
paidOut += amount;
}
function setRewardDivisor(uint _rewardDivisor) onlyClient {
rewardDivisor = _rewardDivisor;
}
function setDeploymentReward(uint _deploymentReward) onlyClient {
deploymentReward = _deploymentReward;
}
function updateClientAddress(DAO _newClient) onlyClient {
client = _newClient;
}
// interface for Ethereum Computer
function payOneTimeReward() returns(bool) {
if (msg.value < deploymentReward)
throw;
if (client.DAOrewardAccount().call.value(msg.value)()) {
return true;
} else {
throw;
}
}
// pay reward
function payReward() returns(bool) {
if (client.DAOrewardAccount().call.value(msg.value)()) {
return true;
} else {
throw;
}
}
}