@@ -4,27 +4,25 @@ pragma solidity ^0.7.6;
4
4
5
5
import "@openzeppelin/contracts/token/ERC721/ERC721.sol " ;
6
6
import "@openzeppelin/contracts/utils/Address.sol " ;
7
- import "@openzeppelin/contracts/utils/Strings.sol " ;
8
7
9
8
import "../governance/Governed.sol " ;
9
+ import "../libraries/HexStrings.sol " ;
10
10
import "./ISubgraphNFT.sol " ;
11
11
import "./ISubgraphNFTDescriptor.sol " ;
12
12
13
13
/// @title NFT that represents ownership of a Subgraph
14
14
contract SubgraphNFT is Governed , ERC721 , ISubgraphNFT {
15
- using Strings for uint256 ;
16
-
17
15
// -- State --
18
16
19
17
address public minter;
20
18
ISubgraphNFTDescriptor public tokenDescriptor;
21
- mapping (uint256 => string ) private _subgraphURIs ;
19
+ mapping (uint256 => bytes32 ) private _subgraphMetadataHashes ;
22
20
23
21
// -- Events --
24
22
25
23
event MinterUpdated (address minter );
26
24
event TokenDescriptorUpdated (address tokenDescriptor );
27
- event SubgraphURIUpdated (uint256 indexed tokenID , string subgraphURI );
25
+ event SubgraphMetadataUpdated (uint256 indexed tokenID , bytes32 subgraphURI );
28
26
29
27
// -- Modifiers --
30
28
@@ -111,18 +109,19 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
111
109
}
112
110
113
111
/**
114
- * @notice Set the URI for a subgraph represented by `_tokenId`.
112
+ * @notice Set the metadata for a subgraph represented by `_tokenId`.
115
113
* @dev `_tokenId` must exist.
116
114
* @param _tokenId ID of the NFT
115
+ * @param _subgraphMetadata IPFS hash for the metadata
117
116
*/
118
- function setSubgraphURI (uint256 _tokenId , string memory _subgraphURI )
117
+ function setSubgraphMetadata (uint256 _tokenId , bytes32 _subgraphMetadata )
119
118
external
120
119
override
121
120
onlyMinter
122
121
{
123
122
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 );
126
125
}
127
126
128
127
// -- NFT display --
@@ -137,13 +136,21 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
137
136
require (_exists (_tokenId), "ERC721Metadata: URI query for nonexistent token " );
138
137
139
138
// 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
141
140
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
+ );
143
148
}
144
149
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) : "" ;
147
154
string memory base = baseURI ();
148
155
149
156
// If there is no base URI, return the token URI.
@@ -155,6 +162,6 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
155
162
return string (abi.encodePacked (base, _subgraphURI));
156
163
}
157
164
// 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 )));
159
166
}
160
167
}
0 commit comments