Skip to content

Commit 8eb5786

Browse files
author
Yash Agrawal
committed
feat: update the structure of SBTData
1 parent ac525c1 commit 8eb5786

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

contracts/SBTToken.sol

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
2121
/// @dev Account with proxy adming rights.
2222
address private _proxyAdmin;
2323

24-
/// @dev Holds the URI information of a SBT token.
25-
mapping(uint256 => string) private _tokenUriImage;
2624
/// @dev Holds the generic metadata and attribute information of a SBT token.
27-
mapping(uint256 => Metadata) private _tokenMetadata;
25+
mapping(uint256 => SBTData) private _sbtdata;
2826

2927
modifier onlyMinter() {
3028
require(_minter == _msgSender(), "Illegal access");
@@ -33,12 +31,23 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
3331

3432
function _setTokenURI(
3533
uint256 tokenId,
36-
Metadata memory tokenMetadata,
34+
string memory name,
35+
string memory description,
36+
StringAttribute[] memory stringAttributes,
37+
NumberAttribute[] memory numberAttributes,
3738
string memory tokenUriImage
3839
) private {
39-
_tokenMetadata[tokenId] = tokenMetadata;
40-
_tokenUriImage[tokenId] = tokenUriImage;
41-
emit SetSBTTokenURI(tokenId, abi.encode(tokenMetadata, tokenUriImage));
40+
bytes memory stringAttributesEncoded = abi.encode(stringAttributes);
41+
bytes memory numberAttributesEncoded = abi.encode(numberAttributes);
42+
SBTData memory sbtData = SBTData({
43+
name: name,
44+
image: tokenUriImage,
45+
description: description,
46+
stringAttributesEncoded: stringAttributesEncoded,
47+
numberAttributesEncoded: numberAttributesEncoded
48+
});
49+
_sbtdata[tokenId] = sbtData;
50+
emit SetSBTTokenURI(tokenId, abi.encode(sbtData, tokenUriImage));
4251
}
4352

4453
function _beforeTokenTransfer(
@@ -75,27 +84,47 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
7584

7685
function setTokenURI(
7786
uint256 tokenId,
78-
Metadata memory tokenMetadata,
87+
string memory name,
88+
string memory description,
89+
StringAttribute[] memory stringAttributes,
90+
NumberAttribute[] memory numberAttributes,
7991
string memory tokenUriImage
8092
) external override onlyMinter {
8193
require(tokenId < currentIndex(), "Token not found");
82-
_setTokenURI(tokenId, tokenMetadata, tokenUriImage);
94+
_setTokenURI(
95+
tokenId,
96+
name,
97+
description,
98+
stringAttributes,
99+
numberAttributes,
100+
tokenUriImage
101+
);
83102
}
84103

85104
function mint(
86105
address to,
87-
Metadata memory tokenMetadata,
106+
string memory name,
107+
string memory description,
108+
StringAttribute[] memory stringAttributes,
109+
NumberAttribute[] memory numberAttributes,
88110
string memory tokenUriImage
89111
) external override onlyMinter returns (uint256 tokenId_) {
90112
uint256 currentId = currentIndex();
91113
_mint(to, currentId);
92114
emit Minted(currentId, to);
93-
_setTokenURI(currentId, tokenMetadata, tokenUriImage);
115+
_setTokenURI(
116+
currentId,
117+
name,
118+
description,
119+
stringAttributes,
120+
numberAttributes,
121+
tokenUriImage
122+
);
94123
return currentId;
95124
}
96125

97126
function _tokenURI(uint256 tokenId) private view returns (string memory) {
98-
return _tokenUriImage[tokenId];
127+
return string(bytes(abi.encode(_sbtdata[tokenId])));
99128
}
100129

101130
function tokenURI(

contracts/interfaces/ISBTToken.sol

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ interface ISBTToken {
1616
}
1717

1818
/// @dev Data strucutre to represent all generic metadata of the SBT.
19-
struct Metadata {
19+
struct SBTData {
2020
string name;
2121
string image;
2222
string description;
23-
bytes stringAttributes;
24-
bytes NumberAttributes;
23+
bytes stringAttributesEncoded;
24+
bytes numberAttributesEncoded;
2525
}
2626

2727
/*
@@ -53,7 +53,10 @@ interface ISBTToken {
5353
*/
5454
function mint(
5555
address _owner,
56-
Metadata memory metadata,
56+
string memory name,
57+
string memory description,
58+
StringAttribute[] memory stringAttributes,
59+
NumberAttribute[] memory numberAttributes,
5760
string memory tokenURIImage
5861
) external returns (uint256);
5962

@@ -68,7 +71,10 @@ interface ISBTToken {
6871
*/
6972
function setTokenURI(
7073
uint256 _tokenId,
71-
Metadata memory metadata,
74+
string memory name,
75+
string memory description,
76+
StringAttribute[] memory stringAttributes,
77+
NumberAttribute[] memory numberAttributes,
7278
string memory tokenURIImage
7379
) external;
7480

0 commit comments

Comments
 (0)