mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[DOC] Some changes to functions.
This commit is contained in:
parent
2de7687c4f
commit
fa026aacb4
@ -286,7 +286,8 @@ Below you can see an example of a Sink contract that uses function ``receive``.
|
|||||||
Fallback Function
|
Fallback Function
|
||||||
=================
|
=================
|
||||||
|
|
||||||
A contract can have at most one ``fallback`` function, declared using ``fallback () external [payable]``.
|
A contract can have at most one ``fallback`` function, declared using ``fallback () external [payable]``
|
||||||
|
(without the ``function`` keyword).
|
||||||
This function cannot have arguments, cannot return anything and must have ``external`` visibility.
|
This function cannot have arguments, cannot return anything and must have ``external`` visibility.
|
||||||
It is executed on a call to the contract if none of the other
|
It is executed on a call to the contract if none of the other
|
||||||
functions match the given function signature, or if no data was supplied at
|
functions match the given function signature, or if no data was supplied at
|
||||||
@ -294,19 +295,31 @@ all and there is no :ref:`receive Ether function <receive-ether-function>`.
|
|||||||
The fallback function always receives data, but in order to also receive Ether
|
The fallback function always receives data, but in order to also receive Ether
|
||||||
it must be marked ``payable``.
|
it must be marked ``payable``.
|
||||||
|
|
||||||
In the worst case, if a payable fallback function is also used in place of a receive function, it can only rely on 2300 gas being
|
In the worst case, if a payable fallback function is also used in
|
||||||
available (see :ref:`receive Ether function <receive-ether-function>` for a brief description of the implications of this).
|
place of a receive function, it can only rely on 2300 gas being
|
||||||
|
available (see :ref:`receive Ether function <receive-ether-function>`
|
||||||
|
for a brief description of the implications of this).
|
||||||
|
|
||||||
Like any function, the fallback function can execute complex operations as long as there is enough gas passed on to it.
|
Like any function, the fallback function can execute complex
|
||||||
|
operations as long as there is enough gas passed on to it.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
A ``payable`` fallback function is also executed for plain Ether transfers, if no :ref:`receive Ether function <receive-ether-function>`
|
A ``payable`` fallback function is also executed for
|
||||||
is present. It is recommended to always define a receive Ether function as well, if you define a payable fallback function
|
plain Ether transfers, if no :ref:`receive Ether function <receive-ether-function>`
|
||||||
|
is present. It is recommended to always define a receive Ether
|
||||||
|
function as well, if you define a payable fallback function
|
||||||
to distinguish Ether transfers from interface confusions.
|
to distinguish Ether transfers from interface confusions.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Even though the fallback function cannot have arguments, one can still use ``msg.data`` to retrieve
|
Even though the fallback function cannot have arguments, one can still use ``msg.data`` to retrieve
|
||||||
any payload supplied with the call.
|
any payload supplied with the call.
|
||||||
|
After having checked the first four bytes of ``msg.data``,
|
||||||
|
you can use ``abi.decode`` together with the array slice syntax to
|
||||||
|
decode ABI-encoded data:
|
||||||
|
``(c, d) = abi.decode(msg.data[4:], (uint256, uint256));``
|
||||||
|
Note that this should only be used as a last resort and
|
||||||
|
proper functions should be used instead.
|
||||||
|
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user