aboutsummaryrefslogtreecommitdiffstats
path: root/docs/solidity-by-example.rst
diff options
context:
space:
mode:
authorAlex Darby <alexdarby64@gmail.com>2016-06-18 09:29:54 +0800
committerchriseth <c@ethdev.com>2016-08-19 00:00:30 +0800
commit41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71 (patch)
treef7141a628156f932364066a972e2a84471952ab6 /docs/solidity-by-example.rst
parentc282ab379aac4a6b14f59a957c6261e2edb8b1ce (diff)
downloaddexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar.gz
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar.bz2
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar.lz
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar.xz
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.tar.zst
dexon-solidity-41eaf3a0cc6b234b681ab93e8c81ad2180a9bc71.zip
Updated the function withdraw() in the SimpleAuction and BlindAuction contracts to not use a 'throw' if a address send() fails.
Diffstat (limited to 'docs/solidity-by-example.rst')
-rw-r--r--docs/solidity-by-example.rst44
1 files changed, 29 insertions, 15 deletions
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index 7dd51f00..4051cd94 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -278,14 +278,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
@@ -489,15 +496,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