PullPayment.sol 797 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. pragma solidity ^0.4.8;
  2. import '../SafeMath.sol';
  3. /*
  4. * PullPayment
  5. * Base contract supporting async send for pull payments.
  6. * Inherit from this contract and use asyncSend instead of send.
  7. */
  8. contract PullPayment is SafeMath {
  9. mapping(address => uint) public payments;
  10. // store sent amount as credit to be pulled, called by payer
  11. function asyncSend(address dest, uint amount) internal {
  12. payments[dest] = safeAdd(payments[dest], amount);
  13. }
  14. // withdraw accumulated balance, called by payee
  15. function withdrawPayments() {
  16. address payee = msg.sender;
  17. uint payment = payments[payee];
  18. if (payment == 0) {
  19. throw;
  20. }
  21. if (this.balance < payment) {
  22. throw;
  23. }
  24. payments[payee] = 0;
  25. if (!payee.send(payment)) {
  26. throw;
  27. }
  28. }
  29. }