Skip to content

Commit 2670157

Browse files
author
Yash Agrawal
committed
feat: add metadataOf in sbt
1 parent 9dac806 commit 2670157

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

contracts/SBT.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@ contract SBT is ISBT, ERC721EnumerableUpgradeable {
106106
}
107107

108108
function _tokenURI(uint256 tokenId) private view returns (string memory) {
109+
require(tokenId < currentIndex(), "Token not found");
110+
109111
(
110112
string memory name,
111113
string memory description,
112114
string memory tokenUriImage,
113115
StringAttribute[] memory stringAttributes,
114116
NumberAttribute[] memory numberAttributes
115117
) = abi.decode(
116-
_sbtdata[tokenId],
118+
metadataOf(tokenId),
117119
(string, string, string, StringAttribute[], NumberAttribute[])
118120
);
119121

@@ -230,6 +232,13 @@ contract SBT is ISBT, ERC721EnumerableUpgradeable {
230232
return super.totalSupply();
231233
}
232234

235+
function metadataOf(
236+
uint256 tokenId
237+
) public view override returns (bytes memory) {
238+
require(tokenId < currentIndex(), "Token not found");
239+
return _sbtdata[tokenId];
240+
}
241+
233242
function owner() external view returns (address) {
234243
return ProxyAdmin(_proxyAdmin).owner();
235244
}

contracts/interfaces/ISBT.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,11 @@ interface ISBT {
111111
* @return uint256 current token id
112112
*/
113113
function currentIndex() external view returns (uint256);
114+
115+
/*
116+
* @dev get mapped metadata bytes of token id
117+
* @param tokenId the token id of the NFT
118+
* @return bytes The mapped metadata bytes
119+
*/
120+
function metadataOf(uint256 tokenId) external view returns (bytes memory);
114121
}

0 commit comments

Comments
 (0)