Browse Source

nft nits

Change-Id: Ie6265e1fcc8d91294dc416ad6bac18327f582c1e
valentin 4 năm trước cách đây
mục cha
commit
75ac0c9153

+ 11 - 19
ethereum/contracts/nft/NFTBridge.sol

@@ -5,7 +5,6 @@ pragma solidity ^0.8.0;
 
 import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
 import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
-import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
 
 import "../libraries/external/BytesLib.sol";
 
@@ -40,7 +39,6 @@ contract NFTBridge is NFTBridgeGovernance {
         string memory nameString;
         string memory uriString;
         {
-            // decimals, symbol & token are not part of the core ERC20 token standard, so we need to support contracts that dont implement them
             (,bytes memory queriedSymbol) = token.staticcall(abi.encodeWithSignature("symbol()"));
             (,bytes memory queriedName) = token.staticcall(abi.encodeWithSignature("name()"));
             (,bytes memory queriedURI) = token.staticcall(abi.encodeWithSignature("tokenURI(uint256)", tokenID));
@@ -53,37 +51,34 @@ contract NFTBridge is NFTBridgeGovernance {
         bytes32 symbol;
         bytes32 name;
         assembly {
-        // first 32 bytes hold string length
+            // first 32 bytes hold string length
             symbol := mload(add(symbolString, 32))
             name := mload(add(nameString, 32))
         }
 
-
         if (tokenChain == chainId()) {
             IERC721(token).safeTransferFrom(msg.sender, address(this), tokenID);
         } else {
             NFTImplementation(token).burn(tokenID);
         }
 
-        sequence = logTransfer(NFTBridgeStructs.Transfer(
-            {
+        sequence = logTransfer(NFTBridgeStructs.Transfer({
             tokenAddress : tokenAddress,
-            tokenChain : tokenChain,
-            name : name,
-            symbol : symbol,
-            tokenID : tokenID,
-            uri : uriString,
-            to : recipient,
-            toChain : recipientChain
-            }
-            ), msg.value, nonce);
+            tokenChain   : tokenChain,
+            name         : name,
+            symbol       : symbol,
+            tokenID      : tokenID,
+            uri          : uriString,
+            to           : recipient,
+            toChain      : recipientChain
+        }), msg.value, nonce);
     }
 
     function logTransfer(NFTBridgeStructs.Transfer memory transfer, uint256 callValue, uint32 nonce) internal returns (uint64 sequence) {
         bytes memory encoded = encodeTransfer(transfer);
 
         sequence = wormhole().publishMessage{
-        value : callValue
+            value : callValue
         }(nonce, encoded, 15);
     }
 
@@ -248,7 +243,4 @@ contract NFTBridge is NFTBridgeGovernance {
         }
         return string(array);
     }
-
-    // we need to accept ETH sends to unwrap WETH
-    receive() external payable {}
 }

+ 1 - 13
ethereum/contracts/nft/token/NFTImplementation.sol

@@ -14,7 +14,7 @@ import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
 import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
 import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
 
-// Based on the OpenZepplin ERC20 implementation, licensed under MIT
+// Based on the OpenZepplin ERC721 implementation, licensed under MIT
 contract NFTImplementation is NFTState, Context, IERC721, IERC721Metadata, ERC165 {
     using Address for address;
     using Strings for uint256;
@@ -167,8 +167,6 @@ contract NFTImplementation is NFTState, Context, IERC721, IERC721Metadata, ERC16
         require(to != address(0), "ERC721: mint to the zero address");
         require(!_exists(tokenId), "ERC721: token already minted");
 
-        _beforeTokenTransfer(address(0), to, tokenId);
-
         _state.balances[to] += 1;
         _state.owners[tokenId] = to;
         _state.tokenURIs[tokenId] = uri;
@@ -183,8 +181,6 @@ contract NFTImplementation is NFTState, Context, IERC721, IERC721Metadata, ERC16
     function _burn(uint256 tokenId) internal {
         address owner_ = NFTImplementation.ownerOf(tokenId);
 
-        _beforeTokenTransfer(owner_, address(0), tokenId);
-
         // Clear approvals
         _approve(address(0), tokenId);
 
@@ -202,8 +198,6 @@ contract NFTImplementation is NFTState, Context, IERC721, IERC721Metadata, ERC16
         require(NFTImplementation.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
         require(to != address(0), "ERC721: transfer to the zero address");
 
-        _beforeTokenTransfer(from, to, tokenId);
-
         // Clear approvals from the previous owner
         _approve(address(0), tokenId);
 
@@ -242,12 +236,6 @@ contract NFTImplementation is NFTState, Context, IERC721, IERC721Metadata, ERC16
         }
     }
 
-    function _beforeTokenTransfer(
-        address from,
-        address to,
-        uint256 tokenId
-    ) internal {}
-
     modifier onlyOwner() {
         require(owner() == _msgSender(), "caller is not the owner");
         _;