Updated the function withdraw() in the SimpleAuction and BlindAuction contracts to not use a 'throw' if a address send() fails.

This commit is contained in:
Alex Darby 2016-06-18 02:29:54 +01:00 committed by chriseth
parent c282ab379a
commit 41eaf3a0cc

View File

@ -278,14 +278,21 @@ activate themselves.
} }
/// Withdraw a bid that was overbid. /// Withdraw a bid that was overbid.
function withdraw() { function withdraw() returns (bool) {
var amount = pendingReturns[msg.sender]; var amount = pendingReturns[msg.sender];
// It is important to set this to zero because the recipient if (amount > 0) {
// can call this function again as part of the receiving call // It is important to set this to zero because the recipient
// before `send` returns. // can call this function again as part of the receiving call
pendingReturns[msg.sender] = 0; // before `send` returns.
if (!msg.sender.send(amount)) pendingReturns[msg.sender] = 0;
throw; // If anything fails, this will revert the changes above
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 /// End the auction and send the highest bid
@ -489,15 +496,22 @@ high or low invalid bids.
} }
/// Withdraw a bid that was overbid. /// Withdraw a bid that was overbid.
function withdraw() { function withdraw() returns (bool) {
var amount = pendingReturns[msg.sender]; var amount = pendingReturns[msg.sender];
// It is important to set this to zero because the recipient if (amount > 0) {
// can call this function again as part of the receiving call // It is important to set this to zero because the recipient
// before `send` returns (see the remark above about // can call this function again as part of the receiving call
// conditions -> effects -> interaction). // before `send` returns (see the remark above about
pendingReturns[msg.sender] = 0; // conditions -> effects -> interaction).
if (!msg.sender.send(amount)) pendingReturns[msg.sender] = 0;
throw; // If anything fails, this will revert the changes above
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 /// End the auction and send the highest bid