lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.21
//oraclize callback method
function __callback(bytes32 myid, string result, bytes proof) public {
        require (msg.sender == oraclize_cbAddress());
        require (!chronus.race_end);
        bytes32 coin_pointer; // variable to differentiate different callbacks
        chronus.race_start = true;
        chronus.betting_open = false;
        bettingControllerInstance.remoteBettingClose();
        coin_pointer = oraclizeIndex[myid];

        if (myid == coinIndex[coin_pointer].preOraclizeId) {
            if (coinIndex[coin_pointer].pre > 0) {
            } else if (now >= chronus.starting_time+chronus.betting_duration+ 30 minutes) {
                forceVoidRace();
            } else {
                coinIndex[coin_pointer].pre = stringToUintNormalize(result);
                emit newPriceTicker(coinIndex[coin_pointer].pre);
            }
        } else if (myid == coinIndex[coin_pointer].postOraclizeId){
            if (coinIndex[coin_pointer].pre > 0 ){
                if (coinIndex[coin_pointer].post > 0) {
                } else if (now >= chronus.starting_time+chronus.race_duration+ 30 minutes) {
                    forceVoidRace();
                } else {
                    coinIndex[coin_pointer].post = stringToUintNormalize(result);
                    coinIndex[coin_pointer].price_check = true;
                    emit newPriceTicker(coinIndex[coin_pointer].post);
                    
                    if (coinIndex[horses.ETH].price_check && coinIndex[horses.BTC].price_check && coinIndex[horses.LTC].price_check) {
                        reward();
                    }
                }
            } else {
                forceVoidRace();
            }
        }
    }
// Solidity 0.4.21
// place a bet on a coin(horse) lockBetting
function placeBet(bytes32 horse) external duringBetting payable  {
        require(msg.value >= 0.01 ether);
        if (voterIndex[msg.sender].total_bet==0) {
            total_bettors+=1;
        }
        uint _newAmount = voterIndex[msg.sender].bets[horse] + msg.value;
        voterIndex[msg.sender].bets[horse] = _newAmount;
        voterIndex[msg.sender].total_bet += uint160(msg.value);
        uint160 _newTotal = coinIndex[horse].total + uint160(msg.value); 
        uint32 _newCount = coinIndex[horse].count + 1;
        coinIndex[horse].total = _newTotal;
        coinIndex[horse].count = _newCount;
        emit Deposit(msg.sender, msg.value, horse, now);
    }
// Solidity 0.4.21
// method to calculate an invidual's reward
function calculateReward(address candidate) internal afterRace constant returns(uint winner_reward) {
        voter_info storage bettor = voterIndex[candidate];
        if(chronus.voided_bet) {
            winner_reward = bettor.total_bet;
        } else {
            uint winning_bet_total;
            if(winner_horse[horses.BTC]) {
                winning_bet_total += bettor.bets[horses.BTC];
            } if(winner_horse[horses.ETH]) {
                winning_bet_total += bettor.bets[horses.ETH];
            } if(winner_horse[horses.LTC]) {
                winning_bet_total += bettor.bets[horses.LTC];
            }
            winner_reward += (((total_reward.mul(10000000)).div(winnerPoolTotal)).mul(winning_bet_total)).div(10000000);
        } 
    }
// Solidity 0.4.21
// utility function to convert string to integer with precision consideration
function stringToUintNormalize(string s) internal pure returns (uint result) {
        uint p =2;
        bool precision=false;
        bytes memory b = bytes(s);
        uint i;
        result = 0;
        for (i = 0; i < b.length; i++) {
            if (precision) {p = p-1;}
            if (uint(b[i]) == 46){precision = true;}
            uint c = uint(b[i]);
            if (c >= 48 && c <= 57) {result = result * 10 + (c - 48);}
            if (precision && p == 0){return result;}
        }
        while (p!=0) {
            result = result*10;
            p=p-1;
        }
    }
// Solidity 0.4.25
/**
 * @dev player send crystals to the pot
 */
