Skip to content

Commit 161f3d6

Browse files
author
Oren Sokolowsky
committed
NFTManager
1 parent 630b932 commit 161f3d6

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

contracts/misc/NFTManager.sol

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
pragma solidity ^0.5.17;
1+
pragma solidity ^0.6.10;
22

3-
import "@openzeppelin/upgrades/contracts/Initializable.sol";
43
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721.sol";
54
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721Receiver.sol";
6-
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
5+
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
76

8-
contract NFTManager is Initializable, Ownable, IERC721Receiver {
7+
8+
contract NFTManager is Initializable, OwnableUpgradeSafe, IERC721Receiver {
99
event SendNFT(address indexed recipient, IERC721 indexed nftContract, uint256 tokenId);
1010

11-
function initialize() public initializer {
12-
Ownable.initialize(msg.sender);
11+
function initialize(address _owner) external initializer {
12+
__Ownable_init_unchained();
13+
transferOwnership(_owner);
1314
}
1415

1516
/// @notice Safe Transfer specified NFT to a given recipient, with arbitrary extra data
@@ -34,7 +35,8 @@ contract NFTManager is Initializable, Ownable, IERC721Receiver {
3435
/**
3536
* @notice Handle the receipt of an NFT
3637
* @dev The ERC721 smart contract calls this function on the recipient
37-
* @dev The NFTManager uses this to notify other contracts that it accepts NFTs, and does not have any extra functionality on this hook.
38+
* @dev The NFTManager uses this to notify other contracts that it accepts NFTs,
39+
* and does not have any extra functionality on this hook.
3840
* after a {IERC721-safeTransferFrom}. This function MUST return the function selector,
3941
* otherwise the caller will revert the transaction. The selector to be
4042
* returned can be obtained as `this.onERC721Received.selector`. This
@@ -43,8 +45,8 @@ contract NFTManager is Initializable, Ownable, IERC721Receiver {
4345
* @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
4446
*/
4547
function onERC721Received(address, address, uint256, bytes memory)
46-
public returns (bytes4)
48+
public override returns (bytes4)
4749
{
4850
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
4951
}
50-
}
52+
}

contracts/test/ERC721Mock.sol

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
pragma solidity ^0.5.17;
1+
pragma solidity ^0.6.10;
22

3-
import "@openzeppelin/upgrades/contracts/Initializable.sol";
4-
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721Mintable.sol";
3+
import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
4+
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721.sol";
55

6-
contract ERC721Mock is Initializable, ERC721Mintable {
7-
function __ERC721Mock_initialize() public initializer {
8-
ERC721.initialize();
9-
ERC721Mintable.initialize(msg.sender);
6+
7+
8+
contract ERC721Mock is Initializable, ERC721UpgradeSafe, OwnableUpgradeSafe {
9+
10+
function initialize(address _owner) public initializer {
11+
__ERC721_init_unchained("ERC721Mock", "721");
12+
__Ownable_init_unchained();
13+
transferOwnership(_owner);
14+
}
15+
16+
function mint(address _to, uint256 _tokenId) public onlyOwner returns (bool) {
17+
_mint(_to, _tokenId);
18+
return true;
1019
}
11-
}
20+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
pragma solidity ^0.5.17;
1+
pragma solidity ^0.6.10;
22

33
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721Receiver.sol";
44

55
contract IERC721NonReceiverMock is IERC721Receiver {
66
function onERC721Received(address, address, uint256, bytes memory)
7-
public returns (bytes4)
7+
public override returns (bytes4)
88
{
99
return bytes4(keccak256("Don't Receive ERC721"));
1010
}
11-
}
11+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
pragma solidity ^0.5.17;
1+
pragma solidity ^0.6.10;
22

33
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721Receiver.sol";
44

55
contract IERC721ReceiverMock is IERC721Receiver {
66
function onERC721Received(address, address, uint256, bytes memory)
7-
public returns (bytes4)
7+
public override returns (bytes4)
88
{
99
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
1010
}
11-
}
11+
}

test/nftmanager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ const assertEventParams = (event, params, expectedParams) => {
184184

185185
const setupNFT = async (owner, nftMinter, nftSender) => {
186186
const nftMock = await ERC721Mock.new({ from: nftMinter });
187-
await nftMock.__ERC721Mock_initialize({ from: nftMinter });
187+
await nftMock.initialize(nftMinter ,{ from: nftMinter });
188188

189189
const nftManager = await NFTManager.new({ from: owner });
190-
await nftManager.initialize({ from: owner });
190+
await nftManager.initialize(owner, { from: owner });
191191

192192
await nftMock.mint(nftManager.address, 0, { from: nftMinter });
193193
await nftMock.mint(nftSender, 1, { from: nftMinter });

0 commit comments

Comments
 (0)