update mysteryboxV1
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
- contracts/DODOFee/FeeDistributer.sol
|
||||
|
||||
- contracts/external/ERC721/
|
||||
|
||||
- contracts/external/ERC1155/
|
||||
|
||||
- contracts/external/ERC20/InitializableERC20.sol
|
||||
@@ -20,6 +18,8 @@
|
||||
|
||||
### DODO MysteryBox
|
||||
|
||||
- contracts/DODOMysteryBox/MysteryBox1.sol
|
||||
- contracts/DODOMysteryBox/MysteryBoxV1.sol
|
||||
|
||||
- contracts/lib/RandomGenerator.sol
|
||||
- contracts/lib/RandomGenerator.sol
|
||||
|
||||
- contracts/external/ERC721/
|
||||
@@ -11,9 +11,9 @@ import {SafeMath} from "../lib/SafeMath.sol";
|
||||
import {IRandomGenerator} from "../lib/RandomGenerator.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
import {Address} from "../external/utils/Address.sol";
|
||||
import {ERC721} from "../external/ERC721/ERC721.sol";
|
||||
import {ERC721URIStorage} from "../external/ERC721/ERC721URIStorage.sol";
|
||||
|
||||
contract MysteryBox1 is ERC721, InitializableOwnable {
|
||||
contract MysteryBoxV1 is ERC721URIStorage, InitializableOwnable {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
using Address for address;
|
||||
@@ -28,6 +28,8 @@ contract MysteryBox1 is ERC721, InitializableOwnable {
|
||||
uint256 public _TICKET_UNIT_ = 1; // ticket consumed in a single lottery
|
||||
|
||||
uint256[] public _TOKEN_IDS_;
|
||||
uint256 public _ID_POINT_;
|
||||
|
||||
address public _RANDOM_GENERATOR_;
|
||||
|
||||
bool public _REDEEM_ALLOWED_ = true;
|
||||
@@ -51,13 +53,13 @@ contract MysteryBox1 is ERC721, InitializableOwnable {
|
||||
function init(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUrI,
|
||||
string memory baseUri,
|
||||
address owner,
|
||||
address randomGenerator
|
||||
) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_baseURI = baseUrI;
|
||||
_baseUri = baseUri;
|
||||
|
||||
initOwner(owner);
|
||||
_RANDOM_GENERATOR_ = randomGenerator;
|
||||
@@ -78,14 +80,16 @@ contract MysteryBox1 is ERC721, InitializableOwnable {
|
||||
emit BuyTicket(msg.sender, buyAmount - leftOver, tickets);
|
||||
}
|
||||
|
||||
function redeemPrize() external {
|
||||
|
||||
function redeemPrize(uint256 ticketNum) external {
|
||||
require(_REDEEM_ALLOWED_, "REDEEM_CLOSED");
|
||||
require(!address(msg.sender).isContract(), "ONLY_ALLOW_EOA");
|
||||
uint256 ticketNum = _USER_TICKETS_[msg.sender];
|
||||
require(ticketNum >= 1, "TICKET_NOT_ENOUGH");
|
||||
require(ticketNum >= 1 && ticketNum <= _USER_TICKETS_[msg.sender], "TICKET_NUM_INVALID");
|
||||
for (uint256 i = 0; i < ticketNum; i++) {
|
||||
_redeemSinglePrize(msg.sender);
|
||||
}
|
||||
_USER_TICKETS_[msg.sender] = _USER_TICKETS_[msg.sender].sub(ticketNum);
|
||||
_TOTAL_TICKETS_ = _TOTAL_TICKETS_.sub(ticketNum);
|
||||
}
|
||||
|
||||
// =============== Internal ================
|
||||
@@ -139,11 +143,13 @@ contract MysteryBox1 is ERC721, InitializableOwnable {
|
||||
emit Withdraw(msg.sender, amount);
|
||||
}
|
||||
|
||||
function batchMint(uint256[] calldata tokenIds) external onlyOwner {
|
||||
for(uint256 i = 0; i<tokenIds.length; i++) {
|
||||
_mint(address(this), tokenIds[i]);
|
||||
_TOKEN_IDS_.push(tokenIds[i]);
|
||||
function batchMint(string[] calldata urls) external onlyOwner {
|
||||
for(uint256 i = 0; i < urls.length; i++) {
|
||||
_mint(address(this), _ID_POINT_);
|
||||
_TOKEN_IDS_.push(_ID_POINT_);
|
||||
_setTokenURI(_ID_POINT_, urls[i]);
|
||||
_ID_POINT_++;
|
||||
}
|
||||
emit BatchMint(tokenIds.length);
|
||||
emit BatchMint(urls.length);
|
||||
}
|
||||
}
|
||||
12
contracts/external/ERC721/ERC721.sol
vendored
12
contracts/external/ERC721/ERC721.sol
vendored
@@ -27,7 +27,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
// Token symbol
|
||||
string internal _symbol;
|
||||
|
||||
string internal _baseURI = "";
|
||||
string internal _baseUri = "";
|
||||
|
||||
// Mapping from token ID to owner address
|
||||
mapping (uint256 => address) private _owners;
|
||||
@@ -87,12 +87,20 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
|
||||
|
||||
string memory baseURI = _baseURI;
|
||||
string memory baseURI = _baseURI();
|
||||
return bytes(baseURI).length > 0
|
||||
? string(abi.encodePacked(baseURI, tokenId.toString()))
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
|
||||
* in child contracts.
|
||||
*/
|
||||
function _baseURI() internal view virtual returns (string memory) {
|
||||
return _baseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-approve}.
|
||||
*/
|
||||
|
||||
67
contracts/external/ERC721/ERC721URIStorage.sol
vendored
Normal file
67
contracts/external/ERC721/ERC721URIStorage.sol
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721URIStorage.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./ERC721.sol";
|
||||
|
||||
/**
|
||||
* @dev ERC721 token with storage based token URI management.
|
||||
*/
|
||||
abstract contract ERC721URIStorage is ERC721 {
|
||||
using Strings for uint256;
|
||||
|
||||
// Optional mapping for token URIs
|
||||
mapping (uint256 => string) private _tokenURIs;
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Metadata-tokenURI}.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
|
||||
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseURI();
|
||||
|
||||
// If there is no base URI, return the token URI.
|
||||
if (bytes(base).length == 0) {
|
||||
return _tokenURI;
|
||||
}
|
||||
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
|
||||
if (bytes(_tokenURI).length > 0) {
|
||||
return string(abi.encodePacked(base, _tokenURI));
|
||||
}
|
||||
|
||||
return super.tokenURI(tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*/
|
||||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
|
||||
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
|
||||
_tokenURIs[tokenId] = _tokenURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Destroys `tokenId`.
|
||||
* The approval is cleared when the token is burned.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _burn(uint256 tokenId) internal virtual override {
|
||||
super._burn(tokenId);
|
||||
|
||||
if (bytes(_tokenURIs[tokenId]).length != 0) {
|
||||
delete _tokenURIs[tokenId];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,11 @@ contract InitializableERC721 is ERC721 {
|
||||
address creator,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUrI
|
||||
string memory baseUri
|
||||
) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_baseURI = baseUrI;
|
||||
_baseUri = baseUri;
|
||||
_mint(creator, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user