lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 	 * @notice Enumerate PixelCon in collection #`(_collectionIndex)`
 	 * @dev Throws if the collection does not exist or index is out of bounds
 	 * @param _collectionIndex Collection index
 	 * @param _index Counter less than `collectionTotal(_collection)`
 	 * @return PixelCon ID for the `(_index)`th PixelCon in collection #`(_collectionIndex)`
 	 */
function tokenOfCollectionByIndex(uint64 _collectionIndex, uint256 _index) public view validIndex(_collectionIndex) returns(uint256)
	{
		require(_collectionIndex < totalCollections(), "Collection does not exist");
		require(_index < collectionTokens[_collectionIndex].length, "Index is out of bounds");
		PixelCon storage pixelcon = pixelcons[collectionTokens[_collectionIndex][_index]];
		return pixelcon.tokenId;
	}
// Solidity 0.4.24
/**
 	 * @notice Get the basic data for the given PixelCon indexes
 	 * @dev This function is for web3 calls only, as it returns a dynamic array
 	 * @param _tokenIndexes List of PixelCon indexes
 	 * @return All PixelCon basic data
 	 */
function getBasicData(uint64[] _tokenIndexes) public view returns(uint256[], bytes8[], address[], uint64[])
	{
		uint256[] memory tokenIds = new uint256[](_tokenIndexes.length);
		bytes8[] memory names = new bytes8[](_tokenIndexes.length);
		address[] memory owners = new address[](_tokenIndexes.length);
		uint64[] memory collectionIdxs = new uint64[](_tokenIndexes.length);

		for (uint i = 0; i < _tokenIndexes.length; i++)	{
			uint64 tokenIndex = _tokenIndexes[i];
			require(tokenIndex < totalSupply(), "PixelCon index is out of bounds");

			tokenIds[i] = pixelcons[tokenIndex].tokenId;
			names[i] = pixelconNames[tokenIndex];
			owners[i] = tokenLookup[pixelcons[tokenIndex].tokenId].owner;
			collectionIdxs[i] = pixelcons[tokenIndex].collectionIndex;
		}
		return (tokenIds, names, owners, collectionIdxs);
	}
// Solidity 0.5.0
/**
 * @dev Increase total supply (mint) to an address with deposit
 *
 * @param _value The amount of tokens to be mint
 * @param _to The address which will receive token
 * @param _deposit The amount of deposit
 */
function increaseSupplyWithDeposit(uint256 _value, address _to, uint256 _deposit) external
        onlyOwner
        onlyActive(_to)
        returns (bool)
    {
        require(0 < _value, "StableCoin.increaseSupplyWithDeposit: Zero value");
        require(_deposit <= _value, "StableCoin.increaseSupplyWithDeposit: Insufficient deposit");

        totalSupply = totalSupply.add(_value);
        balances[_to] = balances[_to].add(_value);
        freezeWithPurposeCode(_to, _deposit, encodePacked("InitialDeposit"));
        emit Transfer(address(0), _to, _value.sub(_deposit));
        return true;
    }
// Solidity 0.5.0
/**
 * @dev Decrease total supply (burn) from an address that gave allowance
 *
 * @param _value The amount of tokens to be burn
 * @param _from The address's token will be burn
 */
function decreaseSupply(uint256 _value, address _from) external
        onlyOwner
        onlyActive(_from)
        returns (bool)
    {
        require(0 < _value, "StableCoin.decreaseSupply: Zero value");
        require(_value <= balances[_from], "StableCoin.decreaseSupply: Insufficient fund");
        require(_value <= allowed[_from][address(0)], "StableCoin.decreaseSupply: Insufficient allowance");

        totalSupply = totalSupply.sub(_value);
        balances[_from] = balances[_from].sub(_value);
        allowed[_from][address(0)] = allowed[_from][address(0)].sub(_value);
        emit Transfer(_from, address(0), _value);
        return true;
    }
