Skip to content

Commit dfa1f6e

Browse files
author
Adrien Hamelin
authored
Clarify event and comments (#14)
1 parent 393b5ef commit dfa1f6e

8 files changed

+21
-21
lines changed

contracts/mocks/ERC721RentAgreementMock.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contract ERC721RentAgreementMock is IERC721RentalAgreement {
88
bool private _fail;
99

1010
// Interface
11-
function afterRentalAgreementReplaced(uint256) external view override {
11+
function afterAgreementRemoved(uint256) external view override {
1212
require(!_fail, "Failed from agreement contract");
1313
}
1414

contracts/token/ERC721/ERC721.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Rental, IERC721Metadata {
203203
_rentalAgreements[tokenId] = agreement;
204204

205205
if (address(currentAgreement) != address(0)) {
206-
currentAgreement.afterRentalAgreementReplaced(tokenId);
206+
currentAgreement.afterAgreementRemoved(tokenId);
207207
}
208208
}
209209

@@ -411,7 +411,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Rental, IERC721Metadata {
411411
delete _rentalAgreements[tokenId];
412412

413413
if (address(rentAgreement) != address(0)) {
414-
rentAgreement.afterRentalAgreementReplaced(tokenId);
414+
rentAgreement.afterAgreementRemoved(tokenId);
415415
}
416416

417417
emit Transfer(from, to, tokenId);

contracts/token/ERC721/ERC721BundleRentalAgreement.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ contract ERC721BundleRentalAgreement is IERC721RentalAgreement, ERC165 {
4141
}
4242

4343
/// @inheritdoc IERC721RentalAgreement
44-
function afterRentalAgreementReplaced(uint256 tokenId) external view virtual override {
44+
function afterAgreementRemoved(uint256 tokenId) external view virtual override {
4545
// We don't need to check if a rental is in progress because the IERC721Rental does that for us
4646
// We don't allow to change the contract if funds remain, because we don't store the owner
4747
require(

contracts/token/ERC721/ERC721SingleRentalAgreement.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ contract ERC721SingleRentalAgreement is Context, IERC721RentalAgreement, ERC165
7777
}
7878

7979
/// @inheritdoc IERC721RentalAgreement
80-
function afterRentalAgreementReplaced(uint256) public view override onlyErc721Contract {
80+
function afterAgreementRemoved(uint256) public view override onlyErc721Contract {
8181
require(
8282
rentalStatus == RentalStatus.pending,
8383
"ERC721SingleRentalAgreement: rental agreement has to be pending to be updated."

contracts/token/ERC721/ERC721SwapRentalAgreement.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ contract ERC721SwapRentalAgreement is Context, IERC721RentalAgreement, ERC165 {
7070
}
7171

7272
/// @inheritdoc IERC721RentalAgreement
73-
function afterRentalAgreementReplaced(uint256) public view override onlyErc721Contracts {
73+
function afterAgreementRemoved(uint256) public view override onlyErc721Contracts {
7474
require(
7575
rentalAgreement.rentalStatus == RentalStatus.pending,
7676
"ERC721SwapRentalAgreement: rental agreement already active"

contracts/token/ERC721/extensions/IERC721Rental.sol

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import "../../../utils/introspection/IERC165.sol";
99
/// Defines the interface that a rental agreement contract should support to be used by
1010
/// `IERC721Rental`.
1111
interface IERC721RentalAgreement is IERC165 {
12-
/// Function called at the end of `IERC721Rental.setRentalAgreement` to replace an
13-
/// existing rental agreement contract of a token.
12+
/// Function called at the end of `IERC721Rental.setRentalAgreement` on the agreement
13+
/// currently set for the token, if one exists.
1414
///
1515
/// @dev Allows the agreement to cancel the change by reverting if it deems it
1616
/// necessary. The `IERC721Rental` is calling this function, so all information needed
17-
/// can be queried through the `msg.sender`. This event is not called if a rental agreement
18-
/// is not in progress.
19-
function afterRentalAgreementReplaced(uint256 tokenId) external;
17+
/// can be queried through the `msg.sender`. This event is only called when the token
18+
/// is not rented, as it is not allowed to change an agreement during a rental.
19+
function afterAgreementRemoved(uint256 tokenId) external;
2020

2121
/// Function called at the end of `IERC721Rental.acceptRentalAgreement`.
2222
///
@@ -52,13 +52,13 @@ interface IERC721RentalAgreement is IERC165 {
5252
interface IERC721Rental is IERC721 {
5353
/// Set the rental agreement contract for a specific token.
5454
///
55-
/// A previously set rental agreement contract must accept its replacement.
56-
/// The caller must be the owner or their approver or operator.
55+
/// A previously set rental agreement contract must accept the change.
56+
/// The caller must be the owner (not the renter) or their approver or operator.
5757
/// The token must not be currently rented.
5858
/// The agreement is removed upon token transfer.
5959
///
60-
/// @dev If an agreement was set, calls its
61-
/// `IERC721RentalAgreement.afterRentalAgreementReplaced` at the end of the call.
60+
/// @dev If an agreement was already set before this call, calls its
61+
/// `IERC721RentalAgreement.afterAgreementRemoved` at the end of the call.
6262
///
6363
/// @param agreement The agreement. Set to 0 to remove the current agreement.
6464
function setRentalAgreement(IERC721RentalAgreement agreement, uint256 tokenId) external;
@@ -87,7 +87,7 @@ interface IERC721Rental is IERC721 {
8787
/// @dev Calls `IERC721RentalAgreement.afterRentalStopped` at the end of the call.
8888
function stopRentalAgreement(uint256 tokenId) external;
8989

90-
/// @return The address of the rented token owner, or 0 is there is no rental in
91-
/// progress.
90+
/// @return The address of the asset owner and not the renter, or 0 if there is no
91+
/// rental in progress.
9292
function rentedOwnerOf(uint256 tokenId) external view returns (address);
9393
}

test/token/ERC721/ERC721BundleRentAgreement.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract('ERC721BundleRentalAgreement', function (accounts) {
3838
it('cannot call IERC721RentalAgreement to modify state', async function () {
3939
expect(
4040
ERC721BundleRentalAgreement.abi.find(
41-
(abi) => abi.name === 'afterRentalAgreementReplaced',
41+
(abi) => abi.name === 'afterAgreementRemoved',
4242
).constant,
4343
).to.equal(true);
4444
expect(

test/token/ERC721/ERC721SingleRentalAgreement.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ contract('ERC721SingleRentalAgreement', function (accounts) {
5353

5454
it('Only erc721 contract can update state', async function () {
5555
await expectRevert(
56-
this.erc721SingleRentalAgreement.afterRentalAgreementReplaced(this.tokenId, { from: this.renter }),
56+
this.erc721SingleRentalAgreement.afterAgreementRemoved(this.tokenId, { from: this.renter }),
5757
'ERC721SingleRentalAgreement: only erc721Contract contract can modify rental agreement state',
5858
);
5959
});
6060

6161
it('Enable to change agreement when status is pending', async function () {
62-
await this.erc721SingleRentalAgreement.afterRentalAgreementReplaced(this.tokenId, { from: this.erc721.address });
62+
await this.erc721SingleRentalAgreement.afterAgreementRemoved(this.tokenId, { from: this.erc721.address });
6363
});
6464
});
6565

@@ -94,7 +94,7 @@ contract('ERC721SingleRentalAgreement', function (accounts) {
9494
// Pay rent.
9595
await this.erc721SingleRentalAgreement.payAndStartRent({ from: this.renter, value: this.rentalFees });
9696
await expectRevert(
97-
this.erc721SingleRentalAgreement.afterRentalAgreementReplaced(this.tokenId, { from: this.erc721.address }),
97+
this.erc721SingleRentalAgreement.afterAgreementRemoved(this.tokenId, { from: this.erc721.address }),
9898
'ERC721SingleRentalAgreement: rental agreement has to be pending to be updated',
9999
);
100100
});

0 commit comments

Comments
 (0)