11// SPDX-License-Identifier: Apache-2.0
22pragma solidity ^ 0.8.0 ;
33
4- import '@openzeppelin/contracts/token/ERC1155/ERC1155 .sol ' ;
4+ import '@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage .sol ' ;
55import '@openzeppelin/contracts/utils/Context.sol ' ;
6- import '@openzeppelin/contracts/utils/math/SafeMath.sol ' ;
76import './IERC1155MixedFungible.sol ' ;
87
98/**
@@ -28,7 +27,7 @@ import './IERC1155MixedFungible.sol';
2827 * Remember to always consult best practices from other communities and examples (such as OpenZeppelin)
2928 * when crafting your token logic, rather than relying on the FireFly community alone. Happy minting!
3029 */
31- contract ERC1155MixedFungible is Context , ERC1155 , IERC1155MixedFungible {
30+ contract ERC1155MixedFungible is Context , ERC1155URIStorage , IERC1155MixedFungible {
3231 // Use a split bit implementation:
3332 // - Bit 255: type flag (0 = fungible, 1 = non-fungible)
3433 // - Bits 255-128: type id
@@ -45,10 +44,6 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
4544 // inherited ERC1155 `_uri` is private, so need our own within this contract
4645 string private _baseTokenURI;
4746
48- // mapping from type ID | index => custom token URIs for non-fungible tokens
49- // fallback behavior if missing is to use the default base URI
50- mapping (uint256 => string ) private _nfTokenURIs;
51-
5247 function isFungible (uint256 id ) internal pure returns (bool ) {
5348 return id & TYPE_NF_BIT == 0 ;
5449 }
@@ -90,18 +85,6 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
9085 );
9186 }
9287
93- function _setNonFungibleURI (
94- uint256 type_id ,
95- uint256 id ,
96- string memory _uri
97- ) private creatorOnly (type_id) {
98- require (
99- isNonFungible (type_id),
100- 'ERC1155MixedFungible: id does not represent a non-fungible type '
101- );
102- _nfTokenURIs[id] = _uri;
103- }
104-
10588 function mintNonFungible (
10689 uint256 type_id ,
10790 address [] calldata to ,
@@ -114,7 +97,7 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
11497
11598 // Indexes are 1-based.
11699 uint256 index = maxIndex[type_id] + 1 ;
117- maxIndex[type_id] = SafeMath. add ( to.length , maxIndex[type_id]) ;
100+ maxIndex[type_id] = to.length + maxIndex[type_id];
118101
119102 for (uint256 i = 0 ; i < to.length ; ++ i) {
120103 _mint (to[i], type_id | (index + i), 1 , data);
@@ -134,12 +117,12 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
134117
135118 // Indexes are 1-based.
136119 uint256 index = maxIndex[type_id] + 1 ;
137- maxIndex[type_id] = SafeMath. add ( to.length , maxIndex[type_id]) ;
120+ maxIndex[type_id] = to.length + maxIndex[type_id];
138121
139122 for (uint256 i = 0 ; i < to.length ; ++ i) {
140123 uint256 id = type_id | (index + i);
141124 _mint (to[i], id, 1 , data);
142- _setNonFungibleURI (type_id, id, _uri);
125+ _setURI ( id, _uri);
143126 }
144127 }
145128
@@ -186,15 +169,22 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
186169
187170 function uri (
188171 uint256 id
189- ) public view virtual override (IERC1155MixedFungible , ERC1155 ) returns (string memory ) {
190- string memory _tokenUri = _nfTokenURIs[id];
191- bytes memory tempURITest = bytes (_tokenUri);
192-
193- if (tempURITest.length == 0 ) {
194- return _baseTokenURI;
195- } else {
196- return _tokenUri;
197- }
172+ )
173+ public
174+ view
175+ virtual
176+ override (IERC1155MixedFungible , ERC1155URIStorage )
177+ returns (string memory )
178+ {
179+ return super .uri (id);
180+ }
181+
182+ function _setURI (uint256 id , string memory tokenURI ) internal virtual override {
183+ require (
184+ isNonFungible (id),
185+ 'ERC1155MixedFungible: id does not represent a non-fungible type '
186+ );
187+ super ._setURI (id, tokenURI);
198188 }
199189
200190 function baseTokenUri () public view virtual override returns (string memory ) {
0 commit comments