@@ -4,27 +4,25 @@ pragma solidity ^0.7.6;
44
55import "@openzeppelin/contracts/token/ERC721/ERC721.sol " ;
66import "@openzeppelin/contracts/utils/Address.sol " ;
7- import "@openzeppelin/contracts/utils/Strings.sol " ;
87
98import "../governance/Governed.sol " ;
9+ import "../libraries/HexStrings.sol " ;
1010import "./ISubgraphNFT.sol " ;
1111import "./ISubgraphNFTDescriptor.sol " ;
1212
1313/// @title NFT that represents ownership of a Subgraph
1414contract SubgraphNFT is Governed , ERC721 , ISubgraphNFT {
15- using Strings for uint256 ;
16-
1715 // -- State --
1816
1917 address public minter;
2018 ISubgraphNFTDescriptor public tokenDescriptor;
21- mapping (uint256 => string ) private _subgraphURIs ;
19+ mapping (uint256 => bytes32 ) private _subgraphMetadataHashes ;
2220
2321 // -- Events --
2422
2523 event MinterUpdated (address minter );
2624 event TokenDescriptorUpdated (address tokenDescriptor );
27- event SubgraphURIUpdated (uint256 indexed tokenID , string subgraphURI );
25+ event SubgraphMetadataUpdated (uint256 indexed tokenID , bytes32 subgraphURI );
2826
2927 // -- Modifiers --
3028
@@ -111,18 +109,19 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
111109 }
112110
113111 /**
114- * @notice Set the URI for a subgraph represented by `_tokenId`.
112+ * @notice Set the metadata for a subgraph represented by `_tokenId`.
115113 * @dev `_tokenId` must exist.
116114 * @param _tokenId ID of the NFT
115+ * @param _subgraphMetadata IPFS hash for the metadata
117116 */
118- function setSubgraphURI (uint256 _tokenId , string memory _subgraphURI )
117+ function setSubgraphMetadata (uint256 _tokenId , bytes32 _subgraphMetadata )
119118 external
120119 override
121120 onlyMinter
122121 {
123122 require (_exists (_tokenId), "ERC721Metadata: URI set of nonexistent token " );
124- _subgraphURIs [_tokenId] = _subgraphURI ;
125- emit SubgraphURIUpdated (_tokenId, _subgraphURI );
123+ _subgraphMetadataHashes [_tokenId] = _subgraphMetadata ;
124+ emit SubgraphMetadataUpdated (_tokenId, _subgraphMetadata );
126125 }
127126
128127 // -- NFT display --
@@ -137,13 +136,21 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
137136 require (_exists (_tokenId), "ERC721Metadata: URI query for nonexistent token " );
138137
139138 // Delegates rendering of the metadata to the token descriptor if existing
140- // This allows for some flexibility in adapting the metadata
139+ // This allows for some flexibility in adapting the token URI
141140 if (address (tokenDescriptor) != address (0 )) {
142- return tokenDescriptor.tokenURI (minter, _tokenId, baseURI (), _subgraphURIs[_tokenId]);
141+ return
142+ tokenDescriptor.tokenURI (
143+ minter,
144+ _tokenId,
145+ baseURI (),
146+ _subgraphMetadataHashes[_tokenId]
147+ );
143148 }
144149
145- // Default metadata
146- string memory _subgraphURI = _subgraphURIs[_tokenId];
150+ // Default token URI
151+ uint256 metadata = uint256 (_subgraphMetadataHashes[_tokenId]);
152+
153+ string memory _subgraphURI = metadata > 0 ? HexStrings.toString (metadata) : "" ;
147154 string memory base = baseURI ();
148155
149156 // If there is no base URI, return the token URI.
@@ -155,6 +162,6 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
155162 return string (abi.encodePacked (base, _subgraphURI));
156163 }
157164 // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
158- return string (abi.encodePacked (base, _tokenId .toString ()));
165+ return string (abi.encodePacked (base, HexStrings .toString (_tokenId )));
159166 }
160167}
0 commit comments