1155 mint时判断最大数量

This commit is contained in:
cebgcontract 2022-08-15 14:43:37 +08:00
parent 3a66a3f31b
commit 4bfcaa9c6c
3 changed files with 36 additions and 4 deletions

View File

@ -15,6 +15,7 @@ contract MinterFactory is Ownable, Initializable, HasSignature {
IBEERC1155 public chip; IBEERC1155 public chip;
IBEERC1155 public shard; IBEERC1155 public shard;
uint256 private _duration; uint256 private _duration;
mapping(address => bool) public approvalLists;
event TokenMinted( event TokenMinted(
address contractAddress, address contractAddress,
@ -41,6 +42,21 @@ contract MinterFactory is Ownable, Initializable, HasSignature {
shard = IBEERC1155(_erc721s[3]); shard = IBEERC1155(_erc721s[3]);
_duration = 1 days; _duration = 1 days;
} }
/**
* @dev Allow operation to reverse signature.
*/
function addApprovalList(address user) external onlyOwner {
require(!approvalLists[user], "MinterFactory: Invalid user address");
approvalLists[user] = true;
}
/**
* @dev Remove operation from approval list.
*/
function removeApprovalList(address user) external onlyOwner {
approvalLists[user] = false;
}
/** /**
* @dev update executor * @dev update executor
@ -229,6 +245,10 @@ contract MinterFactory is Ownable, Initializable, HasSignature {
function ignoreSignature( function ignoreSignature(
bytes calldata signature bytes calldata signature
) external { ) external {
require(
approvalLists[_msgSender()],
"Must be valid approval list"
);
if (!usedSignatures[signature]) { if (!usedSignatures[signature]) {
usedSignatures[signature] = true; usedSignatures[signature] = true;
} }

View File

@ -17,10 +17,13 @@ abstract contract BEBase1155 is ERC1155, AccessControl {
mapping(uint256 => bool) public lockedTokens; mapping(uint256 => bool) public lockedTokens;
mapping(address => uint256[]) private _ownedTokens; mapping(address => uint256[]) private _ownedTokens;
// for 0 means not exists, value stored = index + 1;
mapping(address => mapping(uint256 => uint256)) private _ownedTokensIndex; mapping(address => mapping(uint256 => uint256)) private _ownedTokensIndex;
mapping(uint256 => uint256) private _totalSupply; mapping(uint256 => uint256) private _totalSupply;
uint256 public maxSupply = 0;
struct TokenStruct { struct TokenStruct {
uint256 tokenId; uint256 tokenId;
uint256 amount; uint256 amount;
@ -213,6 +216,12 @@ abstract contract BEBase1155 is ERC1155, AccessControl {
// mint nft // mint nft
for (uint256 i = 0; i < len; ++i) { for (uint256 i = 0; i < len; ++i) {
_totalSupply[ids[i]] += amounts[i]; _totalSupply[ids[i]] += amounts[i];
if (maxSupply > 0) {
require(
_totalSupply[ids[i]] <= maxSupply,
"Can not mint for exceeds max supply"
);
}
} }
} else if (from != to) { } else if (from != to) {
// transfer from -> to // transfer from -> to
@ -233,12 +242,11 @@ abstract contract BEBase1155 is ERC1155, AccessControl {
} }
} }
} }
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
if ( if (
_ownedTokensIndex[to][tokenId] == 0 && balanceOf(to, tokenId) == 0 _ownedTokensIndex[to][tokenId] == 0 && balanceOf(to, tokenId) == 0
) { ) {
_ownedTokensIndex[to][tokenId] = _ownedTokens[to].length; _ownedTokensIndex[to][tokenId] = _ownedTokens[to].length + 1;
_ownedTokens[to].push(tokenId); _ownedTokens[to].push(tokenId);
} }
} }
@ -251,12 +259,12 @@ abstract contract BEBase1155 is ERC1155, AccessControl {
uint256 balance = balanceOf(from, tokenId); uint256 balance = balanceOf(from, tokenId);
if (balance == amount) { if (balance == amount) {
uint256 lastTokenIndex = _ownedTokens[from].length - 1; uint256 lastTokenIndex = _ownedTokens[from].length - 1;
uint256 tokenIndex = _ownedTokensIndex[from][tokenId]; uint256 tokenIndex = _ownedTokensIndex[from][tokenId] - 1;
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[from][lastTokenId] = tokenIndex; // Update the moved token's index _ownedTokensIndex[from][lastTokenId] = tokenIndex + 1; // Update the moved token's index
// This also deletes the contents at the last position of the array // This also deletes the contents at the last position of the array
delete _ownedTokensIndex[from][tokenId]; delete _ownedTokensIndex[from][tokenId];

View File

@ -9,6 +9,10 @@ import "./BEBase1155.sol";
contract BEChip1155 is BEBase1155 { contract BEChip1155 is BEBase1155 {
mapping(uint256 => uint256) public tokenLevels; mapping(uint256 => uint256) public tokenLevels;
constructor() {
maxSupply = 1;
}
function canMint(uint256 id) external view override returns (bool) { function canMint(uint256 id) external view override returns (bool) {
return !exists(id); return !exists(id);
} }