* Added basic Escrow * PullPayment now uses an Escrow, removing all trust from the contract * Abstracted the Escrow tests to a behaviour * Added ConditionalEscrow * Added RefundableEscrow. * RefundableCrowdsale now uses a RefundEscrow, removed RefundVault. * Renaming after code review. * Added log test helper. * Now allowing empty deposits and withdrawals. * Style fixes. * Minor review comments. * Add Deposited and Withdrawn events, removed Refunded * The base Escrow is now Ownable, users of it (owners) must provide methods to access it.
52 lines
1.4 KiB
Solidity
52 lines
1.4 KiB
Solidity
pragma solidity ^0.4.23;
|
|
|
|
import "../math/SafeMath.sol";
|
|
import "../ownership/Ownable.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 owner, and provide public methods redirecting to the escrow's
|
|
* deposit and withdraw.
|
|
*/
|
|
contract Escrow is Ownable {
|
|
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 onlyOwner 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 onlyOwner {
|
|
uint256 payment = deposits[_payee];
|
|
assert(address(this).balance >= payment);
|
|
|
|
deposits[_payee] = 0;
|
|
|
|
_payee.transfer(payment);
|
|
|
|
emit Withdrawn(_payee, payment);
|
|
}
|
|
}
|