Skip to content

Instantly share code, notes, and snippets.

@alexon1234
Created May 11, 2021 22:21
Show Gist options
  • Save alexon1234/a2275d1724ce2122d36bc555e46a25c1 to your computer and use it in GitHub Desktop.
Save alexon1234/a2275d1724ce2122d36bc555e46a25c1 to your computer and use it in GitHub Desktop.
Revert inside a loop

In NFTXMintRequestEligibility, there is the following method. This method will iterate over multiple tokenIds, taking the amount that can be claim and transfer it. But if it finds one token with amount = 0, it will revert the whole transaction. I would recommend that instead of reverting if ammount = 0, to just to break the loop. This way we don't need to run again the transaction if we mistake a number.

function reclaimRequestedMint(uint256[] calldata tokenIds)
        external
        virtual
    {
        ...
        
        for (uint256 i = 0; i < tokenIds.length; i++) {
            uint256 tokenId = tokenIds[i];
            uint256 amount = mintRequests[msg.sender][tokenId];

            //FIXME: Should we have one token with amount <= 0, it will revert all the transactions. Reverting all previous transfer
            // Why not just break the loop
            require(amount > 0, "NFTXVault: nothing to reclaim");
            
            
            mintRequests[msg.sender][tokenId] = 0;
            approvedMints[msg.sender][tokenId] = false;
            if (_is1155) {
                IERC1155Upgradeable(_assetAddress).safeTransferFrom(
                    address(this),
                    msg.sender,
                    tokenId,
                    amount,
                    ""
                );
            } else {
                IERC721Upgradeable(_assetAddress).safeTransferFrom(
                    address(this),
                    msg.sender,
                    tokenId
                );
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment