update initializableERC721 && ERC1155
This commit is contained in:
@@ -8,14 +8,40 @@
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC1155} from "./ERC1155.sol";
|
||||
import {Strings} from "../utils/Strings.sol";
|
||||
|
||||
contract InitializableERC1155 is ERC1155 {
|
||||
using Strings for uint256;
|
||||
|
||||
mapping (uint256 => string) private _tokenURIs;
|
||||
string internal _baseUri = "";
|
||||
|
||||
function init(
|
||||
address creator,
|
||||
uint256 amount,
|
||||
string memory baseUrI
|
||||
string memory uri
|
||||
) public {
|
||||
_setURI(baseUrI);
|
||||
_mint(creator, 0, amount ,"");
|
||||
_setTokenURI(0, uri);
|
||||
}
|
||||
|
||||
function uri(uint256 tokenId) public view override returns (string memory) {
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseUri;
|
||||
|
||||
if (bytes(base).length == 0) {
|
||||
return _tokenURI;
|
||||
}
|
||||
|
||||
if (bytes(_tokenURI).length > 0) {
|
||||
return string(abi.encodePacked(base, _tokenURI));
|
||||
}
|
||||
|
||||
return super.uri(tokenId);
|
||||
}
|
||||
|
||||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
|
||||
_tokenURIs[tokenId] = _tokenURI;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC721} from "./ERC721.sol";
|
||||
import {ERC721URIStorage} from "./ERC721URIStorage.sol";
|
||||
|
||||
contract InitializableERC721 is ERC721 {
|
||||
contract InitializableERC721 is ERC721URIStorage {
|
||||
function init(
|
||||
address creator,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUri
|
||||
string memory uri
|
||||
) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_baseUri = baseUri;
|
||||
_mint(creator, 0);
|
||||
_setTokenURI(0, uri);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user