PullPayment.sol 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. pragma solidity ^0.5.0;
  2. import "./escrow/Escrow.sol";
  3. /**
  4. * @title PullPayment
  5. * @dev Base contract supporting async send for pull payments. Inherit from this
  6. * contract and use {_asyncTransfer} instead of send or transfer.
  7. */
  8. contract PullPayment {
  9. Escrow private _escrow;
  10. constructor () internal {
  11. _escrow = new Escrow();
  12. }
  13. /**
  14. * @dev Withdraw accumulated balance.
  15. * @param payee Whose balance will be withdrawn.
  16. */
  17. function withdrawPayments(address payable payee) public {
  18. _escrow.withdraw(payee);
  19. }
  20. /**
  21. * @dev Returns the credit owed to an address.
  22. * @param dest The creditor's address.
  23. */
  24. function payments(address dest) public view returns (uint256) {
  25. return _escrow.depositsOf(dest);
  26. }
  27. /**
  28. * @dev Called by the payer to store the sent amount as credit to be pulled.
  29. * @param dest The destination address of the funds.
  30. * @param amount The amount to transfer.
  31. */
  32. function _asyncTransfer(address dest, uint256 amount) internal {
  33. _escrow.deposit.value(amount)(dest);
  34. }
  35. }