Skip to content

Commit 481d1d1

Browse files
committed
Add a very simple ClustersNFTBaseURIRenderer
1 parent 705bbe9 commit 481d1d1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/ClustersNFTBaseURIRenderer.sol

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.23;
3+
4+
import {LibString} from "solady/utils/LibString.sol";
5+
import {Ownable} from "solady/auth/Ownable.sol";
6+
7+
/// @title ClustersNFTBaseURIRenderer
8+
/// @dev A very simple contract to return the token URI for the Clusters NFT,
9+
/// using a base URI and the token ID.
10+
contract ClustersNFTBaseURIRenderer is Ownable {
11+
using LibString for LibString.StringStorage;
12+
13+
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
14+
/* STORAGE */
15+
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
16+
17+
LibString.StringStorage internal _baseURI;
18+
19+
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
20+
/* EVENTS */
21+
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
22+
23+
/// @dev The base URI is updated.
24+
event BaseURISet(string baseURI);
25+
26+
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
27+
/* CONSTRUCTOR */
28+
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
29+
30+
constructor() {
31+
_initializeOwner(tx.origin);
32+
}
33+
34+
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
35+
/* TOKEN URI */
36+
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
37+
38+
/// @dev Returns the token URI for the given `id`.
39+
function tokenURI(uint256 id) public view returns (string memory) {
40+
string memory baseURI = _baseURI.get();
41+
if (bytes(baseURI).length == 0) return "";
42+
return LibString.replace(baseURI, "{id}", LibString.toString(id));
43+
}
44+
45+
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
46+
/* ADMIN FUNCTIONS */
47+
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
48+
49+
/// @dev Sets the base URI for the token.
50+
function setBaseURI(string memory baseURI) public onlyOwner {
51+
_baseURI.set(baseURI);
52+
emit BaseURISet(baseURI);
53+
}
54+
}

0 commit comments

Comments
 (0)