* Update to ganache-cli v6.1.0 and truffle v4.1.0 * Update to stable version of ganache-cli * fix: update event emission warning - Fix event emission warnings for solidity 4.21 after truffle has been updated to use this version * fix pr review comments * update to truffle v4.1.5 * update package-lock * add additional emit keywords * update solidity-coverage to 0.4.15 * update to solium 1.1.6 * fix MerkleProof coverage analysis by testing through wrapper * change version pragma to ^0.4.21 * fix solium linting errors
44 lines
1.0 KiB
Solidity
44 lines
1.0 KiB
Solidity
pragma solidity ^0.4.21;
|
|
|
|
|
|
import "../math/SafeMath.sol";
|
|
|
|
|
|
/**
|
|
* @title PullPayment
|
|
* @dev Base contract supporting async send for pull payments. Inherit from this
|
|
* contract and use asyncSend instead of send or transfer.
|
|
*/
|
|
contract PullPayment {
|
|
using SafeMath for uint256;
|
|
|
|
mapping(address => uint256) public payments;
|
|
uint256 public totalPayments;
|
|
|
|
/**
|
|
* @dev Withdraw accumulated balance, called by payee.
|
|
*/
|
|
function withdrawPayments() public {
|
|
address payee = msg.sender;
|
|
uint256 payment = payments[payee];
|
|
|
|
require(payment != 0);
|
|
require(this.balance >= payment);
|
|
|
|
totalPayments = totalPayments.sub(payment);
|
|
payments[payee] = 0;
|
|
|
|
payee.transfer(payment);
|
|
}
|
|
|
|
/**
|
|
* @dev Called by the payer to store the sent amount as credit to be pulled.
|
|
* @param dest The destination address of the funds.
|
|
* @param amount The amount to transfer.
|
|
*/
|
|
function asyncSend(address dest, uint256 amount) internal {
|
|
payments[dest] = payments[dest].add(amount);
|
|
totalPayments = totalPayments.add(amount);
|
|
}
|
|
}
|