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 ' ;
66import './IERC1155MixedFungible.sol ' ;
77
@@ -27,7 +27,7 @@ import './IERC1155MixedFungible.sol';
2727 * Remember to always consult best practices from other communities and examples (such as OpenZeppelin)
2828 * when crafting your token logic, rather than relying on the FireFly community alone. Happy minting!
2929 */
30- contract ERC1155MixedFungible is Context , ERC1155 , IERC1155MixedFungible {
30+ contract ERC1155MixedFungible is Context , ERC1155URIStorage , IERC1155MixedFungible {
3131 // Use a split bit implementation:
3232 // - Bit 255: type flag (0 = fungible, 1 = non-fungible)
3333 // - Bits 255-128: type id
@@ -44,10 +44,6 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
4444 // inherited ERC1155 `_uri` is private, so need our own within this contract
4545 string private _baseTokenURI;
4646
47- // mapping from type ID | index => custom token URIs for non-fungible tokens
48- // fallback behavior if missing is to use the default base URI
49- mapping (uint256 => string ) private _nfTokenURIs;
50-
5147 function isFungible (uint256 id ) internal pure returns (bool ) {
5248 return id & TYPE_NF_BIT == 0 ;
5349 }
@@ -89,18 +85,6 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
8985 );
9086 }
9187
92- function _setNonFungibleURI (
93- uint256 type_id ,
94- uint256 id ,
95- string memory _uri
96- ) private creatorOnly (type_id) {
97- require (
98- isNonFungible (type_id),
99- 'ERC1155MixedFungible: id does not represent a non-fungible type '
100- );
101- _nfTokenURIs[id] = _uri;
102- }
103-
10488 function mintNonFungible (
10589 uint256 type_id ,
10690 address [] calldata to ,
@@ -138,7 +122,7 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
138122 for (uint256 i = 0 ; i < to.length ; ++ i) {
139123 uint256 id = type_id | (index + i);
140124 _mint (to[i], id, 1 , data);
141- _setNonFungibleURI (type_id, id, _uri);
125+ _setURI ( id, _uri);
142126 }
143127 }
144128
@@ -185,15 +169,22 @@ contract ERC1155MixedFungible is Context, ERC1155, IERC1155MixedFungible {
185169
186170 function uri (
187171 uint256 id
188- ) public view virtual override (IERC1155MixedFungible , ERC1155 ) returns (string memory ) {
189- string memory _tokenUri = _nfTokenURIs[id];
190- bytes memory tempURITest = bytes (_tokenUri);
191-
192- if (tempURITest.length == 0 ) {
193- return _baseTokenURI;
194- } else {
195- return _tokenUri;
196- }
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);
197188 }
198189
199190 function baseTokenUri () public view virtual override returns (string memory ) {
0 commit comments