// Solidity 0.5.0
/**
 * @dev Freeze holder balance
 *
 * @param _from The address which will be freeze
 * @param _value The amount of tokens to be freeze
 */
function freeze(address _from, uint256 _value) external
        onlyOwner
        returns (bool)
    {
        require(_value <= balances[_from], "StableCoin.freeze: Insufficient fund");

        balances[_from] = balances[_from].sub(_value);
        freezeOf[_from] = freezeOf[_from].add(_value);
        freezes[_from][FREEZE_CODE_DEFAULT] = freezes[_from][FREEZE_CODE_DEFAULT].add(_value);
        emit Freeze(_from, _value);
        emit FreezeWithPurpose(_from, _value, FREEZE_CODE_DEFAULT);
        return true;
    }
// Solidity 0.5.0
/**
 * @dev Freeze holder balance with purpose code
 *
 * @param _from The address which will be freeze
 * @param _value The amount of tokens to be freeze
 * @param _purposeCode The purpose code of freeze
 */
function freezeWithPurposeCode(address _from, uint256 _value, bytes32 _purposeCode) public
        onlyOwner
        returns (bool)
    {
        require(_value <= balances[_from], "StableCoin.freezeWithPurposeCode: Insufficient fund");

        balances[_from] = balances[_from].sub(_value);
        freezeOf[_from] = freezeOf[_from].add(_value);
        freezes[_from][_purposeCode] = freezes[_from][_purposeCode].add(_value);
        emit Freeze(_from, _value);
        emit FreezeWithPurpose(_from, _value, _purposeCode);
        return true;
    }
// Solidity 0.4.24
/**
 	 * @notice Get the names of all PixelCons from index `(_startIndex)` to `(_endIndex)`
 	 * @dev This function is for web3 calls only, as it returns a dynamic array
 	 * @return The names of the PixelCons in the given range
 	 */
function getNamesInRange(uint64 _startIndex, uint64 _endIndex) public view returns(bytes8[])
	{
		require(_startIndex <= totalSupply(), "Start index is out of bounds");
		require(_endIndex <= totalSupply(), "End index is out of bounds");
		require(_startIndex <= _endIndex, "End index is less than the start index");

		uint64 length = _endIndex - _startIndex;
		bytes8[] memory names = new bytes8[](length);
		for (uint i = 0; i < length; i++)	{
			names[i] = pixelconNames[_startIndex + i];
		}
		return names;
	}
// Solidity 0.4.24
/**
 	 * @notice Approve `(_to)` to transfer PixelCon `(_tokenId)` (zero indicates no approved address)
 	 * @dev Throws if not called by the owner or an approved operator
 	 * @param _to Address to be approved
 	 * @param _tokenId ID of the token to be approved
 	 */
function approve(address _to, uint256 _tokenId) public validId(_tokenId)
	{
		address owner = tokenLookup[_tokenId].owner;
		require(_to != owner, "Cannot approve PixelCon owner");
		require(msg.sender == owner || operatorApprovals[owner][msg.sender], "Sender does not have permission to approve address");

		tokenApprovals[_tokenId] = _to;
		emit Approval(owner, _to, _tokenId);
	}
// Solidity 0.5.0
/**
 * @dev Allocate allowance and perform contract call
 *
 * @param _spender The spender address
 * @param _value The allowance value
 * @param _extraData The function call data
 */
function approveAndCall(address _spender, uint256 _value, bytes calldata _extraData) external
        isUsable
        returns (bool)
    {
        // Give allowance to spender (previous approved allowances will be clear)
        approve(_spender, _value);

        ApprovalReceiver(_spender).receiveApproval(msg.sender, _value, address(this), _extraData);
        return true;
    }
// Solidity 0.7.3
/**
 * @notice Performs an update of the tuple (count, mean, m2) using the new value
 * @param curCount is the current value for count
 * @param curMean is the current value for mean
 * @param curM2 is the current value for M2
 * @param newValue is the new value to be added into the dataset
 */
