-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add various deprecation warnings #16174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
5090f20
c913aee
75fd2cd
91906b4
c51131e
5a9cccd
c618def
206043d
9839da9
838dbbd
2358204
f1cf279
3635b5c
db310b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -692,15 +692,17 @@ and ``assert`` for internal error checking. | |
| :force: | ||
|
|
||
| // SPDX-License-Identifier: GPL-3.0 | ||
| pragma solidity >=0.5.0 <0.9.0; | ||
| pragma solidity >=0.6.2 <0.9.0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some examples need this because before |
||
|
|
||
| contract Sharer { | ||
| function sendHalf(address payable addr) public payable returns (uint balance) { | ||
| require(msg.value % 2 == 0, "Even value required."); | ||
| uint balanceBeforeTransfer = address(this).balance; | ||
| addr.transfer(msg.value / 2); | ||
| // Since transfer throws an exception on failure and | ||
| // cannot call back here, there should be no way for us to | ||
| (bool success, ) = addr.call{value: msg.value / 2}(""); | ||
| require(success); | ||
| // Since require will stop execution and | ||
| // revert if success is false, | ||
| // there should be no way for us to | ||
| // still have half of the Ether. | ||
| assert(address(this).balance == balanceBeforeTransfer - msg.value / 2); | ||
| return address(this).balance; | ||
|
|
@@ -775,7 +777,8 @@ together with ``revert`` and the equivalent ``require``: | |
| if (msg.sender != owner) | ||
| revert Unauthorized(); | ||
|
|
||
| payable(msg.sender).transfer(address(this).balance); | ||
| (bool success, ) = payable(msg.sender).call{value: address(this).balance}(""); | ||
| require(success); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -914,4 +917,4 @@ in scope in the block that follows. | |
| out-of-gas situation and not a deliberate error condition: | ||
| The caller always retains at least 1/64th of the gas in a call and thus | ||
| even if the called contract goes out of gas, the caller still | ||
| has some gas left. | ||
| has some gas left. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ To give an example, the following code contains a bug (it is just a snippet and | |
| mapping(address => uint) shares; | ||
| /// Withdraw your share. | ||
| function withdraw() public { | ||
| // This will report a warning (deprecation) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have left some of these comments because the text mentions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to leave it as-is with your warnings but we should complete the section with reentrancy when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I changed the final example replacing transfer with call. |
||
| if (payable(msg.sender).send(shares[msg.sender])) | ||
| shares[msg.sender] = 0; | ||
| } | ||
|
|
@@ -100,7 +101,7 @@ To avoid reentrancy, you can use the Checks-Effects-Interactions pattern as demo | |
| .. code-block:: solidity | ||
|
|
||
| // SPDX-License-Identifier: GPL-3.0 | ||
| pragma solidity >=0.6.0 <0.9.0; | ||
| pragma solidity >=0.6.2 <0.9.0; | ||
|
|
||
| contract Fund { | ||
| /// @dev Mapping of ether shares of the contract. | ||
|
|
@@ -109,7 +110,8 @@ To avoid reentrancy, you can use the Checks-Effects-Interactions pattern as demo | |
| function withdraw() public { | ||
| uint share = shares[msg.sender]; | ||
| shares[msg.sender] = 0; | ||
| payable(msg.sender).transfer(share); | ||
| (bool success, ) = payable(msg.sender).call{value: share}(""); | ||
| require(success); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -255,6 +257,7 @@ Let's say you have a wallet contract like this: | |
| function transferTo(address payable dest, uint amount) public { | ||
| // THE BUG IS RIGHT HERE, you must use msg.sender instead of tx.origin | ||
| require(tx.origin == owner); | ||
| // This will report a warning (deprecation) | ||
| dest.transfer(amount); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,6 +261,11 @@ reverts on failure. | |
| .. note:: | ||
| If ``x`` is a contract address, its code (more specifically: its :ref:`receive-ether-function`, if present, or otherwise its :ref:`fallback-function`, if present) will be executed together with the ``transfer`` call (this is a feature of the EVM and cannot be prevented). If that execution runs out of gas or fails in any way, the Ether transfer will be reverted and the current contract will stop with an exception. | ||
|
|
||
| .. warning:: | ||
| ``transfer`` is deprecated and scheduled for removal in the next breaking version (0.9). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't hurt to repeat the bit about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| You are encouraged to use the :ref:`call function <address_call_functions>` with an optionally provided maximum | ||
| amount of gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``. | ||
|
|
||
| * ``send`` | ||
|
|
||
| ``send`` is the low-level counterpart of ``transfer``. If the execution fails, the current contract will not stop with an exception, but ``send`` will return ``false``. | ||
|
|
@@ -271,6 +276,13 @@ reverts on failure. | |
| to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better: | ||
| use a pattern where the recipient withdraws the Ether. | ||
|
|
||
| .. warning:: | ||
| ``send`` is deprecated and scheduled for removal in the next breaking version (0.9). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't hurt to repeat the bit about using call instead here and/or link to it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| You are encouraged to use the :ref:`call function <address_call_functions>` with an optionally provided maximum | ||
| amount of gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``. | ||
|
|
||
| .. _address_call_functions: | ||
|
|
||
| * ``call``, ``delegatecall`` and ``staticcall`` | ||
|
|
||
| In order to interface with contracts that do not adhere to the ABI, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.