lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.19
/**
 * @param _tokenId uint256 ID of new token
 * @param _payoutPercentage uint256 payout percentage (divisible by 10)
 */
function createPromoListing(uint256 _tokenId, uint256 _startingPrice, uint256 _payoutPercentage) onlyOwner() public {
     uint256 countryId = _tokenId % COUNTRY_IDX;
     address countryOwner;
     uint256 price;
     (countryOwner,,price,,) = countryContract.getCountryData(countryId);
     require (countryOwner != address(0));

     if (_startingPrice == 0) {
       if (price >= thirdCap) _startingPrice = price.div(80);
       else if (price >= secondCap) _startingPrice = price.div(75);
       else _startingPrice = 0.002 ether;
     }

     createListing(_tokenId, _startingPrice, _payoutPercentage, countryOwner);
   }
// Solidity 0.4.19
/**
 * @dev createListing Adds new ERC721 Token
 * @param _tokenId uint256 ID of new token
 * @param _payoutPercentage uint256 payout percentage (divisible by 10)
 * @param _owner address of new owner
 */
function createListing(uint256 _tokenId, uint256 _startingPrice, uint256 _payoutPercentage, address _owner) onlyOwner() public {

    // make sure price > 0
    require(_startingPrice > 0);
    // make sure token hasn't been used yet
    require(cityData[_tokenId].price == 0);
    
    // create new token
    City storage newCity = cityData[_tokenId];

    newCity.owner = _owner;
    newCity.price = _startingPrice;
    newCity.lastPrice = 0;
    newCity.payout = _payoutPercentage;

    // store city in storage
    listedCities.push(_tokenId);
    
    // mint new token
    _mint(_owner, _tokenId);
  }
// Solidity 0.4.19
/**
 * @dev Determines next price of token
 * @param _price uint256 ID of current price
 */
function getNextPrice (uint256 _price) private view returns (uint256 _nextPrice) {
    if (_price < firstCap) {
      return _price.mul(200).div(94);
    } else if (_price < secondCap) {
      return _price.mul(135).div(95);
    } else if (_price < thirdCap) {
      return _price.mul(118).div(96);
    } else {
      return _price.mul(115).div(97);
    }
  }
// Solidity 0.4.19
/**
 * @dev Transfer City from Previous Owner to New Owner
 * @param _from previous owner address
 * @param _to new owner address
 * @param _tokenId uint256 ID of token
 */
function transferCity(address _from, address _to, uint256 _tokenId) internal {

    // check token exists
    require(tokenExists(_tokenId));

    // make sure previous owner is correct
    require(cityData[_tokenId].owner == _from);

    require(_to != address(0));
    require(_to != address(this));

    // pay any unpaid payouts to previous owner of city
    updateSinglePayout(_from, _tokenId);

    // clear approvals linked to this token
    clearApproval(_from, _tokenId);

    // remove token from previous owner
    removeToken(_from, _tokenId);

    // update owner and add token to new owner
    cityData[_tokenId].owner = _to;
    addToken(_to, _tokenId);

   //raise event
    Transfer(_from, _to, _tokenId);
  }
// Solidity 0.4.19
/**
 * @dev Updates the payout for the cities the owner has
 * @param _owner address of token owner
 */
function updatePayout(address _owner) public {
    uint256[] memory cities = ownedTokens[_owner];
    uint256 owed;
    for (uint256 i = 0; i < cities.length; i++) {
        uint256 totalCityOwed = poolTotal * cityData[cities[i]].payout / 10000;
        uint256 cityOwed = totalCityOwed.sub(cityData[cities[i]].withdrawn);
        owed += cityOwed;
        
        cityData[cities[i]].withdrawn += cityOwed;
    }
    payoutBalances[_owner] += owed;
  }
// Solidity 0.4.19
/**
 * @dev Return all city data
 * @param _tokenId uint256 of token
 */
