@@ -17,33 +17,17 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
17
17
/// @dev Account with proxy adming rights.
18
18
address private _proxyAdmin;
19
19
20
- /// @dev Holds the generic metadata and attribute information of a SBT token.
21
- mapping (uint256 => SBTData ) private _sbtdata;
20
+ /// @dev Holds the encoded metadata of a SBT token.
21
+ mapping (uint256 => bytes ) private _sbtdata;
22
22
23
23
modifier onlyMinter () {
24
24
require (_minter == _msgSender (), "Illegal access " );
25
25
_;
26
26
}
27
27
28
- function _setTokenURI (
29
- uint256 tokenId ,
30
- string memory name ,
31
- string memory description ,
32
- StringAttribute[] memory stringAttributes ,
33
- NumberAttribute[] memory numberAttributes ,
34
- string memory tokenUriImage
35
- ) private {
36
- bytes memory stringAttributesEncoded = abi.encode (stringAttributes);
37
- bytes memory numberAttributesEncoded = abi.encode (numberAttributes);
38
- SBTData memory sbtData = SBTData ({
39
- name: name,
40
- image: tokenUriImage,
41
- description: description,
42
- stringAttributesEncoded: stringAttributesEncoded,
43
- numberAttributesEncoded: numberAttributesEncoded
44
- });
45
- _sbtdata[tokenId] = sbtData;
46
- emit SetSBTTokenURI (tokenId, abi.encode (sbtData, tokenUriImage));
28
+ function _setTokenURI (uint256 tokenId , bytes memory metadata ) private {
29
+ _sbtdata[tokenId] = metadata;
30
+ emit SetSBTTokenURI (tokenId, metadata);
47
31
}
48
32
49
33
function _beforeTokenTransfer (
@@ -80,57 +64,34 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
80
64
81
65
function setTokenURI (
82
66
uint256 tokenId ,
83
- string memory name ,
84
- string memory description ,
85
- StringAttribute[] memory stringAttributes ,
86
- NumberAttribute[] memory numberAttributes ,
87
- string memory tokenUriImage
67
+ bytes memory metadata
88
68
) external override onlyMinter {
89
69
require (tokenId < currentIndex (), "Token not found " );
90
- _setTokenURI (
91
- tokenId,
92
- name,
93
- description,
94
- stringAttributes,
95
- numberAttributes,
96
- tokenUriImage
97
- );
70
+ _setTokenURI (tokenId, metadata);
98
71
}
99
72
100
73
function mint (
101
74
address to ,
102
- string memory name ,
103
- string memory description ,
104
- StringAttribute[] memory stringAttributes ,
105
- NumberAttribute[] memory numberAttributes ,
106
- string memory tokenUriImage
75
+ bytes memory metadata
107
76
) external override onlyMinter returns (uint256 tokenId_ ) {
108
77
uint256 currentId = currentIndex ();
109
78
_mint (to, currentId);
110
79
emit Minted (currentId, to);
111
- _setTokenURI (
112
- currentId,
113
- name,
114
- description,
115
- stringAttributes,
116
- numberAttributes,
117
- tokenUriImage
118
- );
80
+ _setTokenURI (currentId, metadata);
119
81
return currentId;
120
82
}
121
83
122
84
function _tokenURI (uint256 tokenId ) private view returns (string memory ) {
123
- SBTData memory sbtData = _sbtdata[tokenId];
124
-
125
- StringAttribute[] memory stringAttributes = abi.decode (
126
- sbtData.stringAttributesEncoded,
127
- (StringAttribute[])
128
- );
129
-
130
- NumberAttribute[] memory numberAttributes = abi.decode (
131
- sbtData.numberAttributesEncoded,
132
- (NumberAttribute[])
133
- );
85
+ (
86
+ string memory name ,
87
+ string memory description ,
88
+ string memory tokenUriImage ,
89
+ StringAttribute[] memory stringAttributes ,
90
+ NumberAttribute[] memory numberAttributes
91
+ ) = abi.decode (
92
+ _sbtdata[tokenId],
93
+ (string , string , string , StringAttribute[], NumberAttribute[])
94
+ );
134
95
135
96
bool isStringDataPresent = false ;
136
97
string memory sbtAttributes = "" ;
@@ -201,13 +162,13 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
201
162
.encodePacked (
202
163
// solhint-disable-next-line quotes
203
164
'{"name":" ' ,
204
- sbtData. name,
165
+ name,
205
166
// solhint-disable-next-line quotes
206
167
'", "description":" ' ,
207
- sbtData. description,
168
+ description,
208
169
// solhint-disable-next-line quotes
209
170
'", "image": " ' ,
210
- sbtData.image ,
171
+ tokenUriImage ,
211
172
// solhint-disable-next-line quotes
212
173
'", "attributes": ' ,
213
174
sbtAttributes,
0 commit comments