lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.11
/// Returns whether a section is available for purchase as a market sale
function sectionForSale(
        uint _section_index
    ) returns (bool) {
        if (_section_index >= sections.length) throw;
        Section s = sections[_section_index];
        // Has the user set the section as for_sale
        if(s.for_sale)
        {
            // Has the owner set a "sell only to" address?
            if(s.sell_only_to == 0x0) return true;
            if(s.sell_only_to == msg.sender) return true;
            return false;
        }
        else
        {
            // Not for sale
            return false;
        }
    }
// Solidity 0.4.11
/// Set an inidividual section as for sale at the provided price in wei.
/// The section will be available for purchase by any address.
function setSectionForSale(
        uint _section_index,
        uint256 _price
    ) {
        if (_section_index >= sections.length) throw;
        Section section = sections[_section_index];
        if(section.owner != msg.sender) throw;
        section.price = _price;
        section.for_sale = true;
        section.sell_only_to = 0x0;
        NewListing(_section_index, _price);
    }
// Solidity 0.4.19
/**
 * @notice Constructor for contract. Sets token and beneficiary addresses.
 * @param _token token address - supposed to be DGTX address
 * @param _beneficiary recipient of received ethers
 */
function Auction(address _token, address _beneficiary, uint _startTime, uint _maxBidInCentsPerAddress)
            public
            payable
            Ownable()
    {
        require(_token != address(0));
        require(_beneficiary != address(0));
        require(_startTime > now);
        require(_maxBidInCentsPerAddress > 0);
        token = _token;
        beneficiary = _beneficiary;
        startTime = _startTime;
        endTime = startTime + 30 days;
        maxBidInCentsPerAddress = _maxBidInCentsPerAddress;
    }
// Solidity 0.4.19
/**
 * @notice Fallback function.
 * During the auction receives and remembers participants bids.
 * After the sale is finished, withdraws tokens to participants.
 * It is not allowed to bid from contract (e.g., multisig).
 */
function () public payable {
        if (msg.sender == owner) {
            return;
        }
        require(now >= startTime);
        require(!isContract(msg.sender));

        if (!hasEnded()) {
            require(msg.value >= TRANSACTION_MIN_IN_ETH);
            bid(msg.sender, msg.value);
        } else {
            require(!withdrawn[msg.sender]);
            require(centsReceived[msg.sender] != 0);
            withdrawTokens(msg.sender);
            msg.sender.transfer(msg.value);
        }
    }
// Solidity 0.4.19
/**
 * @notice Get current price: dgtx to cents.
 * 25 cents in the beginning and linearly decreases by 1 cent every hour until it reaches 1 cent.
 * @return current token to cents price
 */
function getPrice() public view returns (uint) {
        if (now < startTime) {
            return START_PRICE_IN_CENTS;
        }
        uint passedHours = (now - startTime) / 1 hours;
        return (passedHours >= 24) ? MIN_PRICE_IN_CENTS : (25 - passedHours);
    }
// Solidity 0.4.19
/**
 * @notice Function to receive transaction from oracle with new ETH rate.
 * @dev Calls updateEthToCentsRate in one hour (starts update cycle)
 * @param result string with new rate
 */
function __callback(bytes32, string result) public {
        require(msg.sender == oraclize_cbAddress());
        uint newEthToCents = parseInt(result, 2); // convert string to cents
        if (newEthToCents > 0) {
            ethToCents = newEthToCents;
            EthToCentsUpdated(ethToCents);
        } 
        if (!hasEnded()) {
            updateEthToCentsRate(1 hours);
        }
    }
// Solidity 0.4.19
/**
 * @notice Function to transfer tokens to participants in the range [_from, _to).
 * @param _from starting index in the range of participants to withdraw to
 * @param _to index after the last participant to withdraw to
 */
function distributeTokensRange(uint _from, uint _to) public {
        require(hasEnded());
        require(_from < _to && _to <= participants.length);

        address recipient;
        for (uint i = _from; i < _to; ++i) {
            recipient = participants[i];
            if (!withdrawn[recipient]) {
                withdrawTokens(recipient);
            }
        }
    }
// Solidity 0.4.19
/**
 * @dev Function which records bids.
 * @param _bidder is the address that bids
 * @param _valueETH is value of THE bid in ether
 */