function update(
        uint256 curCount,
        int256 curMean,
        uint256 curM2,
        int256 newValue
    )
        internal
        pure
        returns (
            uint256 count,
            int256 mean,
            uint256 m2
        )
    {
        int256 _count = int256(curCount + 1);
        int256 delta = newValue.sub(int256(curMean));
        int256 _mean = int256(curMean).add(delta.div(_count));
        int256 delta2 = newValue.sub(_mean);
        int256 _m2 = int256(curM2).add(delta.mul(delta2));

        require(_count > 0, "count<=0");
        require(_m2 >= 0, "m2<0");

        count = uint256(_count);
        mean = _mean;
        m2 = uint256(_m2);
    }
// Solidity 0.4.19
/**
 * Fallback function
 *
 * The function without name is the default function that is called whenever anyone sends funds to a contract
 */
function () payable {
        require(!crowdsaleClosed);
        uint256 bonus;
        uint256 amount = msg.value;
        balanceOf[msg.sender] = balanceOf[msg.sender].add(amount);
        amountRaised = amountRaised.add(amount);
        
        //add bounus for funders
        if(now >= startdate && now <= startdate + 24 hours ){
            amount =  amount.div(price);
            bonus = amount.mul(30).div(100);
            amount = amount.add(bonus);
        }
        else if(now > startdate + 24 hours && now <= startdate + 24 hours + 1 weeks ){
            amount =  amount.div(price);
            bonus = amount.mul(20).div(100);
            amount = amount.add(bonus);
        }
        else if(now > startdate + 24 hours + 1 weeks && now <= startdate + 24 hours + 3 weeks ){
            amount =  amount.div(price);
            bonus = amount.mul(10).div(100);
            amount = amount.add(bonus);
        } else {
            amount =  amount.div(price);
        }
        
        amount = amount.mul(100000000);
        tokenReward.transfer(msg.sender, amount);
        //FundTransfer(msg.sender, amount, true);
    }
// Solidity 0.4.24
/**
 	 * @notice Transfer the ownership of PixelCon `(_tokenId)` to `(_to)` (try to use 'safeTransferFrom' instead)
 	 * @dev Throws if the sender is not the owner, approved, or operator
 	 * @param _from Current owner
 	 * @param _to Address to receive the PixelCon
 	 * @param _tokenId ID of the PixelCon to be transferred
 	 */
function transferFrom(address _from, address _to, uint256 _tokenId) public validAddress(_from) validAddress(_to) validId(_tokenId)
	{
		require(isApprovedOrOwner(msg.sender, _tokenId), "Sender does not have permission to transfer PixelCon");
		clearApproval(_from, _tokenId);
		removeTokenFrom(_from, _tokenId);
		addTokenTo(_to, _tokenId);

		emit Transfer(_from, _to, _tokenId);
	}
// Solidity 0.4.24
/**
 	 * @notice Get a distinct Uniform Resource Identifier (URI) for PixelCon `(_tokenId)`
 	 * @dev Throws if the given PixelCon does not exist
 	 * @return PixelCon URI
 	 */
function tokenURI(uint256 _tokenId) public view returns(string)
	{
		TokenLookup storage lookupData = tokenLookup[_tokenId];
		require(lookupData.owner != address(0), "PixelCon does not exist");
		PixelCon storage pixelcon = pixelcons[lookupData.tokenIndex];
		bytes8 pixelconName = pixelconNames[lookupData.tokenIndex];

		//Available values: <tokenId>, <tokenIndex>, <name>, <owner>, <creator>, <dateCreated>, <collectionIndex>

		//start with the token URI template and replace in the appropriate values
		string memory finalTokenURI = tokenURITemplate;
		finalTokenURI = StringUtils.replace(finalTokenURI, "<tokenId>", StringUtils.toHexString(_tokenId, 32));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<tokenIndex>", StringUtils.toHexString(uint256(lookupData.tokenIndex), 8));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<name>", StringUtils.toHexString(uint256(pixelconName), 8));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<owner>", StringUtils.toHexString(uint256(lookupData.owner), 20));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<creator>", StringUtils.toHexString(uint256(pixelcon.creator), 20));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<dateCreated>", StringUtils.toHexString(uint256(pixelcon.dateCreated), 8));
		finalTokenURI = StringUtils.replace(finalTokenURI, "<collectionIndex>", StringUtils.toHexString(uint256(pixelcon.collectionIndex), 8));

		return finalTokenURI;
	}