function share(uint256 _value) public disableContract
    {
        require(games[round].ended == false);
        require(games[round].startTime <= now);
        require(_value >= 1);

        MiningWar.subCrystal(msg.sender, _value); 

        if (games[round].endTime <= now) endRound();
        
        updateReward(msg.sender);
        
        Game storage g = games[round];
        uint256 _share = SafeMath.mul(_value, CRTSTAL_MINING_PERIOD);
        g.crystals = SafeMath.add(g.crystals, _share);
        Player storage p = players[msg.sender];
        if (p.currentRound == round) {
            p.share = SafeMath.add(p.share, _share);
        } else {
            p.share = _share;
            p.currentRound = round;
        }

        emit Deposit(msg.sender, p.currentRound, _value, p.share); 
    }
// Solidity 0.5.17
/**
 @notice Transfers `_value` amount of an `_id` from the `_from` address to the `_to` address specified (with safety call).
 @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
 MUST revert if `_to` is the zero address.
 MUST revert if balance of holder for token `_id` is lower than the `_value` sent.
 MUST revert on any other error.
 MUST emit the `TransferSingle` event to reflect the balance change (see "Safe Transfer Rules" section of the standard).
 After the above conditions are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call `onERC1155Received` on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
 @param _from    Source address
 @param _to      Target address
 @param _id      ID of the token type
 @param _value   Transfer amount
 @param _data    Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to`
 */
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external {

        require(_to != address(0x0), "_to must be non-zero.");
        require(_from == msg.sender || operatorApproval[_from][msg.sender] == true, "Need operator approval for 3rd party transfers.");

        // SafeMath will throw with insuficient funds _from
        // or if _id is not valid (balance will be 0)
        balances[_id][_from] = balances[_id][_from].sub(_value);
        balances[_id][_to]   = _value.add(balances[_id][_to]);

        // MUST emit event
        emit TransferSingle(msg.sender, _from, _to, _id, _value);

        // Now that the balance is updated and the event was emitted,
        // call onERC1155Received if the destination is a contract.
        if (_to.isContract()) {
            _doSafeTransferAcceptanceCheck(msg.sender, _from, _to, _id, _value, _data);
        }
    }
// Solidity 0.5.17
/**
 @notice Get the balance of an account's Tokens.
 @param _owner  The address of the token holder
 @param _id     ID of the Token
 @return        The _owner's balance of the Token type requested
 */
function balanceOf(address _owner, uint256 _id) external view returns (uint256) {
        // The balance of any account can be calculated from the Transfer events history.
        // However, since we need to keep the balances to validate transfer request,
        // there is no extra cost to also privide a querry function.
        return balances[_id][_owner];
    }
// Solidity 0.8.7
/**
 * @notice Allows to mint one NFT if whitelisted
 *
 * @param _account The account of the user minting the NFT
 * @param _proof The Merkle Proof
 **/
function presaleMint(address _account, bytes32[] calldata _proof) external payable nonReentrant {
        //Are we in Presale ?
        require(sellingStep == Steps.Presale, "Presale has not started yet.");
        //Did this account already mint an NFT ?
        require(nftsPerWallet[_account] < 1, "You can only get 10 NFT on the Presale");
        //Is this user on the whitelist ?
        require(isWhiteListed(_account, _proof), "Not on the whitelist");
        //Get the price of one NFT during the Presale
        uint price = pricePresale;
        //Did the user send enought Ethers ?
        require(msg.value >= price, "Not enought funds.");
        //Increment the number of NFTs this user minted
        nftsPerWallet[_account]++;
        //Mint the user NFT
        _safeMint(_account, _nftIdCounter.current());
        //Increment the Id of the next NFT to mint
        _nftIdCounter.increment();
    }
// Solidity 0.8.7
/**
 * @notice Allows to get the complete URI of a specific NFT by his ID
 *
 * @param _nftId The id of the NFT
 *
 * @return The token URI of the NFT which has _nftId Id
 **/
function tokenURI(uint _nftId) public view override(ERC721) returns (string memory) {
        require(_exists(_nftId), "This NFT doesn't exist.");
        if(revealed == false) {
            return notRevealedURI;
        }
        
        string memory currentBaseURI = _baseURI();
        return 
            bytes(currentBaseURI).length > 0 
            ? string(abi.encodePacked(currentBaseURI, _nftId.toString(), baseExtension))
            : "";
    }