function bid(address _bidder, uint _valueETH) internal {
        uint price = getPrice();
        uint bidInCents = _valueETH * ethToCents / 1 ether;

        uint centsToAccept = bidInCents;
        uint ethToAccept = _valueETH;

        // Refund any ether above address bid limit
        if (centsReceived[_bidder] + centsToAccept > maxBidInCentsPerAddress) {
            centsToAccept = maxBidInCentsPerAddress - centsReceived[_bidder];
            ethToAccept = centsToAccept * 1 ether / ethToCents;
        }

        // Refund bid part which more than total tokens cost
        if (totalCentsCollected + centsToAccept > price * totalTokens / TOKEN_DECIMALS_MULTIPLIER) {
            centsToAccept = price * totalTokens / TOKEN_DECIMALS_MULTIPLIER - totalCentsCollected;
            ethToAccept = centsToAccept * 1 ether / ethToCents;
        }

        require(centsToAccept > 0 && ethToAccept > 0);

        if (centsReceived[_bidder] == 0) {
            participants.push(_bidder);
        }

        centsReceived[_bidder] += centsToAccept;
        totalCentsCollected += centsToAccept;
        Bid(_bidder, centsToAccept);

        if (ethToAccept < _valueETH) {
            _bidder.transfer(_valueETH - ethToAccept);
        }
        beneficiary.transfer(ethToAccept);
    }
// Solidity 0.4.19
/**
 * @dev Internal function to withdraw tokens by final price.
 * @param _recipient participant to withdraw
 */
function withdrawTokens(address _recipient) internal {
        uint256 tokens = 0;
        if (totalCentsCollected < totalTokens * MIN_PRICE_IN_CENTS / TOKEN_DECIMALS_MULTIPLIER) {
            tokens = centsReceived[_recipient] * TOKEN_DECIMALS_MULTIPLIER / MIN_PRICE_IN_CENTS;
        } else {
            tokens = centsReceived[_recipient] * totalTokens / totalCentsCollected;
        }
        withdrawn[_recipient] = true;
        ERC223(token).transfer(_recipient, tokens);
        TokensWithdraw(_recipient, tokens);
    }
// Solidity 0.4.11
/// Set a section region for sale at the provided price in wei.
/// The sections in the region will be available for purchase by any address.
function setRegionForSale(
        uint _start_section_index,
        uint _end_section_index,
        uint _price
    ) {
        if(_start_section_index > _end_section_index) throw;
        if(_end_section_index > 9999) throw;
        uint x_pos = _start_section_index % 100;
        uint base_y_pos = (_start_section_index - (_start_section_index % 100)) / 100;
        uint x_max = _end_section_index % 100;
        uint y_max = (_end_section_index - (_end_section_index % 100)) / 100;
        while(x_pos <= x_max)
        {
            uint y_pos = base_y_pos;
            while(y_pos <= y_max)
            {
                Section section = sections[x_pos + (y_pos * 100)];
                if(section.owner == msg.sender)
                {
                    section.price = _price;
                    section.for_sale = true;
                    section.sell_only_to = 0x0;
                    NewListing(x_pos + (y_pos * 100), _price);
                }
                y_pos++;
            }
            x_pos++;
        }
    }
// Solidity 0.4.11
/// Set a section region starting in the top left at the supplied start section
/// index to and including the supplied bottom right end section index
/// for sale at the provided price in wei, to the provided address.
/// The sections in the region will be available for purchase only by the
/// provided address.
function setRegionForSaleToAddress(
        uint _start_section_index,
        uint _end_section_index,
        uint _price,
        address _only_sell_to
    ) {
        if(_start_section_index > _end_section_index) throw;
        if(_end_section_index > 9999) throw;
        uint x_pos = _start_section_index % 100;
        uint base_y_pos = (_start_section_index - (_start_section_index % 100)) / 100;
        uint x_max = _end_section_index % 100;
        uint y_max = (_end_section_index - (_end_section_index % 100)) / 100;
        while(x_pos <= x_max)
        {
            uint y_pos = base_y_pos;
            while(y_pos <= y_max)
            {
                Section section = sections[x_pos + (y_pos * 100)];
                if(section.owner == msg.sender)
                {
                    section.price = _price;
                    section.for_sale = true;
                    section.sell_only_to = _only_sell_to;
                    NewListing(x_pos + (y_pos * 100), _price);
                }
                y_pos++;
            }
            x_pos++;
        }
    }
