From bb493bf52d174ee1095db268453ad500de15c6a5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 24 Aug 2017 10:34:18 +0100 Subject: Require 0.4.16 for view/pure in docs examples --- docs/contracts.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/contracts.rst b/docs/contracts.rst index 50e7f3d1..973386d5 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -471,7 +471,7 @@ Functions can be declared ``view`` in which case they promise not to modify the :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.16; contract C { function f(uint a, uint b) view returns (uint) { @@ -498,7 +498,7 @@ Functions can be declared ``pure`` in which case they promise not to read from o :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.16; contract C { function f(uint a, uint b) pure returns (uint) { -- cgit v1.2.3 From f791ca3957e30ba89763d3cf3327ed3e58d21b15 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 24 Aug 2017 15:32:23 +0100 Subject: Clarify ABI regarding constant --- docs/abi-spec.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst index c0969cae..fffd9a2c 100644 --- a/docs/abi-spec.rst +++ b/docs/abi-spec.rst @@ -293,9 +293,9 @@ The JSON format for a contract's interface is given by an array of function and/ * `name`: the name of the parameter; * `type`: the canonical type of the parameter. - `outputs`: an array of objects similar to `inputs`, can be omitted if function doesn't return anything; -- `constant`: `true` if function is :ref:`specified to not modify blockchain state `); - `payable`: `true` if function accepts ether, defaults to `false`; -- `stateMutability`: a string with one of the following values: `pure` (:ref:`specified to not read blockchain state `), `view` (same as `constant` above), `nonpayable` and `payable` (same as `payable` above). +- `stateMutability`: a string with one of the following values: `pure` (:ref:`specified to not read blockchain state `), `view` (:ref:`specified to not modify the blockchain state `), `nonpayable` and `payable` (same as `payable` above). +- `constant`: `true` if function is either `pure` or `view` `type` can be omitted, defaulting to `"function"`. -- cgit v1.2.3 From 2af949baaa31c328060008fe5b4dc251657f3d9d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 25 Aug 2017 11:12:26 +0100 Subject: Explain the limitations of view and pure --- docs/contracts.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/contracts.rst b/docs/contracts.rst index 973386d5..ef09d935 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -469,6 +469,17 @@ 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. `. +#. :ref:`Creating other 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.16; @@ -496,6 +507,13 @@ 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 ``
.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.16; -- cgit v1.2.3