forked from blockchainsllc/DAO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagedAccount.sol
67 lines (54 loc) · 2.25 KB
/
ManagedAccount.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
/*
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/>.
*/
/*
Basic account, used by the DAO contract to separately manage both the rewards
and the extraBalance accounts.
*/
contract ManagedAccountInterface {
// The only address with permission to withdraw from this account
address public owner;
// If true, only the owner of the account can receive ether from it
bool public payOwnerOnly;
// The sum of ether (in wei) which has been sent to this contract
uint public accumulatedInput;
/// @notice Sends `_amount` of wei to _recipient
/// @param _amount The amount of wei to send to `_recipient`
/// @param _recipient The address to receive `_amount` of wei
/// @return True if the send completed
function payOut(address _recipient, uint _amount) returns (bool);
event PayOut(address indexed _recipient, uint _amount);
}
contract ManagedAccount is ManagedAccountInterface{
// The constructor sets the owner of the account
function ManagedAccount(address _owner, bool _payOwnerOnly) {
owner = _owner;
payOwnerOnly = _payOwnerOnly;
}
// When the contract receives a transaction without data this is called.
// It counts the amount of ether it receives and stores it in
// accumulatedInput.
function() {
accumulatedInput += msg.value;
}
function payOut(address _recipient, uint _amount) returns (bool) {
if (msg.sender != owner || msg.value > 0 || (payOwnerOnly && _recipient != owner))
throw;
if (_recipient.call.value(_amount)()) {
PayOut(_recipient, _amount);
return true;
} else {
return false;
}
}
}