// Solidity 0.4.11
/// Update a region of sections' cloud image_id and md5 to be redrawn on the
/// map starting at the top left start section index to and including the
/// bottom right section index. Fires a NewImage event with the top left
/// section index. If any sections not owned by the sender are in the region
/// they are ignored.
function setRegionImageDataCloud(
        uint _start_section_index,
        uint _end_section_index,
        uint _image_id,
        string _md5
    ) {
        if (_end_section_index < _start_section_index) throw;
        var (start_x, start_y) = getIdentifierFromSectionIndex(_start_section_index);
        var (end_x, end_y) = getIdentifierFromSectionIndex(_end_section_index);
        if (start_x >= mapWidth) throw;
        if (start_y >= mapHeight) throw;
        if (end_x >= mapWidth) throw;
        if (end_y >= mapHeight) throw;
        uint y_pos = start_y;
        while (y_pos <= end_y)
        {
            uint x_pos = start_x;
            while (x_pos <= end_x)
            {
                uint identifier = (x_pos + (y_pos * 100));
                Section s = sections[identifier];
                if(s.owner == msg.sender)
                {
                    s.image_id = _image_id;
                    s.md5 = _md5;
                }
                x_pos = x_pos + 1;
            }
            y_pos = y_pos + 1;
        }
        NewImage(_start_section_index);
        return;
    }
// Solidity 0.4.11
/// Set a single section as for sale at the provided price in wei only
/// to the supplied address.
function setSectionForSaleToAddress(
        uint _section_index,
        uint256 _price,
        address _to
    ) {
        if (_section_index >= sections.length) throw;
        Section section = sections[_section_index];
        if(section.owner != msg.sender) throw;
        section.price = _price;
        section.for_sale = true;
        section.sell_only_to = _to;
        NewListing(_section_index, _price);
    }
// Solidity 0.4.11
/// Delist a region of sections for sale. Making the sections no longer
/// no longer available on the market.
function unsetRegionForSale(
        uint _start_section_index,
        uint _end_section_index
    ) {
        if(_start_section_index > _end_section_index) throw;
        if(_end_section_index > 9999) throw;
        uint x_pos = _start_section_index % 100;
        uint base_y_pos = (_start_section_index - (_start_section_index % 100)) / 100;
        uint x_max = _end_section_index % 100;
        uint y_max = (_end_section_index - (_end_section_index % 100)) / 100;
        while(x_pos <= x_max)
        {
            uint y_pos = base_y_pos;
            while(y_pos <= y_max)
            {
                Section section = sections[x_pos + (y_pos * 100)];
                if(section.owner == msg.sender)
                {
                    section.for_sale = false;
                    section.price = 0;
                    Delisted(x_pos + (y_pos * 100));
                }
                y_pos++;
            }
            x_pos++;
        }
    }
// Solidity 0.4.11
/// Depreciated. Store the raw image data in the contract.
function setImageData(
        uint _section_index
        // bytes32 _row_zero,
        // bytes32 _row_one,
        // bytes32 _row_two,
        // bytes32 _row_three,
        // bytes32 _row_four,
        // bytes32 _row_five,
        // bytes32 _row_six,
        // bytes32 _row_seven,
        // bytes32 _row_eight,
        // bytes32 _row_nine
    ) {
        if (_section_index >= sections.length) throw;
        Section section = sections[_section_index];
        if(section.owner != msg.sender) throw;
        // section.image_data[0] = _row_zero;
        // section.image_data[1] = _row_one;
        // section.image_data[2] = _row_two;
        // section.image_data[3] = _row_three;
        // section.image_data[4] = _row_four;
        // section.image_data[5] = _row_five;
        // section.image_data[6] = _row_six;
        // section.image_data[7] = _row_seven;
        // section.image_data[8] = _row_eight;
        // section.image_data[9] = _row_nine;
        section.image_id = 0;
        section.md5 = "";
        section.last_update = block.timestamp;
        NewImage(_section_index);
    }
// Solidity 0.4.11
/// Set a section's image data to be redrawn on the map. Fires a NewImage
/// event.
function setImageDataCloud(
        uint _section_index,
        uint _image_id,
        string _md5
    ) {
        if (_section_index >= sections.length) throw;
        Section section = sections[_section_index];
        if(section.owner != msg.sender) throw;
        section.image_id = _image_id;
        section.md5 = _md5;
        section.last_update = block.timestamp;
        NewImage(_section_index);
    }
// Solidity 0.4.24
/**
 * @dev low level token purchase ***DO NOT OVERRIDE***
 * This function has a non-reentrancy guard, so it shouldn't be called by
 * another `nonReentrant` function.
 * @param beneficiary Recipient of the token purchase
 */
function buyTokens(address beneficiary) public nonReentrant payable {
        uint256 weiAmount = msg.value;
        _preValidatePurchase(beneficiary, weiAmount);

        // calculate token amount to be created
        uint256 tokens = _getTokenAmount(weiAmount);

        // update state
        _weiRaised = _weiRaised.add(weiAmount);

        _processPurchase(beneficiary, tokens);
        emit TokensPurchased(msg.sender, beneficiary, weiAmount, tokens);

        // _updatePurchasingState(beneficiary, weiAmount);

        _forwardFunds();
        // _postValidatePurchase(beneficiary, weiAmount);
    }