function getCityData (uint256 _tokenId) external view 
  returns (address _owner, uint256 _price, uint256 _nextPrice, uint256 _payout, address _cOwner, uint256 _cPrice, uint256 _cPayout) 
  {
    City memory city = cityData[_tokenId];
    address countryOwner;
    uint256 countryPrice;
    uint256 countryPayout;
    (countryOwner,,countryPrice,,countryPayout) = countryContract.getCountryData(_tokenId % COUNTRY_IDX);
    return (city.owner, city.price, getNextPrice(city.price), city.payout, countryOwner, countryPrice, countryPayout);
  }
// Solidity 0.4.19
/**
 * @dev Approves another address to claim for the ownership of the given token ID
 * @param _to address to be approved for the given token ID
 * @param _tokenId uint256 ID of the token to be approved
 */
function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
    address owner = ownerOf(_tokenId);
    require(_to != owner);
    if (approvedFor(_tokenId) != 0 || _to != 0) {
      tokenApprovals[_tokenId] = _to;
      Approval(owner, _to, _tokenId);
    }
  }
// Solidity 0.4.19
/**
 * @dev Internal function to clear current approval and transfer the ownership of a given token ID
 * @param _from address which you want to send tokens from
 * @param _to address which you want to transfer the token to
 * @param _tokenId uint256 ID of the token to be transferred
 */
function clearApprovalAndTransfer(address _from, address _to, uint256 _tokenId) internal isNotContract(_to) {
    require(_to != address(0));
    require(_to != ownerOf(_tokenId));
    require(ownerOf(_tokenId) == _from);

    clearApproval(_from, _tokenId);
    updateSinglePayout(_from, _tokenId);
    removeToken(_from, _tokenId);
    addToken(_to, _tokenId);
    Transfer(_from, _to, _tokenId);
  }
// Solidity 0.8.4
/// @notice Whitelist mint using the voucher
function whitelistMint(
        NFTVoucher calldata voucher,
        bytes calldata signature,
        uint8 amount
    ) external payable {
        MinterInfo storage minterInfo = _whitelistInfo[_msgSender()];
        // if haven't redeemed then redeem first
        if (minterInfo.stageId < stageInfo.stageId) {
            // make sure that the signer is authorized to mint NFTs
            _verify(voucher, signature);
            // check current stage
            require(voucher.stageId == stageInfo.stageId, "Wrong stage");
            // update minter info
            minterInfo.stageId = voucher.stageId;
            minterInfo.remain = voucher.amount;
        }

        // check time
        require(block.timestamp >= stageInfo.startTime, "Sale not started");
        require(block.timestamp <= stageInfo.endTime, "Sale already ended");
        // check if enough remain
        require(amount <= minterInfo.remain, "Not enough remain");
        // check if exceed
        require(
            totalSupply() + amount <= stageInfo.maxSupply,
            "Exceed stage max supply"
        );
        // check fund
        require(msg.value >= stageInfo.mintPrice * amount, "Not enough fund");
        super._safeMint(_msgSender(), amount);
        minterInfo.remain -= amount;
    }
// Solidity 0.8.4
/// @notice Public mint
function publicMint(uint8 amount) external payable {
        // check public mint stage
        require(
            stageInfo.stageId == PUBLIC_STAGE_ID,
            "Public mint not started"
        );
        // check time
        require(block.timestamp >= stageInfo.startTime, "Sale not started");
        require(block.timestamp <= stageInfo.endTime, "Sale already ended");
        // check if exceed total supply
        require(totalSupply() + amount <= MAX_SUPPLY, "Exceed total supply");
        // check fund
        require(msg.value >= stageInfo.mintPrice * amount, "Not enough fund");
        // batch mint
        super._safeMint(_msgSender(), amount);
    }
// Solidity 0.8.4
/// @dev Verify voucher
function _verify(NFTVoucher calldata voucher, bytes calldata signature)
        private
        view
    {
        bytes32 digest = _hashTypedDataV4(
            keccak256(
                abi.encode(
                    keccak256(
                        "NFTVoucher(address redeemer,uint8 stageId,uint8 amount)"
                    ),
                    _msgSender(),
                    voucher.stageId,
                    voucher.amount
                )
            )
        );
        require(
            owner() == ECDSA.recover(digest, signature),
            "invalid or unauthorized"
        );
    }
