mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Document view functions
This commit is contained in:
parent
70bb1e7478
commit
b1cdf81506
@ -293,7 +293,7 @@ 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 <constant-functions>`);
|
||||
- `constant`: `true` if function is :ref:`specified to not modify blockchain state <view-functions>`);
|
||||
- `payable`: `true` if function accepts ether, defaults to `false`;
|
||||
- `statemutability`: a string with one of the following values: `view` (same as `constant` above), `nonpayable` and `payable` (same as `payable` above).
|
||||
|
||||
|
@ -461,29 +461,32 @@ value types and strings.
|
||||
}
|
||||
|
||||
|
||||
.. _constant-functions:
|
||||
.. _view-functions:
|
||||
|
||||
******************
|
||||
Constant Functions
|
||||
******************
|
||||
**************
|
||||
View Functions
|
||||
**************
|
||||
|
||||
Functions can be declared constant in which case they promise not to modify the state.
|
||||
Functions can be declared ``view`` in which case they promise not to modify the state.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
contract C {
|
||||
function f(uint a, uint b) constant returns (uint) {
|
||||
function f(uint a, uint b) view returns (uint) {
|
||||
return a * (b + 42);
|
||||
}
|
||||
}
|
||||
|
||||
.. note::
|
||||
Getter methods are marked constant.
|
||||
``constant`` is an alias to ``view``.
|
||||
|
||||
.. note::
|
||||
Getter methods are marked ``view``.
|
||||
|
||||
.. warning::
|
||||
The compiler does not enforce yet that a constant method is not modifying state.
|
||||
The compiler does not enforce yet that a ``view`` method is not modifying state.
|
||||
|
||||
.. index:: ! fallback function, function;fallback
|
||||
|
||||
|
@ -505,11 +505,12 @@ Function Visibility Specifiers
|
||||
Modifiers
|
||||
=========
|
||||
|
||||
- ``view`` for functions: Disallow modification of state - this is not enforced yet.
|
||||
- ``payable`` for functions: Allows them to receive Ether together with a call.
|
||||
- ``constant`` for state variables: Disallows assignment (except initialisation), does not occupy storage slot.
|
||||
- ``constant`` for functions: Disallows modification of state - this is not enforced yet.
|
||||
- ``constant`` for functions: Same as ``view``.
|
||||
- ``anonymous`` for events: Does not store event signature as topic.
|
||||
- ``indexed`` for event parameters: Stores the parameter as topic.
|
||||
- ``payable`` for functions: Allows them to receive Ether together with a call.
|
||||
|
||||
Reserved Keywords
|
||||
=================
|
||||
|
Loading…
Reference in New Issue
Block a user