PullPayment
父类合约。支持通过拉取方式实现支付。继承这个合约,并通过asyncSend
来替代发送功能。理念参考这个文章:http://me.tryblockchain.org/onward-with-ethereum-smart-contract-security.html
原文地址:http://zeppelin-solidity.readthedocs.io/en/latest/pullpayment.html
asyncSend(address dest, uint amount) internal
设置收款人可以接收的付款额度(这里还兼容了某个人可能有好几份的情况,不知道这样是好的,还是不好的呢)。
function asyncSend(address dest, uint256 amount) internal {
payments[dest] = payments[dest].add(amount);
totalPayments = totalPayments.add(amount);
}
withdrawPayments( )
当收款人调用合约时,发送指定的余额给收款人。当余额是0
时,或没有足够余额,或者发送失败了,将抛出异常(话说这种涉及到钱的,应该加一些日志)。
function withdrawPayments() {
address payee = msg.sender;
uint256 payment = payments[payee];
require(payment != 0);
require(this.balance >= payment);
totalPayments = totalPayments.sub(payment);
payments[payee] = 0;
assert(payee.send(payment));
}
处于某些特定的环境下,可以看到评论框,欢迎留言交流^_^。