// Solidity 0.8.4
/// @dev Go to next stage
function nextStage(StageInfo memory _stageInfo) external onlyOwner {
        require(
            _stageInfo.stageId >= stageInfo.stageId,
            "Cannot set to previous stage"
        );
        require(_stageInfo.maxSupply <= MAX_SUPPLY, "Set exceed max supply");
        require(_stageInfo.stageId <= PUBLIC_STAGE_ID, "Public is final stage");
        stageInfo = _stageInfo;
    }
// Solidity 0.4.15
// This will not throw error on wrong input, but instead consume large and unknown amount of gas
// This should never occure as it's use with the ShapeShift deposit return value is checked before calling function
function parseAddr(string _a) internal returns (address){
        bytes memory tmp = bytes(_a);
        uint160 iaddr = 0;
        uint160 b1;
        uint160 b2;
        for (uint i=2; i<2+2*20; i+=2){
            iaddr *= 256;
            b1 = uint160(tmp[i]);
            b2 = uint160(tmp[i+1]);
            if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87;
            else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55;
            else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48;
            if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87;
            else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55;
            else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48;
            iaddr += (b1*16+b2);
        }
        return address(iaddr);
    }
// Solidity 0.4.15
/**
 * Callback function for use exclusively by Oraclize.
 * @param myid The Oraclize id of the query.
 * @param result The result of the query.
 */
function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize.cbAddress()) revert();

        uint conversionID = oraclizeMyId2conversionID[myid];

        if( bytes(result).length == 0 ) {
            ConversionAborted(conversionID, "Oraclize return value was invalid, this is probably due to incorrect convert() argments");
            recoverable[conversions[conversionID].returnAddress] += conversions[conversionID].amount;
            conversions[conversionID].amount = 0;
        }
        else {
            address depositAddress = parseAddr(result);
            require(depositAddress != msg.sender); // prevent DAO tpe re-entracy vulnerability that can potentially be done by Oraclize
            uint sendAmount = conversions[conversionID].amount;
            conversions[conversionID].amount = 0;
            if (depositAddress.send(sendAmount)) {
                ConversionSentToShapeShift(conversionID, conversions[conversionID].returnAddress, depositAddress, sendAmount);
            }
            else {
                ConversionAborted(conversionID, "deposit to address returned by Oraclize failed");
                recoverable[conversions[conversionID].returnAddress] += sendAmount;
            }
        }
    }
// Solidity 0.4.15
/**
 * Cancel a cryptocurrency conversion.
 * This should only be required to be called if Oraclize fails make a return call to __callback().
 * @param conversionID The conversion ID of the cryptocurrency conversion, generated during engine().
 */
function cancelConversion(uint conversionID) external {
        Conversion memory conversion = conversions[conversionID];

        if (conversion.amount > 0) {
            require(msg.sender == conversion.returnAddress);
            recoverable[msg.sender] += conversion.amount;
            conversions[conversionID].amount = 0;
            ConversionAborted(conversionID, "conversion cancelled by creator");
        }
    }
// Solidity 0.4.15
/**
 * Sets up a ShapeShift cryptocurrency conversion using Oraclize and the ShapeShift API. Must be sent more Ether than the Oraclize price.
 * Returns a conversionID which can be used for tracking of the conversion.
 * @param _coinSymbol The coinsymbol of the other blockchain to be used by ShapeShift. See engine() function for more details.
 * @param _toAddress The address on the other blockchain that the converted cryptocurrency will be sent to.
 * Example first two arguments:
 * "ltc", "LbZcDdMeP96ko85H21TQii98YFF9RgZg3D"    Litecoin
 * "btc", "1L8oRijgmkfcZDYA21b73b6DewLtyYs87s"    Bitcoin
 * "dash", "Xoopows17idkTwNrMZuySXBwQDorsezQAx"   Dash
 * "zec", "t1N7tf1xRxz5cBK51JADijLDWS592FPJtya"   ZCash
 * "doge", "DMAFvwTH2upni7eTau8au6Rktgm2bUkMei"   Dogecoin
 * Test symbol pairs using ShapeShift API (shapeshift.io/validateAddress/[address]/[coinSymbol]) or by creating a test
 * conversion on https://shapeshift.io first whenever possible before using it with InterCrypto.
 * @param _returnAddress The Ethereum address that any Ether should be sent back to in the event that the ShapeShift conversion is invalid or fails.
 */
