mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Document call/gas modifiers properly
This commit is contained in:
parent
bf294253bb
commit
8743b2cead
@ -503,23 +503,6 @@ Note2: Optimizing storage access can pull the gas costs down considerably, becau
|
|||||||
currently do not work across loops and also have a problem with bounds checking.
|
currently do not work across loops and also have a problem with bounds checking.
|
||||||
You might get much better results in the future, though.
|
You might get much better results in the future, though.
|
||||||
|
|
||||||
What does ``p.recipient.call.value(p.amount)(p.data)`` do?
|
|
||||||
==========================================================
|
|
||||||
|
|
||||||
Every external function call in Solidity can be modified in two ways:
|
|
||||||
|
|
||||||
1. You can add Ether together with the call
|
|
||||||
2. You can limit the amount of gas available to the call
|
|
||||||
|
|
||||||
This is done by "calling a function on the function":
|
|
||||||
|
|
||||||
``f.gas(2).value(20)()`` calls the modified function ``f`` and thereby sending 20
|
|
||||||
Wei and limiting the gas to 2 (so this function call will most likely go out of
|
|
||||||
gas and return your 20 Wei).
|
|
||||||
|
|
||||||
In the above example, the low-level function ``call`` is used to invoke another
|
|
||||||
contract with ``p.data`` as payload and ``p.amount`` Wei is sent with that call.
|
|
||||||
|
|
||||||
What happens to a ``struct``'s mapping when copying over a ``struct``?
|
What happens to a ``struct``'s mapping when copying over a ``struct``?
|
||||||
======================================================================
|
======================================================================
|
||||||
|
|
||||||
|
@ -127,6 +127,18 @@ the function ``call`` is provided which takes an arbitrary number of arguments o
|
|||||||
|
|
||||||
``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned (for this we would need to know the encoding and size in advance).
|
``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned (for this we would need to know the encoding and size in advance).
|
||||||
|
|
||||||
|
It is possible to adjust the supplied gas with the ``.gas()`` modifier::
|
||||||
|
|
||||||
|
namReg.call.gas(1000000)("register", "MyName");
|
||||||
|
|
||||||
|
Similarly, the supplied Ether value can be controlled too::
|
||||||
|
|
||||||
|
nameReg.call.value(1 ether)("register", "MyName");
|
||||||
|
|
||||||
|
Lastly, these modifiers can be combined. Their order does not matter::
|
||||||
|
|
||||||
|
nameReg.call.gas(1000000).value(1 ether)("register", "MyName");
|
||||||
|
|
||||||
In a similar way, the function ``delegatecall`` can be used: the difference is that only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract. The purpose of ``delegatecall`` is to use library code which is stored in another contract. The user has to ensure that the layout of storage in both contracts is suitable for delegatecall to be used. Prior to homestead, only a limited variant called ``callcode`` was available that did not provide access to the original ``msg.sender`` and ``msg.value`` values.
|
In a similar way, the function ``delegatecall`` can be used: the difference is that only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract. The purpose of ``delegatecall`` is to use library code which is stored in another contract. The user has to ensure that the layout of storage in both contracts is suitable for delegatecall to be used. Prior to homestead, only a limited variant called ``callcode`` was available that did not provide access to the original ``msg.sender`` and ``msg.value`` values.
|
||||||
|
|
||||||
All three functions ``call``, ``delegatecall`` and ``callcode`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
|
All three functions ``call``, ``delegatecall`` and ``callcode`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
|
||||||
|
Loading…
Reference in New Issue
Block a user