diff options
author | Matt Wisniewski <contact.mattdylan@gmail.com> | 2017-04-20 02:12:45 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-05-03 18:03:02 +0800 |
commit | 2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53 (patch) | |
tree | 34b54c98a4e9f359479bbc5b73945b3c74884c98 /docs/contracts.rst | |
parent | 00933b99cc64a5af1e00ed4b119fc725ddbb3513 (diff) | |
download | dexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.tar.gz dexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.tar.zst dexon-solidity-2b4b86aa7f72d8f7c2c4e250953d8f9018f4fd53.zip |
Update common-patterns.rst
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r-- | docs/contracts.rst | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst index 26c0c886..a26d5a5e 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -327,7 +327,7 @@ inheritable properties of contracts and may be overridden by derived contracts. :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.11; contract owned { function owned() { owner = msg.sender; } @@ -341,8 +341,7 @@ inheritable properties of contracts and may be overridden by derived contracts. // function is executed and otherwise, an exception is // thrown. modifier onlyOwner { - if (msg.sender != owner) - throw; + require(msg.sender == owner); _; } } @@ -390,7 +389,7 @@ inheritable properties of contracts and may be overridden by derived contracts. contract Mutex { bool locked; modifier noReentrancy() { - if (locked) throw; + require(!locked); locked = true; _; locked = false; @@ -401,7 +400,7 @@ inheritable properties of contracts and may be overridden by derived contracts. /// The `return 7` statement assigns 7 to the return value but still /// executes the statement `locked = false` in the modifier. function f() noReentrancy returns (uint) { - if (!msg.sender.call()) throw; + require(msg.sender.call()); return 7; } } @@ -989,7 +988,7 @@ more advanced example to implement a set). :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.11; library Set { // We define a new struct datatype that will be used to @@ -1035,8 +1034,7 @@ more advanced example to implement a set). // The library functions can be called without a // specific instance of the library, since the // "instance" will be the current contract. - if (!Set.insert(knownValues, value)) - throw; + assert(Set.insert(knownValues, value)); } // In this contract, we can also directly access knownValues.flags, if we want. } @@ -1166,7 +1164,7 @@ available without having to add further code. Let us rewrite the set example from the :ref:`libraries` in this way:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.11; // This is the same code as before, just without comments library Set { @@ -1207,8 +1205,7 @@ Let us rewrite the set example from the // corresponding member functions. // The following function call is identical to // Set.insert(knownValues, value) - if (!knownValues.insert(value)) - throw; + require(knownValues.insert(value)); } } |