diff options
author | chriseth <chris@ethereum.org> | 2016-08-25 05:17:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 05:17:04 +0800 |
commit | c2665dc2fe0e7e973ae599ac7010fa6939ebd20f (patch) | |
tree | e956143f6b17e3794efa0dedfc225cb8cb64bb0c /docs | |
parent | 9fc1bcb2becf48192e5c52d6af1fac2b88656f2d (diff) | |
parent | 41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71 (diff) | |
download | dexon-solidity-c2665dc2fe0e7e973ae599ac7010fa6939ebd20f.tar.gz dexon-solidity-c2665dc2fe0e7e973ae599ac7010fa6939ebd20f.tar.zst dexon-solidity-c2665dc2fe0e7e973ae599ac7010fa6939ebd20f.zip |
Merge pull request #913 from chriseth/auction
Updated the function withdraw() in the SimpleAuction and BlindAuction…
Diffstat (limited to 'docs')
-rw-r--r-- | docs/solidity-by-example.rst | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index 86d6f72b..61589b2e 100644 --- a/docs/solidity-by-example.rst +++ b/docs/solidity-by-example.rst @@ -280,14 +280,21 @@ activate themselves. } /// Withdraw a bid that was overbid. - function withdraw() { + function withdraw() returns (bool) { var amount = pendingReturns[msg.sender]; - // It is important to set this to zero because the recipient - // can call this function again as part of the receiving call - // before `send` returns. - pendingReturns[msg.sender] = 0; - if (!msg.sender.send(amount)) - throw; // If anything fails, this will revert the changes above + if (amount > 0) { + // It is important to set this to zero because the recipient + // can call this function again as part of the receiving call + // before `send` returns. + pendingReturns[msg.sender] = 0; + + if (!msg.sender.send(amount)) { + // No need to call throw here, just reset the amount owing + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; } /// End the auction and send the highest bid @@ -491,15 +498,22 @@ high or low invalid bids. } /// Withdraw a bid that was overbid. - function withdraw() { + function withdraw() returns (bool) { var amount = pendingReturns[msg.sender]; - // It is important to set this to zero because the recipient - // can call this function again as part of the receiving call - // before `send` returns (see the remark above about - // conditions -> effects -> interaction). - pendingReturns[msg.sender] = 0; - if (!msg.sender.send(amount)) - throw; // If anything fails, this will revert the changes above + if (amount > 0) { + // It is important to set this to zero because the recipient + // can call this function again as part of the receiving call + // before `send` returns (see the remark above about + // conditions -> effects -> interaction). + pendingReturns[msg.sender] = 0; + + if (!msg.sender.send(amount)){ + // No need to call throw here, just reset the amount owing + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; } /// End the auction and send the highest bid |