You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
pragma solidity ^0.4.24;
|
|
|
|
import "../math/SafeMath.sol";
|
|
import "../ownership/Secondary.sol";
|
|
|
|
/**
|
|
* @title Escrow
|
|
* @dev Base escrow contract, holds funds destinated to a payee until they
|
|
* withdraw them. The contract that uses the escrow as its payment method
|
|
* should be its primary, and provide public methods redirecting to the escrow's
|
|
* deposit and withdraw.
|
|
*/
|
|
contract Escrow is Secondary {
|
|
using SafeMath for uint256;
|
|
|
|
event Deposited(address indexed payee, uint256 weiAmount);
|
|
event Withdrawn(address indexed payee, uint256 weiAmount);
|
|
|
|
mapping(address => uint256) private _deposits;
|
|
|
|
function depositsOf(address payee) public view returns (uint256) {
|
|
return _deposits[payee];
|
|
}
|
|
|
|
/**
|
|
* @dev Stores the sent amount as credit to be withdrawn.
|
|
* @param payee The destination address of the funds.
|
|
*/
|
|
function deposit(address payee) public onlyPrimary payable {
|
|
uint256 amount = msg.value;
|
|
_deposits[payee] = _deposits[payee].add(amount);
|
|
|
|
emit Deposited(payee, amount);
|
|
}
|
|
|
|
/**
|
|
* @dev Withdraw accumulated balance for a payee.
|
|
* @param payee The address whose funds will be withdrawn and transferred to.
|
|
*/
|
|
function withdraw(address payee) public onlyPrimary {
|
|
uint256 payment = _deposits[payee];
|
|
assert(address(this).balance >= payment);
|
|
|
|
_deposits[payee] = 0;
|
|
|
|
payee.transfer(payment);
|
|
|
|
emit Withdrawn(payee, payment);
|
|
}
|
|
}
|
|
|