PullPayment.sol 733 B

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