2019-09-25 13:59:52 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-10-23 20:10:12 +00:00
|
|
|
abstract contract ManagedAccountInterface {
|
2019-09-25 13:59:52 +00:00
|
|
|
// 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
|
2019-11-05 17:25:34 +00:00
|
|
|
function payOut(address payable _recipient, uint _amount) public virtual returns (bool);
|
2019-09-25 13:59:52 +00:00
|
|
|
|
|
|
|
event PayOut(address indexed _recipient, uint _amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract ManagedAccount is ManagedAccountInterface{
|
|
|
|
|
|
|
|
// The constructor sets the owner of the account
|
2020-06-23 12:14:24 +00:00
|
|
|
constructor(address _owner, bool _payOwnerOnly) {
|
2019-09-25 13:59:52 +00:00
|
|
|
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.
|
2019-09-09 16:22:02 +00:00
|
|
|
receive() external payable {
|
2019-09-25 13:59:52 +00:00
|
|
|
accumulatedInput += msg.value;
|
|
|
|
}
|
|
|
|
|
2019-09-16 12:33:43 +00:00
|
|
|
function payOut(address payable _recipient, uint _amount) public override returns (bool) {
|
2019-09-25 13:59:52 +00:00
|
|
|
if (msg.sender != owner || (payOwnerOnly && _recipient != owner))
|
|
|
|
revert();
|
2020-04-03 14:29:17 +00:00
|
|
|
(bool success,) = _recipient.call{value: _amount}("");
|
2019-09-25 13:59:52 +00:00
|
|
|
if (success) {
|
|
|
|
emit PayOut(_recipient, _amount);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|