// Solidity 0.4.24
/**
 	 * @notice Check whether the given editor is the current owner and original creator of a given token ID
 	 * @param _address Address to check for
 	 * @param _tokenId ID of the token to be edited
 	 * @return True if the editor is approved for the given token ID, is an operator of the owner, or is the owner of the token
 	 */
function isCreatorAndOwner(address _address, uint256 _tokenId) internal view returns(bool)
	{
		TokenLookup storage lookupData = tokenLookup[_tokenId];
		address owner = lookupData.owner;
		address creator = pixelcons[lookupData.tokenIndex].creator;

		return (_address == owner && _address == creator);
	}
// Solidity 0.4.24
/**
 	 * @notice Check whether the given spender can transfer a given token ID
 	 * @dev Throws if the PixelCon does not exist
 	 * @param _address Address of the spender to query
 	 * @param _tokenId ID of the token to be transferred
 	 * @return True if the spender is approved for the given token ID, is an operator of the owner, or is the owner of the token
 	 */
function isApprovedOrOwner(address _address, uint256 _tokenId) internal view returns(bool)
	{
		address owner = tokenLookup[_tokenId].owner;
		require(owner != address(0), "PixelCon does not exist");
		return (_address == owner || tokenApprovals[_tokenId] == _address || operatorApprovals[owner][_address]);
	}
// Solidity 0.8.11
/*
 	 * @dev function to buy tokens. 
 	 * @param _amount how much tokens can be bought.
 	 */
function buyBatch(uint _amount) external payable {
		require(block.timestamp >= START_TIME, "sale is not started yet");
		require(tokensSold + _amount <= MAX_NFT_TO_SELL, "exceed sell limit");
		require(_amount > 0, "empty input");
		require(_amount <= MAX_UNITS_PER_TRANSACTION, "exceed MAX_UNITS_PER_TRANSACTION");

		uint totalPrice = SALE_PRICE * _amount;
		require(msg.value >= totalPrice, "too low value");
		if(msg.value > totalPrice) {
			//send the rest back
			(bool sent, ) = payable(msg.sender).call{value: msg.value - totalPrice}("");
        	require(sent, "Failed to send Ether");
		}
		
		tokensSold += _amount;
		nft.mintBatch(msg.sender, _amount);		
	}
// Solidity 0.8.4
/**
 * @dev Mints yourself NFTs.
 */
function mintNFTs(uint256 count) external payable {
        require(saleIsActive, "Sale must be active to mint");
        require(totalSupply() < MAX_NFT_SUPPLY, "Sale has already ended");
        require(count > 0, "numberOfNfts cannot be 0");
        require(count <= 20, "You may not buy more than 20 NFTs at once");
        require(
            SafeMath.add(totalSupply(), count) <= MAX_NFT_SUPPLY,
            "Exceeds MAX_NFT_SUPPLY"
        );
        require(
            SafeMath.mul(getNFTPrice(), count) == msg.value,
            "Ether value sent is not correct"
        );

        for (uint256 i = 0; i < count; i++) {
            uint256 mintIndex = totalSupply();
            if (mintIndex < MAX_NFT_SUPPLY) {
                _safeMint(msg.sender, mintIndex);
            }
        }

        // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
        // the end of pre-sale, set the starting index block
        if (
            startingIndexBlock == 0 &&
            (totalSupply() == MAX_NFT_SUPPLY ||
                block.timestamp >= REVEAL_TIMESTAMP)
        ) {
            startingIndexBlock = block.number;
        }
    }
