Skip to content

Commit f1db309

Browse files
authored
Remove deprecated functions and contracts (#2125)
* Remove ERC721.burn(owner, tokenId) * Remove ERC721._checkOnERC721Received from the contract's API * Fix linter error * Remove Escrow and PullPayment withdrawWithGas, replace for withdraw * Add changelog entry * Add reentrancy notice
1 parent c173392 commit f1db309

File tree

8 files changed

+22
-123
lines changed

8 files changed

+22
-123
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* `AccessControl`: new contract for managing permissions in a system, replacement for `Ownable` and `Roles`. ([#2112](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2112))
77

88
### Breaking changes
9+
* `ERC721`: `burn(owner, tokenId)` was removed, use `burn(owner)` instead. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
10+
* `ERC721`: `_checkOnERC721Received` was removed. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
11+
* `PullPayment`, `Escrow`: `withdrawWithGas` was removed. The old `withdraw` function now forwards all gas. ([#2125](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2125))
912
* `Roles` was removed, use `AccessControl` as a replacement. ([#2112](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2112))
1013
* `ECDSA`: when receiving an invalid signature, `recover` now reverts instead of returning the zero address. ([#2114](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2114))
1114
* `Pausable`: moved to the `utils` directory. ([#2122](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2122))

contracts/mocks/ERC721Mock.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ contract ERC721Mock is ERC721 {
1919
_mint(to, tokenId);
2020
}
2121

22-
function burn(address owner, uint256 tokenId) public {
23-
_burn(owner, tokenId);
24-
}
25-
2622
function burn(uint256 tokenId) public {
2723
_burn(tokenId);
2824
}

contracts/payment/PullPayment.sol

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,21 @@ contract PullPayment {
2828
}
2929

3030
/**
31-
* @dev Withdraw accumulated payments.
31+
* @dev Withdraw accumulated payments, forwarding all gas to the recipient.
3232
*
3333
* Note that _any_ account can call this function, not just the `payee`.
3434
* This means that contracts unaware of the `PullPayment` protocol can still
3535
* receive funds this way, by having a separate account call
3636
* {withdrawPayments}.
3737
*
38-
* NOTE: This function has been deprecated, use {withdrawPaymentsWithGas}
39-
* instead. Calling contracts with fixed gas limits is an anti-pattern and
40-
* may break contract interactions in network upgrades (hardforks).
41-
* https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more.]
42-
*
43-
* @param payee Whose payments will be withdrawn.
44-
*/
45-
function withdrawPayments(address payable payee) public virtual {
46-
_escrow.withdraw(payee);
47-
}
48-
49-
/**
50-
* @dev Same as {withdrawPayments}, but forwarding all gas to the recipient.
51-
*
5238
* WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.
5339
* Make sure you trust the recipient, or are either following the
5440
* checks-effects-interactions pattern or using {ReentrancyGuard}.
5541
*
56-
* _Available since v2.4.0._
42+
* @param payee Whose payments will be withdrawn.
5743
*/
58-
function withdrawPaymentsWithGas(address payable payee) external virtual {
59-
_escrow.withdrawWithGas(payee);
44+
function withdrawPayments(address payable payee) public virtual {
45+
_escrow.withdraw(payee);
6046
}
6147

6248
/**

contracts/payment/README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
= Payment
22

3-
NOTE: This page is incomplete. We're working to improve it for the next release. Stay tuned!
3+
Utilities related to sending and receiving payments. Examples are {PullPayment}, which implements the best security practices when sending funds to third parties, and {PaymentSplitter} to receive incoming payments among a number of beneficiaries.
4+
5+
TIP: When transferring funds to and from untrusted third parties, there is always a security risk of reentrancy. If you would like to learn more about this and ways to protect against it, check out our blog post https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
46

57
== Utilities
68

contracts/payment/escrow/Escrow.sol

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,16 @@ contract Escrow is Ownable {
4242
}
4343

4444
/**
45-
* @dev Withdraw accumulated balance for a payee, forwarding 2300 gas (a
46-
* Solidity `transfer`).
47-
*
48-
* NOTE: This function has been deprecated, use {withdrawWithGas} instead.
49-
* Calling contracts with fixed-gas limits is an anti-pattern and may break
50-
* contract interactions in network upgrades (hardforks).
51-
* https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more.]
52-
*
53-
* @param payee The address whose funds will be withdrawn and transferred to.
54-
*/
55-
function withdraw(address payable payee) public virtual onlyOwner {
56-
uint256 payment = _deposits[payee];
57-
58-
_deposits[payee] = 0;
59-
60-
payee.transfer(payment);
61-
62-
emit Withdrawn(payee, payment);
63-
}
64-
65-
/**
66-
* @dev Same as {withdraw}, but forwarding all gas to the recipient.
45+
* @dev Withdraw accumulated balance for a payee, forwarding all gas to the
46+
* recipient.
6747
*
6848
* WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.
6949
* Make sure you trust the recipient, or are either following the
7050
* checks-effects-interactions pattern or using {ReentrancyGuard}.
7151
*
72-
* _Available since v2.4.0._
52+
* @param payee The address whose funds will be withdrawn and transferred to.
7353
*/
74-
function withdrawWithGas(address payable payee) public virtual onlyOwner {
54+
function withdraw(address payable payee) public virtual onlyOwner {
7555
uint256 payment = _deposits[payee];
7656

7757
_deposits[payee] = 0;

contracts/token/ERC721/ERC721.sol

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,10 @@ contract ERC721 is Context, ERC165, IERC721 {
269269
/**
270270
* @dev Internal function to burn a specific token.
271271
* Reverts if the token does not exist.
272-
* Deprecated, use {_burn} instead.
273-
* @param owner owner of the token to burn
274272
* @param tokenId uint256 ID of the token being burned
275273
*/
276-
function _burn(address owner, uint256 tokenId) internal virtual {
277-
require(ownerOf(tokenId) == owner, "ERC721: burn of token that is not own");
274+
function _burn(uint256 tokenId) internal virtual {
275+
address owner = ownerOf(tokenId);
278276

279277
_beforeTokenTransfer(owner, address(0), tokenId);
280278

@@ -287,15 +285,6 @@ contract ERC721 is Context, ERC165, IERC721 {
287285
emit Transfer(owner, address(0), tokenId);
288286
}
289287

290-
/**
291-
* @dev Internal function to burn a specific token.
292-
* Reverts if the token does not exist.
293-
* @param tokenId uint256 ID of the token being burned
294-
*/
295-
function _burn(uint256 tokenId) internal virtual {
296-
_burn(ownerOf(tokenId), tokenId);
297-
}
298-
299288
/**
300289
* @dev Internal function to transfer ownership of a given token ID to another address.
301290
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
@@ -324,15 +313,14 @@ contract ERC721 is Context, ERC165, IERC721 {
324313
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
325314
* The call is not executed if the target address is not a contract.
326315
*
327-
* This is an internal detail of the `ERC721` contract and its use is deprecated.
328316
* @param from address representing the previous owner of the given token ID
329317
* @param to target address that will receive the tokens
330318
* @param tokenId uint256 ID of the token to be transferred
331319
* @param _data bytes optional data to send along with the call
332320
* @return bool whether the call correctly returned the expected magic value
333321
*/
334322
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
335-
internal virtual returns (bool)
323+
private returns (bool)
336324
{
337325
if (!to.isContract()) {
338326
return true;

test/payment/PullPayment.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,4 @@ describe('PullPayment', function () {
4646
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
4747
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
4848
});
49-
50-
it('can withdraw payment forwarding all gas', async function () {
51-
const balanceTracker = await balance.tracker(payee1);
52-
53-
await this.contract.callTransfer(payee1, amount, { from: payer });
54-
expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
55-
56-
await this.contract.withdrawPaymentsWithGas(payee1);
57-
58-
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
59-
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
60-
});
6149
});

test/token/ERC721/ERC721.test.js

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
99
const ERC721Mock = contract.fromArtifact('ERC721Mock');
1010

1111
describe('ERC721', function () {
12-
const [ owner, other ] = accounts;
12+
const [ owner ] = accounts;
1313

1414
beforeEach(async function () {
1515
this.token = await ERC721Mock.new();
@@ -47,54 +47,10 @@ describe('ERC721', function () {
4747
});
4848
});
4949

50-
describe('_burn(address, uint256)', function () {
50+
describe('_burn', function () {
5151
it('reverts when burning a non-existent token id', async function () {
5252
await expectRevert(
53-
this.token.methods['burn(address,uint256)'](owner, tokenId), 'ERC721: owner query for nonexistent token'
54-
);
55-
});
56-
57-
context('with minted token', function () {
58-
beforeEach(async function () {
59-
await this.token.mint(owner, tokenId);
60-
});
61-
62-
it('reverts when the account is not the owner', async function () {
63-
await expectRevert(
64-
this.token.methods['burn(address,uint256)'](other, tokenId), 'ERC721: burn of token that is not own'
65-
);
66-
});
67-
68-
context('with burnt token', function () {
69-
beforeEach(async function () {
70-
({ logs: this.logs } = await this.token.methods['burn(address,uint256)'](owner, tokenId));
71-
});
72-
73-
it('emits a Transfer event', function () {
74-
expectEvent.inLogs(this.logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, tokenId });
75-
});
76-
77-
it('deletes the token', async function () {
78-
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal('0');
79-
await expectRevert(
80-
this.token.ownerOf(tokenId), 'ERC721: owner query for nonexistent token'
81-
);
82-
});
83-
84-
it('reverts when burning a token id that has been deleted', async function () {
85-
await expectRevert(
86-
this.token.methods['burn(address,uint256)'](owner, tokenId),
87-
'ERC721: owner query for nonexistent token'
88-
);
89-
});
90-
});
91-
});
92-
});
93-
94-
describe('_burn(uint256)', function () {
95-
it('reverts when burning a non-existent token id', async function () {
96-
await expectRevert(
97-
this.token.methods['burn(uint256)'](tokenId), 'ERC721: owner query for nonexistent token'
53+
this.token.burn(tokenId), 'ERC721: owner query for nonexistent token'
9854
);
9955
});
10056

@@ -105,7 +61,7 @@ describe('ERC721', function () {
10561

10662
context('with burnt token', function () {
10763
beforeEach(async function () {
108-
({ logs: this.logs } = await this.token.methods['burn(uint256)'](tokenId));
64+
({ logs: this.logs } = await this.token.burn(tokenId));
10965
});
11066

11167
it('emits a Transfer event', function () {
@@ -121,7 +77,7 @@ describe('ERC721', function () {
12177

12278
it('reverts when burning a token id that has been deleted', async function () {
12379
await expectRevert(
124-
this.token.methods['burn(uint256)'](tokenId), 'ERC721: owner query for nonexistent token'
80+
this.token.burn(tokenId), 'ERC721: owner query for nonexistent token'
12581
);
12682
});
12783
});

0 commit comments

Comments
 (0)