// Solidity 0.5.15
/** this can only be done once, so this oracle is solely for working with
 * three AssetSwap contracts
 * assetswap 0 is the ETH, at 2.5 leverage
 * assetswap 1 is the SPX, at 10x leverage
 * assetswap 2 is the BTC, at 2.5 leverage
 *
 */
function addAssetSwaps(address newAS0, address newAS1, address newAS2)
        external
        onlyAdmin
    {
        require(assetSwaps[0] == address(0));
        assetSwaps[0] = newAS0;
        assetSwaps[1] = newAS1;
        assetSwaps[2] = newAS2;
        readers[newAS0] = true;
        readers[newAS1] = true;
        readers[newAS2] = true;
    }
// Solidity 0.5.15
/** Quickly fix an erroneous price, or correct the fact that 50% movements are
 * not allowed in the standard price input
 * this must be called within 60 minutes of the initial price update occurence
 */
function editPrice(uint _ethprice, uint _spxprice, uint _btcprice)
        external
        onlyAdmin
    {
        require(now < lastUpdateTime + 60 minutes);
        prices[0][currentDay] = _ethprice;
        prices[1][currentDay] = _spxprice;
        prices[2][currentDay] = _btcprice;
        emit PriceUpdated(_ethprice, _spxprice, _btcprice, now, currentDay, true);
    }
// Solidity 0.5.15
/**
 * @return startDay relevant for trades done now
 * pulls the day relevant for new AssetSwap subcontracts
 * startDay 2 means the 2 slot (ie, the third) of prices will be the initial
 * price for the subcontract. As 5 is the top slot, and rolls into slot 0
 * the next week, the next pricing day is 1 when the current day == 5
 * (this would be a weekend or Monday morning)
 */
function getStartDay()
        public
        view
        returns (uint8 _startDay)
    {
        if (nextUpdateSettle) {
            _startDay = 5;
        } else if (currentDay == 5) {
            _startDay = 1;
        } else {
            _startDay = currentDay + 1;
        }
    }
// Solidity 0.4.11
/// Transfer a region of sections and IPO tokens to the supplied address.
function transferRegion(
        uint _start_section_index,
        uint _end_section_index,
        address _to
    ) {
        if(_start_section_index > _end_section_index) throw;
        if(_end_section_index > 9999) throw;
        uint x_pos = _start_section_index % 100;
        uint base_y_pos = (_start_section_index - (_start_section_index % 100)) / 100;
        uint x_max = _end_section_index % 100;
        uint y_max = (_end_section_index - (_end_section_index % 100)) / 100;
        while(x_pos <= x_max)
        {
            uint y_pos = base_y_pos;
            while(y_pos <= y_max)
            {
                Section section = sections[x_pos + (y_pos * 100)];
                if(section.owner == msg.sender)
                {
                  if (balanceOf[_to] + 1 < balanceOf[_to]) throw;
                  section.owner = _to;
                  section.for_sale = false;
                  balanceOf[msg.sender] -= 1;
                  balanceOf[_to] += 1;
                }
                y_pos++;
            }
            x_pos++;
        }
    }
// Solidity 0.6.12
// this function will only return the no of dai can pay till now
function getCurrentInstallment(address _addr) public view returns(uint256) {
        require(registeredusers[_addr],'you are not registered');
        
       
        if(block.timestamp > users[_addr].time){
            return users[_addr].daiamount;
        }    
        uint256 timeleft = users[_addr].time.sub(block.timestamp);
    
        uint256 amt = users[_addr].daiamount.mul(1e18).div(users[_addr].months);
        uint256 j;
        for(uint256 i = users[_addr].months;i>0;i--){
            if(timeleft <= oneMonthTime || timeleft == 0){
                return users[_addr].daiamount;
            }
            j= j.add(1);
            if(timeleft > i.sub(1).mul(oneMonthTime)){
                return amt.mul(j).div(1e18);
            }
        }
    }
// Solidity 0.4.10
/* only owner address can do manual refund
 * used only if bet placed + oraclize failed to __callback
 * filter LogBet by address and/or playerBetId:
 * LogBet(playerBetId[rngId], playerAddress[rngId], safeAdd(playerBetValue[rngId], playerProfit[rngId]), playerProfit[rngId], playerBetValue[rngId], playerNumber[rngId]);
 * check the following logs do not exist for playerBetId and/or playerAddress[rngId] before refunding:
 * LogResult or LogRefund
 * if LogResult exists player should use the withdraw pattern playerWithdrawPendingTransactions 
 */