function engine(string _coinSymbol, string _toAddress, address _returnAddress) internal returns(uint conversionID) {
        conversionID = conversionCount++;

        if (
            !isValidString(_coinSymbol, 6) || // Waves smbol is "waves"
            !isValidString(_toAddress, 120)   // Monero integrated addresses are 106 characters
            ) {
            ConversionAborted(conversionID, "input parameters are too long or contain invalid symbols");
            recoverable[msg.sender] += msg.value;
            return;
        }

        uint oraclizePrice = getInterCryptoPrice();

        if (msg.value > oraclizePrice) {
            Conversion memory conversion = Conversion(_returnAddress, msg.value-oraclizePrice);
            conversions[conversionID] = Conversion(_returnAddress, msg.value-oraclizePrice);

            string memory postData = createShapeShiftConversionPost(_coinSymbol, _toAddress);
            bytes32 myQueryId = oraclize_query("URL", "json(https://shapeshift.io/shift).deposit", postData);

            if (myQueryId == 0) {
                ConversionAborted(conversionID, "unexpectedly high Oraclize price when calling oraclize_query");
                recoverable[msg.sender] += msg.value-oraclizePrice;
                conversions[conversionID].amount = 0;
                return;
            }
            oraclizeMyId2conversionID[myQueryId] = conversionID;
            ConversionStarted(conversionID);
        }
        else {
            ConversionAborted(conversionID, "Not enough Ether sent to cover Oraclize fee");
            conversions[conversionID].amount = 0;
            recoverable[msg.sender] += msg.value;
        }
    }
// Solidity 0.4.15
/**
 * Returns true if a given string contains only numbers and letters, and is below a maximum length.
 * @param _string String to be checked.
 * @param maxSize The maximum allowable sting character length. The address on the other blockchain that the converted cryptocurrency will be sent to.
 */
function isValidString(string _string, uint maxSize) constant internal returns (bool allowed) {
        bytes memory stringBytes = bytes(_string);
        uint lengthBytes = stringBytes.length;
        if (lengthBytes < 1 ||
            lengthBytes > maxSize) {
            return false;
        }

        for (uint i = 0; i < lengthBytes; i++) {
            byte b = stringBytes[i];
            if ( !(
                (b >= 48 && b <= 57) || // 0 - 9
                (b >= 65 && b <= 90) || // A - Z
                (b >= 97 && b <= 122)   // a - z
            )) {
                return false;
            }
        }
        return true;
    }
// Solidity 0.4.15
/**
 * Returns a concatenation of seven bytes.
 * @param b1 The first bytes to be concatenated.
 * ...
 * @param b7 The last bytes to be concatenated.
 */
function concatBytes(bytes b1, bytes b2, bytes b3, bytes b4, bytes b5, bytes b6, bytes b7) internal returns (bytes bFinal) {
        bFinal = new bytes(b1.length + b2.length + b3.length + b4.length + b5.length + b6.length + b7.length);

        uint i = 0;
        uint j;
        for (j = 0; j < b1.length; j++) bFinal[i++] = b1[j];
        for (j = 0; j < b2.length; j++) bFinal[i++] = b2[j];
        for (j = 0; j < b3.length; j++) bFinal[i++] = b3[j];
        for (j = 0; j < b4.length; j++) bFinal[i++] = b4[j];
        for (j = 0; j < b5.length; j++) bFinal[i++] = b5[j];
        for (j = 0; j < b6.length; j++) bFinal[i++] = b6[j];
        for (j = 0; j < b7.length; j++) bFinal[i++] = b7[j];
    }