// Solidity 0.8.12
/**
 * @dev Returns the owner of the `tokenId` token.
 *
 * Requirements:
 *
 * - `tokenId` must exist.
 */
function ownerOf(uint256 tokenId) public view virtual returns (address) {
        unchecked {
            if (tokenId < _collectionData.index) {
                address ownership = _ownerships[tokenId];
                if (ownership != address(0)) {
                    return ownership;
                }
                    while (true) {
                        tokenId--;
                        ownership = _ownerships[tokenId];

                        if (ownership != address(0)) {
                            return ownership;
                        }
                         
                    }
                }
            }

        revert ();
    }
// Solidity 0.8.12
/**
 * @dev Safely mints `quantity` tokens and transfers them to `to`.
 *
 * Requirements:
 *
 * - `to` cannot be the zero address.
 * - If `to` refers to a smart contract, it must implement {onERC721Received}, which is called for each safe transfer.
 *
 * Emits a {Transfer} event.
 */
function _safeMint(address to, uint256 quantity, bytes memory _data) internal {
        require(to != address(0), "Address 0");
        require(quantity > 0, "Quantity 0");

        unchecked {
            uint256 updatedIndex = _collectionData.index;
            _addressData[to].balance += uint64(quantity);
            _ownerships[updatedIndex] = to;
            
            for (uint256 i; i < quantity; i++) {
                emit Transfer(address(0), to, updatedIndex);
                require(to.code.length == 0 ||
                        ERC721TokenReceiver(to).onERC721Received(_msgSender(), address(0), updatedIndex, _data) ==
                        ERC721TokenReceiver.onERC721Received.selector, "Unsafe Destination");
                updatedIndex++;
            }

            _collectionData.index = updatedIndex;
        }
    }
// Solidity 0.8.12
/**
 * @dev Returns whether `_addressToCheck` is the owner of `quantity` tokens sequentially starting from `startID`.
 *
 * Requirements:
 *
 * - `startID` token and all sequential tokens must exist.
 */
function multiOwnerCheck(address _addressToCheck, uint256 startID, uint256 quantity) internal view returns (bool) {
        require(quantity > 1, "Low Quantity");
        unchecked {
            for (uint256 i; i < quantity; i++) {
                if (ownerOf(startID + i) != _addressToCheck){
                    return false;
                }
            }
        }
        return true;
    }
// Solidity 0.8.12
/**
 * @dev Locks `_owner`'s tokens from any form of transferring.
 * Requirements:
 *
 * - The `caller` cannot have their tokens locked currently.
 *
 * Emits a {Locked} event.
 */
function lock(uint256 _cooldown) public {
        require(!_addressData[_msgSender()].locked, "Tokens currently locked");
        require(_cooldown > 0 && _cooldown < 31, "Invalid Cooldown");
        unchecked {
            uint256 proposedCooldown = _cooldown * 1 days;
            require(block.timestamp + proposedCooldown > _addressData[_msgSender()].lockedUnlockTimestamp, "Proposed cooldown too small");
            _addressData[_msgSender()].locked = true;
            _addressData[_msgSender()].lockedUnlockCooldown = uint64(proposedCooldown);
        }
        emit Locked(_msgSender(), _cooldown);
    }
// Solidity 0.8.12
/**
 * @dev Returns tokenIDs owned by `_owner`.
 */
function tokensOfOwner(address _owner) public view returns (uint256[] memory) {
        uint256 totalOwned = _addressData[_owner].balance;
        require(totalOwned > 0, "balance 0");
        uint256 supply = _collectionData.index;
        uint256[] memory tokenIDs = new uint256[](totalOwned);
        uint256 ownedIndex;
        address currentOwner;

        unchecked {
            for (uint256 i; i < supply; i++) {
                address currentAddress = _ownerships[i];
                if (currentAddress != address(0)) {
                    currentOwner = currentAddress;
                }
                if (currentOwner == _owner) {
                    tokenIDs[ownedIndex++] = i;
                    if (ownedIndex == totalOwned){
                        return tokenIDs;
                    }
                }
            }
        }

        revert();
    }
