Skip to content

Commit 4b51e2f

Browse files
committed
add nonReentrant modifier to mint func
1 parent 5f96df4 commit 4b51e2f

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

contracts/NexusNFT.sol

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
3636

3737
mapping(address => uint256) public addressMintedBalance;
3838

39+
bool private locked;
40+
3941
constructor(
4042
string memory _name,
4143
string memory _symbol,
@@ -46,25 +48,43 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
4648
setNotRevealedURI(_initNotRevealedUri);
4749
}
4850

51+
modifier nonReentrant() {
52+
require(!locked, "No re-entrancy");
53+
locked = true;
54+
_;
55+
locked = false;
56+
}
57+
4958
// internal
5059
function _baseURI() internal view virtual override returns (string memory) {
5160
return baseURI;
5261
}
5362

5463
// public
55-
function mint(uint256 _mintAmount) public payable {
64+
function mint(uint256 _mintAmount) public payable nonReentrant {
5665
require(!paused, "the contract is paused");
5766
uint256 supply = totalSupply();
5867
require(_mintAmount > 0, "need to mint at least 1 NFT");
59-
require(_mintAmount <= maxMintAmount,"max mint amount per session exceeded");
68+
require(
69+
_mintAmount <= maxMintAmount,
70+
"max mint amount per session exceeded"
71+
);
6072
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
6173

6274
uint256 costToMint = isWhitelisted(msg.sender) && whitelistEnabled
63-
? cost - whitelistDiscount : cost;
75+
? cost - whitelistDiscount
76+
: cost;
6477

6578
if (msg.sender != owner()) {
66-
require(msg.value >= costToMint * _mintAmount,"insufficient funds");
67-
require(addressMintedBalance[msg.sender] + _mintAmount <=maxNFTPerAddress,"max NFT per address exceeded");
79+
require(
80+
msg.value >= costToMint * _mintAmount,
81+
"insufficient funds"
82+
);
83+
require(
84+
addressMintedBalance[msg.sender] + _mintAmount <=
85+
maxNFTPerAddress,
86+
"max NFT per address exceeded"
87+
);
6888
}
6989

7090
for (uint256 i = 1; i <= _mintAmount; i++) {
@@ -73,11 +93,9 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
7393
}
7494
}
7595

76-
function walletOfOwner(address _owner)
77-
public
78-
view
79-
returns (uint256[] memory)
80-
{
96+
function walletOfOwner(
97+
address _owner
98+
) public view returns (uint256[] memory) {
8199
uint256 ownerTokenCount = balanceOf(_owner);
82100
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
83101
for (uint256 i; i < ownerTokenCount; i++) {
@@ -86,13 +104,9 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
86104
return tokenIds;
87105
}
88106

89-
function tokenURI(uint256 tokenId)
90-
public
91-
view
92-
virtual
93-
override
94-
returns (string memory)
95-
{
107+
function tokenURI(
108+
uint256 tokenId
109+
) public view virtual override returns (string memory) {
96110
require(
97111
_exists(tokenId),
98112
"ERC721Metadata: URI query for nonexistent token"
@@ -148,10 +162,9 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
148162
baseURI = _newBaseURI;
149163
}
150164

151-
function setBaseExtension(string memory _newBaseExtension)
152-
public
153-
onlyOwner
154-
{
165+
function setBaseExtension(
166+
string memory _newBaseExtension
167+
) public onlyOwner {
155168
baseExtension = _newBaseExtension;
156169
}
157170

@@ -173,10 +186,9 @@ contract NexusEtherealsNFT is ERC721Enumerable, Ownable {
173186
}
174187
}
175188

176-
function removeFromWhitelist(address[] calldata _addresses)
177-
public
178-
onlyOwner
179-
{
189+
function removeFromWhitelist(
190+
address[] calldata _addresses
191+
) public onlyOwner {
180192
for (uint256 i = 0; i < _addresses.length; i++) {
181193
if (whitelist[_addresses[i]]) {
182194
whitelist[_addresses[i]] = false;

0 commit comments

Comments
 (0)