diff options
author | Denton Liu <liu.denton+github@gmail.com> | 2016-08-19 00:56:39 +0800 |
---|---|---|
committer | Denton Liu <liu.denton+github@gmail.com> | 2016-08-19 00:56:39 +0800 |
commit | e27493aa8306da65d4cfc464b7867f1faaf72a9f (patch) | |
tree | ce22ca6273d4e28a23858d1c02f3462d37271912 /docs/common-patterns.rst | |
parent | 0b3ad9262cd99ae4788e14f399905952c16d5d27 (diff) | |
download | dexon-solidity-e27493aa8306da65d4cfc464b7867f1faaf72a9f.tar.gz dexon-solidity-e27493aa8306da65d4cfc464b7867f1faaf72a9f.tar.zst dexon-solidity-e27493aa8306da65d4cfc464b7867f1faaf72a9f.zip |
Remove throw from withdrawal pattern
Diffstat (limited to 'docs/common-patterns.rst')
-rw-r--r-- | docs/common-patterns.rst | 10 |
1 files changed, 7 insertions, 3 deletions
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; } } } |