Repository: CryptoBlades/cryptoblades
File: contracts/CBKLandSale.sol (Solidity)

Code before:

    function getPurchase()  public view returns (uint256, uint256) {
        return (purchaseAddressMapping[msg.sender].purchasedTier, purchaseAddressMapping[msg.sender].stamp);
    }

    function getPurchaseOf(address owner)  public view returns (uint256, uint256) {
        return (purchaseAddressMapping[owner].purchasedTier, purchaseAddressMapping[owner].stamp);
    }

    function getSalesCount() public view returns (uint256){
        return totalSales;
    }

    function getPurchaseBySale(uint256 sale)  public view returns (address, uint256, uint256) {
        return (sales[sale].buyer, sales[sale].purchasedTier, sales[sale].stamp);
    }

    function setSaleAllowed(bool allowed) external isAdmin {
        _enabled = allowed;
    }

    function setReservedSaleAllowed(bool allowed) external isAdmin {
        _reservedEnabled = allowed;
    }

    function reserveChunks(uint256[] calldata chunkIds, address reserveFor, bool reserve, bool forced) external isAdmin {
        for (uint256 i = 0; i < chunkIds.length; i++) {
            require (chunkIds[i] != 0, "0 NA"); // chunk id 0 shouldn't be reserved
            require(!reserve || (forced || chunksReservedFor[chunkIds[i]] == address(0)), "AS"); // already reserved, request has to be forced to avoid issues
            
            if(reserve && !reservedChunkIds.contains(chunkIds[i])) {
                reservedChunkIds.add(chunkIds[i]);
            }

            if(!reserve) {
                reservedChunkIds.remove(chunkIds[i]);
                chunksReservedFor[chunkIds[i]] = address(0);
                 reservedChunks[reserveFor].remove(chunkIds[i]);
            }

            if(reserve && !reservedChunks[reserveFor].contains(chunkIds[i])) {
                reservedChunks[reserveFor].add(chunkIds[i]);
                chunksReservedFor[chunkIds[i]] = reserveFor;
            }
        }
    }

    function getReservedChunksIdsForAddress(address reservedFor) public view  returns (uint256[] memory chunkIds) {
        uint256 amount = reservedChunks[reservedFor].length();
        chunkIds = new uint256[](amount);


Review comment (suggestion):
a small note on the reserve parameter, it could be a bit confusing. But since this is an admin only function it's not a big deal. Ideally the function or param name would indicate the two directions this function can set things.

Code after:
        return (purchaseAddressMapping[msg.sender].purchasedTier, purchaseAddressMapping[msg.sender].stamp);
    }

    function getPurchaseOf(address owner)  public view returns (uint256, uint256) {
        return (purchaseAddressMapping[owner].purchasedTier, purchaseAddressMapping[owner].stamp);
    }

    function getSalesCount() public view returns (uint256){
        return totalSales;
    }

    function getPurchaseBySale(uint256 sale)  public view returns (address, uint256, uint256) {
        return (sales[sale].buyer, sales[sale].purchasedTier, sales[sale].stamp);
    }

    function setSaleAllowed(bool allowed) external isAdmin {
        _enabled = allowed;
    }

    function setReservedSaleAllowed(bool allowed) external isAdmin {
        _reservedEnabled = allowed;
    }

    function setChunksReservationInfo(uint256[] calldata chunkIds, address reserveFor, bool reserved, bool forced) external isAdmin {
        for (uint256 i = 0; i < chunkIds.length; i++) {
            require (chunkIds[i] != 0, "0 NA"); // chunk id 0 shouldn't be reserved
            require(!reserved || (forced || chunksReservedFor[chunkIds[i]] == address(0)), "AS"); // already reserved, request has to be forced to avoid issues
            
            if(reserved && !reservedChunkIds.contains(chunkIds[i])) {
                reservedChunkIds.add(chunkIds[i]);
            }

            if(!reserved) {
                reservedChunkIds.remove(chunkIds[i]);
                chunksReservedFor[chunkIds[i]] = address(0);
                 reservedChunks[reserveFor].remove(chunkIds[i]);
            }

            if(reserved && !reservedChunks[reserveFor].contains(chunkIds[i])) {
                reservedChunks[reserveFor].add(chunkIds[i]);
                chunksReservedFor[chunkIds[i]] = reserveFor;
            }
        }
    }

    function getReservedChunksIdsForAddress(address reservedFor) public view  returns (uint256[] memory chunkIds) {
        uint256 amount = reservedChunks[reservedFor].length();
        chunkIds = new uint256[](amount);

        uint256 index = 0;
        for (uint256 i = 0; i < amount; i++) {