aboutsummaryrefslogtreecommitdiffstats
path: root/docs/common-patterns.rst
diff options
context:
space:
mode:
authorMatt Wisniewski <contact.mattdylan@gmail.com>2017-04-20 02:12:45 +0800
committerchriseth <chris@ethereum.org>2017-05-03 18:03:02 +0800
commit2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53 (patch)
tree34b54c98a4e9f359479bbc5b73945b3c74884c98 /docs/common-patterns.rst
parent00933b99cc64a5af1e00ed4b119fc725ddbb3513 (diff)
downloaddexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.tar.gz
dexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.tar.zst
dexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.zip
Update common-patterns.rst
Diffstat (limited to 'docs/common-patterns.rst')
-rw-r--r--docs/common-patterns.rst22
1 files changed, 9 insertions, 13 deletions
diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst
index de2da690..37973c62 100644
--- a/docs/common-patterns.rst
+++ b/docs/common-patterns.rst
@@ -28,7 +28,7 @@ become the new richest.
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
contract WithdrawalContract {
address public richest;
@@ -70,7 +70,7 @@ This is as opposed to the more intuitive sending pattern:
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
contract SendContract {
address public richest;
@@ -86,9 +86,7 @@ This is as opposed to the more intuitive sending pattern:
// Check if call succeeds to prevent an attacker
// from trapping the previous person's funds in
// this contract through a callstack attack
- if (!richest.send(msg.value)) {
- throw;
- }
+ richest.transfer(msg.value);
richest = msg.sender;
mostSent = msg.value;
return true;
@@ -135,7 +133,7 @@ restrictions highly readable.
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
contract AccessRestriction {
// These will be assigned at the construction
@@ -152,8 +150,7 @@ restrictions highly readable.
// a certain address.
modifier onlyBy(address _account)
{
- if (msg.sender != _account)
- throw;
+ require(msg.sender == _account);
// Do not forget the "_;"! It will
// be replaced by the actual function
// body when the modifier is used.
@@ -169,7 +166,7 @@ restrictions highly readable.
}
modifier onlyAfter(uint _time) {
- if (now < _time) throw;
+ require(now >= _time);
_;
}
@@ -190,8 +187,7 @@ restrictions highly readable.
// This was dangerous before Solidity version 0.4.0,
// where it was possible to skip the part after `_;`.
modifier costs(uint _amount) {
- if (msg.value < _amount)
- throw;
+ require(msg.value >= _amount);
_;
if (msg.value > _amount)
msg.sender.send(msg.value - _amount);
@@ -276,7 +272,7 @@ function finishes.
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
contract StateMachine {
enum Stages {
@@ -293,7 +289,7 @@ function finishes.
uint public creationTime = now;
modifier atStage(Stages _stage) {
- if (stage != _stage) throw;
+ require(stage == _stage);
_;
}