// Solidity 0.8.12
/**
 * @dev Destroys `tokenIDs`.
 * The approval is cleared when each token is burned.
 *
 * Requirements:
 *
 * - `tokenIDs` must exist.
 * - caller must be Owner or Approved for token usage.
 *
 * Emits a {Transfer} event.
 */
function batchBurn(uint256 startID, uint256 quantity) public {
        address currentOwner = ownerOf(startID);
        require(isUnlocked(currentOwner), "ERC721L: Tokens Locked");
        require(multiOwnerCheck(currentOwner, startID, quantity), "ERC721L: Not Batchable");
        require(_msgSender() == currentOwner || isApprovedForAll(currentOwner, _msgSender()), "ERC721M: Not Approved");
        
        unchecked {
            for (uint256 i; i < quantity; i++) {
                uint256 currentToken = startID + i;
                delete _tokenApprovals[currentToken];

                if (i == 0){
                    _ownerships[currentToken] = address(0x000000000000000000000000000000000000dEaD);
                } else {
                    delete _ownerships[currentToken];
                }
                emit Transfer(currentOwner, address(0x000000000000000000000000000000000000dEaD), currentToken);
            }
            _addressData[currentOwner].balance -= uint64(quantity);
            _collectionData.burned += uint128(quantity);
            uint256 nextTokenId = startID + quantity;
            if (_ownerships[nextTokenId] == address(0) && nextTokenId < _collectionData.index) {
                _ownerships[nextTokenId] = currentOwner;

            }
        }

    }
// Solidity 0.4.24
/**
 * Initialize a new asset
 * @param dataNumber The number of data array
 * @param linkSet The set of URL of the original information for storing data, empty means undisclosed
 *          needle is " "
 * @param encryptionTypeSet The set of encryption method of the original data, such as SHA-256
 *          needle is " "
 * @param hashValueSet The set of hashvalue
 *          needle is " "
 */
function initAsset(
        uint dataNumber,
        string linkSet,
        string encryptionTypeSet,
        string hashValueSet) public onlyHolder {
        // split string to array
        var links = linkSet.toSlice();
        var encryptionTypes = encryptionTypeSet.toSlice();
        var hashValues = hashValueSet.toSlice();
        var delim = " ".toSlice();
        
        dataNum = dataNumber;
        
        // after init, the initAsset function cannot be called
        require(isInit == false, "The contract has been initialized");

        //check data
        require(dataNumber >= 1, "Param dataNumber smaller than 1");
        require(dataNumber - 1 == links.count(delim), "Param linkSet invalid");
        require(dataNumber - 1 == encryptionTypes.count(delim), "Param encryptionTypeSet invalid");
        require(dataNumber - 1 == hashValues.count(delim), "Param hashValueSet invalid");
        
        isInit = true;
        
        var empty = "".toSlice();
        
        for (uint i = 0; i < dataNumber; i++) {
            var link = links.split(delim);
            var encryptionType = encryptionTypes.split(delim);
            var hashValue = hashValues.split(delim);
            
            //require data not null
            // link can be empty
            require(!encryptionType.empty(), "Param encryptionTypeSet data error");
            require(!hashValue.empty(), "Param hashValueSet data error");
            
            dataArray.push(
                data(link.toString(), encryptionType.toString(), hashValue.toString())
                );
        }
    }
// Solidity 0.4.24
/**
 * Get data info by index
 * @param index index of dataArray
 */
function getDataByIndex(uint index) public view returns (string link, string encryptionType, string hashValue) {
        require(isValid == true, "contract invaild");
        require(index >= 0, "Param index smaller than 0");
        require(index < dataNum, "Param index not smaller than dataNum");
        link = dataArray[index].link;
        encryptionType = dataArray[index].encryptionType;
        hashValue = dataArray[index].hashValue;
    }
// Solidity 0.4.24
/**
 * Modify the link of the indexth data to be url
 * @param index index of assetInfo
 * @param url new link
 * Only can be called by holder
 */