// Solidity 0.8.4
/**
 * Set the starting index for the collection
 */
function setStartingIndex() external {
        require(startingIndex == 0, "Starting index is already set");
        require(startingIndexBlock != 0, "Starting index block must be set");

        startingIndex = uint256(blockhash(startingIndexBlock)) % MAX_NFT_SUPPLY;
        // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes)
        if (block.number.sub(startingIndexBlock) > 255) {
            startingIndex =
                uint256(blockhash(block.number - 1)) %
                MAX_NFT_SUPPLY;
        }
        // Prevent default sequence
        if (startingIndex == 0) {
            startingIndex = startingIndex.add(1);
        }
    }
// Solidity 0.5.17
//event DebugTest2(uint allowance,uint from,address sender);
function _transferFrom(address _operator, address _from, address _to, uint256 _value, bool _payFee) internal {
        if (_value == 0) {
            emit Transfer(_from, _to, 0);
            return;
        }

        uint256 balanceFrom = _balanceOf(_from);
        require(balanceFrom >= _value, "balance not enough");

        if (_from != _operator) {
            uint256 allowanceFrom = _allowance(_from, _operator);
            if (allowanceFrom != uint(-1)) {
                //emit DebugTest2(allowanceFrom,_value,_operator);
                require(allowanceFrom >= _value, "allowance not enough");
                _setAllowance(_from, _operator, allowanceFrom.sub(_value));
            }
        }

        uint256
// Solidity 0.4.24
/**
 	 * @dev Replaces the given key with the given value in the given string
 	 * @param _str String to find and replace in
 	 * @param _key Value to search for
 	 * @param _value Value to replace key with
 	 * @return The replaced string
 	 */
function replace(string _str, string _key, string _value) internal pure returns(string)
	{
		bytes memory bStr = bytes(_str);
		bytes memory bKey = bytes(_key);
		bytes memory bValue = bytes(_value);

		uint index = indexOf(bStr, bKey);
		if (index < bStr.length) {
			bytes memory rStr = new bytes((bStr.length + bValue.length) - bKey.length);

			uint i;
			for (i = 0; i < index; i++) rStr[i] = bStr[i];
			for (i = 0; i < bValue.length; i++) rStr[index + i] = bValue[i];
			for (i = 0; i < bStr.length - (index + bKey.length); i++) rStr[index + bValue.length + i] = bStr[index + bKey.length + i];

			return string(rStr);
		}
		return string(bStr);
	}
// Solidity 0.4.24
/**
 	 * @dev Converts a given number into a string with hex representation
 	 * @param _num Number to convert
 	 * @param _byteSize Size of the number in bytes
 	 * @return The hex representation as string
 	 */
function toHexString(uint256 _num, uint _byteSize) internal pure returns(string)
	{
		bytes memory s = new bytes(_byteSize * 2 + 2);
		s[0] = 0x30;
		s[1] = 0x78;
		for (uint i = 0; i < _byteSize; i++) {
			byte b = byte(uint8(_num / (2 ** (8 * (_byteSize - 1 - i)))));
			byte hi = byte(uint8(b) / 16);
			byte lo = byte(uint8(b) - 16 * uint8(hi));
			s[2 + 2 * i] = char(hi);
			s[3 + 2 * i] = char(lo);
		}
		return string(s);
	}
// Solidity 0.4.24
/**
 	 * @dev Gets the index of the key string in the given string
 	 * @param _str String to search in
 	 * @param _key Value to search for
 	 * @return The index of the key in the string (string length if not found)
 	 */
function indexOf(bytes _str, bytes _key) internal pure returns(uint)
	{
		for (uint i = 0; i < _str.length - (_key.length - 1); i++) {
			bool matchFound = true;
			for (uint j = 0; j < _key.length; j++) {
				if (_str[i + j] != _key[j]) {
					matchFound = false;
					break;
				}
			}
			if (matchFound) {
				return i;
			}
		}
		return _str.length;
	}
// Solidity 0.4.18
/**
 * Upgrader upgrade tokens of holder to a new smart contract.
 * @param _holders List of token holder.
 */
function forceUpgrade(address[] _holders)
        public
        onlyUpgradeMaster
        canUpgrade
    {
        uint amount;

        for (uint i = 0; i < _holders.length; i++) {
            amount = balanceOf[_holders[i]];

            if (amount == 0) {
                continue;
            }

            processUpgrade(_holders[i], amount);
        }
    }
// Solidity 0.4.18
/**
 * @dev Constructor
 */
function QNTU(address[] _wallets, uint[] _amount)
        public
    {
        require(_wallets.length == _amount.length);

        symbol = "QNTU";
        name = "QNTU Token";
        decimals = 18;

        uint num = 0;
        uint length = _wallets.length;
        uint multiplier = 10 ** uint(decimals);

        for (uint i = 0; i < length; i++) {
            num = _amount[i] * multiplier;

            balanceOf[_wallets[i]] = num;
            Transfer(0, _wallets[i], num);

            totalSupply += num;
        }
    }
// Solidity 0.5.11
/**
 @dev returns the product of multiplying _x by _y, asserts if the calculation overflows
 
 @param _x   factor 1
 @param _y   factor 2
 
 @return product
 */
function safeMul(uint256 _x, uint256 _y) internal pure returns (uint256) {
        uint256 z = _x * _y;
        require(_x == 0 || z / _x == _y);        //assert(_x == 0 || z / _x == _y);
        return z;
    }
// Solidity 0.5.11
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) public returns (bool success) {
	    require(_value > 0 );                                          // Check send token value > 0;
		require(balances[msg.sender] >= _value);                       // Check if the sender has enough
        require(balances[_to] + _value > balances[_to]);               // Check for overflows											
    	balances[msg.sender] = safeSub(balances[msg.sender], _value);  // Subtract from the sender
		balances[_to]  = safeAdd(balances[_to], _value);               // Add the same to the recipient                       
	    if(_to == address(0)) {
	        _burn(_to, _value);
	    }
	
		emit Transfer(msg.sender, _to, _value); 			       // Notify anyone listening that this transfer took place
		return true;      
	}