// Solidity 0.4.15
/**
 * Returns the ShapeShift shift API string that is needed to be sent to Oraclize.
 * @param _coinSymbol The coinsymbol of the other blockchain to be used by ShapeShift. See engine() function for more details.
 * @param _toAddress The address on the other blockchain that the converted cryptocurrency will be sent to.
 * Example output:
 * ' {"withdrawal":"LbZcDdMeP96ko85H21TQii98YFF9RgZg3D","pair":"eth_ltc","returnAddress":"558999ff2e0daefcb4fcded4c89e07fdf9ccb56c"}'
 * Note that an extra space ' ' is needed at the start to tell Oraclize to make a POST query
 */
function createShapeShiftConversionPost(string _coinSymbol, string _toAddress) internal returns (string sFinal) {
        string memory s1 = ' {"withdrawal":"';
        string memory s3 = '","pair":"eth_';
        string memory s5 = '","returnAddress":"';
        string memory s7 = '"}';

        bytes memory bFinal = concatBytes(bytes(s1), bytes(_toAddress), bytes(s3), bytes(_coinSymbol), bytes(s5), bytes(addressToBytes(msg.sender)), bytes(s7));

        sFinal = string(bFinal);
    }
// Solidity 0.4.15
/**
 * Returns the bytes representation of a provided Ethereum address
 * Authored by from https://github.com/axic
 * @param _address Ethereum address to be cast to bytes
 */
function addressToBytes(address _address) internal returns (bytes) {
        uint160 tmp = uint160(_address);

        // 40 bytes of space, but actually uses 64 bytes
        string memory holder = "                                        ";
        bytes memory ret = bytes(holder);

        // NOTE: this is written in an expensive way, as out-of-order array access
        //       is not supported yet, e.g. we cannot go in reverse easily
        //       (or maybe it is a bug: https://github.com/ethereum/solidity/issues/212)
        uint j = 0;
        for (uint i = 0; i < 20; i++) {
            uint _tmp = tmp / (2 ** (8*(19-i))); // shr(tmp, 8*(19-i))
            uint nb1 = (_tmp / 0x10) & 0x0f;     // shr(tmp, 8) & 0x0f
            uint nb2 = _tmp & 0x0f;
            ret[j++] = byte(nibbleToChar(nb1));
            ret[j++] = byte(nibbleToChar(nb2));
        }

        return ret;
    }
// Solidity 0.8.7
// function mint(uint256 count) external payable {
//     require(isMintingOn , 'minting not started');
//     require(count < MAX_MINT_COUNT, 'Max Mint per Txn exceeded');
//     require(totalPublicSupply + count < MAX_SUPPLY, 'All testnets have already been minted!');
//     require(tokenPrice * count == msg.value, 'Insufficient / Incorrect Funds');
//     for (uint256 i =0 ;i < count + 1 ; i++){
//     _safeMint(msg.sender, totalPublicSupply + i);
//     }
//     totalPublicSupply += count;
// }
function mint(uint256 freeCount, uint256 paidCount) external payable {
        require(isMintingOn, 'minting not started');
        uint256 count = freeCount + paidCount;
        // Total
        require(count < MAX_MINT_COUNT, 'Max Mint per Txn exceeded');
        // Free
        require(
            hasUserFreeMinted[msg.sender] == false || freeCount == 0,
            'user already free minted'
        );
        require(freeCount < MAX_FREE_MINT_COUNT, 'free mints exceed count');
        require(
            totalFreeSupply + freeCount < MAX_FREE_SUPPLY,
            'free mints exceed supply'
        );
        // Paid
        require(
            tokenPrice * paidCount == msg.value,
            'Insufficient / Incorrect Funds'
        );
        require(
            totalPublicSupply + count < MAX_SUPPLY,
            'All testnets have already been minted!'
        );

        for (uint256 i = 1; i < count + 1; i++) {
            _safeMint(msg.sender, totalPublicSupply + i);
        }
        totalFreeSupply += freeCount;
        totalPublicSupply += count;
        hasUserFreeMinted[msg.sender] =
            freeCount > 0 &&
            hasUserFreeMinted[msg.sender] == false;
    }