function setDataLink(uint index, string url) public onlyHolder {
        require(isValid == true, "contract invaild");
        require(index >= 0, "Param index smaller than 0");
        require(index < dataNum, "Param index not smaller than dataNum");
        dataArray[index].link = url;
    }
// Solidity 0.5.17
// ------------------------------------------------------------------------
// Increment supply
// ------------------------------------------------------------------------
function incrementSupply(uint256 increments) public onlyOwner returns (bool){
    require(increments > 0);
    uint256 curTotalSupply = _totalSupply;
    uint256 previousBalance = balanceOf(msg.sender);
    _totalSupply = curTotalSupply.add(increments);
    balances[msg.sender] = previousBalance.add(increments);
    emit IncrementSupply(msg.sender, increments);
    emit Transfer(address(0), msg.sender, increments);
    return true;
  }
// Solidity 0.5.17
// ------------------------------------------------------------------------
// Burns `amount` tokens from `owner`
// @param amount The quantity of tokens being burned
// @return True if the tokens are burned correctly
// ------------------------------------------------------------------------
function burnTokens(uint256 amount) public onlyOwner returns (bool) {
    require(amount > 0);
    uint256 curTotalSupply = _totalSupply;
    require(curTotalSupply >= amount);
    uint256 previousBalanceTo = balanceOf(msg.sender);
    require(previousBalanceTo >= amount);
    _totalSupply = curTotalSupply.sub(amount);
    balances[msg.sender] = previousBalanceTo.sub(amount);
    emit BurnTokens(msg.sender, amount);
    emit Transfer(msg.sender, address(0), amount);
    return true;
  }
// Solidity 0.5.11
// sets the discount and referral percentages for the current user
// this is deliberately user-customisable
function setSplit(uint8 discount, uint8 referrer) public {
        require(discountLimit >= discount + referrer, "can't give more than the limit");
        require(discount + referrer >= discount, "can't overflow");
        splits[msg.sender] = Split({
            discountPercentage: discount,
            referrerPercentage: referrer,
            set: true
        });
        emit SplitChanged(msg.sender, discount, referrer);
    }
// Solidity 0.5.11
// override a user's split
function overrideSplit(address user, uint8 discount, uint8 referrer) public onlyOwner {
        require(discountLimit >= discount + referrer, "can't give more than the limit");
        require(discount + referrer >= discount, "can't overflow");
        splits[user] = Split({
            discountPercentage: discount,
            referrerPercentage: referrer,
            set: true
        });
        emit SplitChanged(user, discount, referrer);
    }
// Solidity 0.5.11
// sets the default discount and referral percentages
function setDefaults(uint _discount, uint _refer) public onlyOwner {
        require(discountLimit >= _discount + _refer, "can't be more than the limit");
        require(_discount + _refer >= _discount, "can't overflow");
        defaultDiscount = _discount;
        defaultRefer = _refer;
    }
// Solidity 0.5.11
// gets the discount and referral rates for a particular user
function getSplit(address user) public view returns (uint8 discount, uint8 referrer) {
        if (user == address(0)) {
            return (0, 0);
        }
        Split memory s = splits[user];
        if (!s.set) {
            return (uint8(defaultDiscount), uint8(defaultRefer));
        }
        return (s.discountPercentage, s.referrerPercentage);
    }
// Solidity 0.5.11
// get the amount of the purchase which will be allocated to
// the vault and to the referrer
function getAllocations(uint cost, uint items, address referrer) public view returns (uint toVault, uint toReferrer) {
        uint8 discount;
        uint8 refer;
        (discount, refer) = referrals.getSplit(referrer);
        require(discount + refer <= 100 && discount + refer >= discount, "invalid referral split");
        // avoid overflow
        uint total = cost.mul(items);
        uint8 vaultPercentage = 100 - discount - refer;
        toVault = getPercentage(total, vaultPercentage);
        toReferrer = getPercentage(total, refer);
        uint discountedTotal = getPercentage(total, 100 - discount);
        require(discountedTotal == toVault.add(toReferrer), "not all funds allocated");
        return (toVault, toReferrer);
    }