Commit ae60987f by Manuel Araoz

refactor and document PullPaymentCapable

parent 71295a12
/*
* PullPaymentCapable
* Base contract supporting async send for pull payments.
* Inherit from this contract and use asyncSend instead of send.
*/
contract PullPaymentCapable { contract PullPaymentCapable {
mapping(address => uint) refunds; mapping(address => uint) payments;
// store sent amount as credit to be pulled, called by payer
function asyncSend(address dest, uint amount) internal { function asyncSend(address dest, uint amount) internal {
refunds[dest] += amount; payments[dest] += amount;
} }
function withdrawRefund() external { // withdraw accumulated balance, called by payee
uint refund = refunds[msg.sender]; function withdrawPayments() external {
refunds[msg.sender] = 0; uint payment = payments[msg.sender];
if (!msg.sender.send(refund)) { payments[msg.sender] = 0;
refunds[msg.sender] = refund; if (!msg.sender.send(payment)) {
payments[msg.sender] = payment;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment