From e27493aa8306da65d4cfc464b7867f1faaf72a9f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 18 Aug 2016 12:56:39 -0400 Subject: Remove throw from withdrawal pattern --- docs/common-patterns.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'docs/common-patterns.rst') diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 6302af72..12c6f20c 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -51,13 +51,17 @@ become the new richest. } } - function withdraw() { + function withdraw() returns (bool) { uint amount = pendingWithdrawals[msg.sender]; // Remember to zero the pending refund before // sending to prevent re-entrancy attacks pendingWithdrawals[msg.sender] = 0; - if (!msg.sender.send(amount)) { - throw; + if (msg.sender.send(amount)) { + return true; + } + else { + pendingWithdrawals[msg.sender] = amount; + return false; } } } -- cgit v1.2.3