PullPayment.sol 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pragma solidity ^0.4.24;
  2. import "./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() public {
  11. escrow = new Escrow();
  12. }
  13. /**
  14. * @dev Withdraw accumulated balance, called by payee.
  15. */
  16. function withdrawPayments() public {
  17. address payee = msg.sender;
  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. }