function ownerRefundPlayer(bytes32 originalPlayerBetId, address sendTo, uint originalPlayerProfit, uint originalPlayerBetValue) public 
		onlyOwner
    {        
        /* safely reduce pendingPayouts by playerProfit[rngId] */
        maxPendingPayouts = safeSub(maxPendingPayouts, originalPlayerProfit);
        /* send refund */
        if(!sendTo.send(originalPlayerBetValue)) throw;
        /* log refunds */
        LogRefund(originalPlayerBetId, sendTo, originalPlayerBetValue);        
    }
// Solidity 0.5.12
/**************************************************** Public Interface for Stakers **************************************************************/
function createNewStake(uint256 _amount, uint8 _lockupPeriod, bool _compound) public {
        require(!paused, "New stakes are paused");
        require(_isValidLockupPeriod(_lockupPeriod), "The lockup period is invalid");
        require(_amount >= 5000000000000000000000, "You must stake at least 5000 LIT");
        require(_canStakeToday(), "You can't start a stake until the first day of next month");
        require(IERC20(litionToken).transferFrom(msg.sender, address(this), _amount), "Couldn't take the LIT from the sender");
        
        Stake memory stake = Stake({createdOn: now, 
                                    totalStaked:_amount, 
                                    lockupPeriod:_lockupPeriod, 
                                    compound:_compound, 
                                    isFinished:false});
                                    
        Stake[] storage stakes = stakeListBySender[msg.sender].stakes;
        stakes.push(stake);
        _addStakerIfNotExist(msg.sender);
        
        emit NewStake(msg.sender, _amount, _lockupPeriod, _compound);
    }
// Solidity 0.5.12
// Will be called monthly, at the end of each month
function _accreditRewards() public onlyOwner {
        uint256 totalToAccredit = getTotalRewardsToBeAccredited();
        require(IERC20(litionToken).transferFrom(msg.sender, address(this), totalToAccredit), "Couldn't take the LIT from the sender");

        for (uint256 i = 0; i < stakers.length; i++) {
            StakeList storage stakeList = stakeListBySender[stakers[i]];
            uint256 rewardsToBeAccredited = stakeList.rewardsToBeAccredited;
            if (rewardsToBeAccredited > 0) {
                stakeList.rewardsToBeAccredited = 0;
                stakeList.rewards += rewardsToBeAccredited;
                
                emit RewardsAccreditedToStaker(stakers[i], rewardsToBeAccredited);
            }
        }
        
        emit RewardsAccredited(totalToAccredit);
    }
// Solidity 0.5.12
// Will be called every day to distribute the accumulated new MiningReward events coming from LitionRegistry
function _updateRewardsToBeAccredited(uint256 _fromMiningRewardBlock, uint256 _toMiningRewardBlock, uint256 _amount) public onlyOwner {
        require(_fromMiningRewardBlock < _toMiningRewardBlock, "Invalid params");
        require(_fromMiningRewardBlock > lastMiningRewardBlock, "Rewards already distributed");
        
        lastMiningRewardBlock = _toMiningRewardBlock;
        
        //Won't consider any stake marked as isFinished
        
        uint256 fees = _amount.mul(5) / 100; // Amount the validator will keep for himself
        uint256 totalParts = _calculateParts();

        _distributeBetweenStakers(totalParts, _amount.sub(fees));

        emit RewardsToBeAccreditedDistributed(_amount);
    }
// Solidity 0.5.12
/**************************************************** Internal Admin - Lockups **************************************************************/
function calculateFinishTimestamp(uint256 _timestamp, uint8 _lockupPeriod) public pure returns (uint256) {
        uint16 year = Date.getYear(_timestamp);
        uint8 month = Date.getMonth(_timestamp);
        month += _lockupPeriod;
        if (month > 12) {
            year += 1;
            month = month % 12;
        }
        uint8 newDay = Date.getDaysInMonth(month, year);
        return Date.toTimestamp(year, month, newDay);
    }
// Solidity 0.5.12
/**************************************************** Internal Admin - Validations **************************************************************/
function _isValidLockupPeriod(uint8 n) internal pure returns (bool) {
        if (n == 1) {
            return true;
        }
        else if (n == 3) {
            return true;
        }
        else if (n == 6) {
            return true;
        }
        else if (n == 12) {
            return true;
        }
        return false;
    }