// Solidity 0.5.11
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
	  
	    require(balances[_from] >= _value);                 // Check if the sender has enough
        require(balances[_to] + _value >= balances[_to]);   // Check for overflows
        require(_value <= allowed[_from][msg.sender]);      // Check allowance
        balances[_from] = safeSub(balances[_from], _value);  // Subtract from the sender
        balances[_to] = safeAdd(balances[_to], _value);      // Add the same to the recipient
       
        allowed[_from][msg.sender] = safeSub(allowed[_from][msg.sender], _value);
        
        if(_to == address(0)) {
	        _burn(_to, _value);
	    }
        
        emit Transfer(_from, _to, _value);
        return true;
	}
// Solidity 0.5.16
/**
 * @dev Multiplies two numbers, returns an error on overflow.
 */
function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (a == 0) {
            return (MathError.NO_ERROR, 0);
        }

        uint c = a * b;

        if (c / a != b) {
            return (MathError.INTEGER_OVERFLOW, 0);
        } else {
            return (MathError.NO_ERROR, c);
        }
    }
// Solidity 0.5.16
/**
 * @dev Adds two numbers, returns an error on overflow.
 */
function addUInt(uint a, uint b) internal pure returns (MathError, uint) {
        uint c = a + b;

        if (c >= a) {
            return (MathError.NO_ERROR, c);
        } else {
            return (MathError.INTEGER_OVERFLOW, 0);
        }
    }
// Solidity 0.5.16
/**
 * @dev add a and b and then subtract c
 */
function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {
        (MathError err0, uint sum) = addUInt(a, b);

        if (err0 != MathError.NO_ERROR) {
            return (err0, 0);
        }

        return subUInt(sum, c);
    }