Skip to content

Commit

Permalink
chore[docs]: nonpayable internal function behaviour (#4416)
Browse files Browse the repository at this point in the history
this commit adds a note to clarify that `nonpayable` `internal`
functions can be called via `external` `payable` functions.
  • Loading branch information
pcaversaccio authored Dec 31, 2024
1 parent 194d60a commit da5beb6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ Or for internal functions which are defined in :ref:`imported modules <modules>`
def calculate(amount: uint256) -> uint256:
return calculator_library._times_two(amount)
Marking an internal function as ``payable`` specifies that the function can interact with ``msg.value``. A ``nonpayable`` internal function can be called from an external ``payable`` function, but it cannot access ``msg.value``.

.. code-block:: vyper
@payable
def _foo() -> uint256:
return msg.value % 2
.. note::
As of v0.4.0, the ``@internal`` decorator is optional. That is, functions with no visibility decorator default to being ``internal``.

Expand Down Expand Up @@ -110,7 +118,7 @@ You can optionally declare a function's mutability by using a :ref:`decorator <f
* ``@pure``: does not read from the contract state or any environment variables.
* ``@view``: may read from the contract state, but does not alter it.
* ``@nonpayable`` (default): may read from and write to the contract state, but cannot receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive and access Ether via ``msg.value``.

.. code-block:: vyper
Expand All @@ -132,6 +140,9 @@ Functions marked with ``@view`` cannot call mutable (``payable`` or ``nonpayable

Functions marked with ``@pure`` cannot call non-``pure`` functions.

.. note::
The ``@nonpayable`` decorator is not strictly enforced on ``internal`` functions when they are invoked through an ``external`` ``payable`` function. As a result, an ``external`` ``payable`` function can invoke an ``internal`` ``nonpayable`` function. However, the ``nonpayable`` ``internal`` function cannot have access to ``msg.value``.

Re-entrancy Locks
-----------------

Expand Down

0 comments on commit da5beb6

Please sign in to comment.