aboutsummaryrefslogtreecommitdiffstats
path: root/docs/contracts.rst
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-25 20:22:03 +0800
committerGitHub <noreply@github.com>2017-08-25 20:22:03 +0800
commit1417e5a4591d3472daaa3305cd61011b6241287a (patch)
treee46eb9b865b767efc09b1ae3f87d68fb6e23ae5c /docs/contracts.rst
parentd787aff6572bbc92778fb75fbeba0ce67dd408c9 (diff)
parent2af949baaa31c328060008fe5b4dc251657f3d9d (diff)
downloaddexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar.gz
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar.bz2
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar.lz
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar.xz
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.tar.zst
dexon-solidity-1417e5a4591d3472daaa3305cd61011b6241287a.zip
Merge pull request #2792 from ethereum/statemutability-docs
Require 0.4.16 for view/pure in docs examples
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r--docs/contracts.rst22
1 files changed, 20 insertions, 2 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 50e7f3d1..ef09d935 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -469,9 +469,20 @@ View Functions
Functions can be declared ``view`` in which case they promise not to modify the state.
+The following statements are considered modifying the state:
+
+#. Writing to state variables.
+#. :ref:`Emitting events. <events>`.
+#. :ref:`Creating other contracts <creating-contracts>`.
+#. Using ``selfdestruct``.
+#. Sending Ether via calls.
+#. Calling any function not marked ``view`` or ``pure``.
+#. Using low-level calls.
+#. Using inline assembly that contains certain opcodes.
+
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.16;
contract C {
function f(uint a, uint b) view returns (uint) {
@@ -496,9 +507,16 @@ Pure Functions
Functions can be declared ``pure`` in which case they promise not to read from or modify the state.
+In addition to the list of state modifying statements explained above, the following are considered reading from the state:
+#. Reading from state variables.
+#. Accessing ``this.balance`` or ``<address>.balance``.
+#. Accessing any of the members of ``block``, ``tx``, ``msg`` (with the exception of ``msg.sig`` and ``msg.data``).
+#. Calling any function not marked ``pure``.
+#. Using inline assembly that contains certain opcodes.
+
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.16;
contract C {
function f(uint a, uint b) pure returns (uint) {