// Solidity 0.4.18
/**
 * Extract 256-bit worth of data from the bytes stream.
 */
function slice32(bytes b, uint offset) constant returns (bytes32) {
    bytes32 out;

    for (uint i = 0; i < 32; i++) {
      out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
    }
    return out;
  }
// Solidity 0.4.18
/**
 * Extract 16-bit worth of data from the bytes stream.
 */
function slice2(bytes b, uint offset) constant returns (bytes2) {
    bytes2 out;

    for (uint i = 0; i < 2; i++) {
      out |= bytes2(b[offset + i] & 0xFF) >> (i * 8);
    }
    return out;
  }
// Solidity 0.4.18
/**
 * Same as above, does not seem to cause any issue.
 */
function getKYCPayload(bytes dataframe) public constant returns(address whitelistedAddress, uint128 customerId, uint32 minEth, uint32 maxEth) {
    address _whitelistedAddress = dataframe.sliceAddress(0);
    uint128 _customerId = uint128(dataframe.slice16(20));
    uint32 _minETH = uint32(dataframe.slice4(36));
    uint32 _maxETH = uint32(dataframe.slice4(40));
    return (_whitelistedAddress, _customerId, _minETH, _maxETH);
  }
// Solidity 0.6.12
// F1 - F10: OK
// C1 - C24: OK
function setBridge(address token, address bridge) external onlyOwner {
        // Checks
        require(
            token != sushi && token != weth && token != bridge,
            "SushiMaker: Invalid bridge"
        );

        // Effects
        _bridges[token] = bridge;
        emit LogBridgeSet(token, bridge);
    }
// Solidity 0.6.12
// F1 - F10: OK, see convert
// C1 - C24: OK
// C3: Loop is under control of the caller
function convertMultiple(
        address[] calldata token0,
        address[] calldata token1
    ) external onlyEOA() {
        // TODO: This can be optimized a fair bit, but this is safer and simpler for now
        uint256 len = token0.length;
        for (uint256 i = 0; i < len; i++) {
            _convert(token0[i], token1[i]);
        }
    }
// Solidity 0.6.12
// F1 - F10: OK
// C1 - C24: OK
// All safeTransfer, swap: X1 - X5: OK
function _swap(
        address fromToken,
        address toToken,
        uint256 amountIn,
        address to
    ) internal returns (uint256 amountOut) {
        // Checks
        // X1 - X5: OK
        IUniswapV2Pair pair =
            IUniswapV2Pair(factory.getPair(fromToken, toToken));
        require(address(pair) != address(0), "SushiMaker: Cannot convert");

        // Interactions
        // X1 - X5: OK
        (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();
        uint256 amountInWithFee = amountIn.mul(997);
        if (fromToken == pair.token0()) {
            amountOut =
                amountInWithFee.mul(reserve1) /
                reserve0.mul(1000).add(amountInWithFee);
            IERC20(fromToken).safeTransfer(address(pair), amountIn);
            pair.swap(0, amountOut, to, new bytes(0));
            // TODO: Add maximum slippage?
        } else {
            amountOut =
                amountInWithFee.mul(reserve0) /
                reserve1.mul(1000).add(amountInWithFee);
            IERC20(fromToken).safeTransfer(address(pair), amountIn);
            pair.swap(amountOut, 0, to, new bytes(0));
            // TODO: Add maximum slippage?
        }
    }
// Solidity 0.5.0
//
// Contract common functions
//
function transfer(address _to, uint256 _value) public returns (bool) {
        //
        require(_to != address(0), "'_to' address has to be set");
        require(_value <= balances[msg.sender], "Insufficient balance");
        //
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        //
        emit Transfer(msg.sender, _to, _value);
        return true;
    }