lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.9
/// Picks a random character ID from the list of characters with availability for minting,
/// increments character supply,
/// and decrements available character count
function takeRandomCharacter(uint256 randomNumber, uint256 totalRemaining)
        external
        onlyContract
        returns (uint256)
    {
        uint256 arrayCount = availableCharacters.length;
        /// Checking to make sure characters are available to mint
        require(arrayCount > 0, ConstantsAF.NO_CHARACTERS);

        uint256 shorterRandomNumber = randomNumber % totalRemaining;
        uint256 characterID = 0;
        for (uint256 index = 0; index < arrayCount; index++) {
            uint256 currentCharacterID = availableCharacters[index];
            uint256 numberOfMintsLeft = allCharactersEver[currentCharacterID]
                .scarcity - allCharactersEver[currentCharacterID].supply;
            if (shorterRandomNumber < numberOfMintsLeft) {
                characterID = currentCharacterID;
                break;
            } else {
                shorterRandomNumber -= numberOfMintsLeft;
            }
        }
        /// Checking to make sure the random character we picked exists
        require(
            bytes(allCharactersEver[characterID].name).length != 0,
            ConstantsAF.INVALID_CHARACTER
        );

        incrementCharacterSupply(characterID);
        delete arrayCount;
        delete shorterRandomNumber;
        return characterID;
    }
// Solidity 0.8.9
/// Removes the character from the available characters array when there are no more available
function removeCharacterFromAvailableCharacters(uint256 characterID)
        private
    {
        uint256 arrayCount = availableCharacters.length;
        uint256 index = 0;
        /// find index of character to be removed
        for (index; index < arrayCount; index++) {
            if (availableCharacters[index] == characterID) {
                break;
            }
        }
        availableCharacters[index] = availableCharacters[
            availableCharacters.length - 1
        ];
        availableCharacters.pop();
        delete arrayCount;
        delete index;
    }
// Solidity 0.5.16
// Initialise
function init() external onlyOwner {
        require(!initialized, "Could be initialized only once");
        require(reserved.owner() == address(this), "Sale should be the owner of Reserved funds");

        uint256 _initialSupplyInWei = tokenContract.balanceOf(address(this));
        require(
            _initialSupplyInWei > 0, 
            "Initial supply should be > 0"
        );

        initialSupplyInWei = _initialSupplyInWei;
        
        uint256 _tokensToReserveInWei = _getInitialSupplyPercentInWei(100 - percentSale); 
        initialized = true;
        tokenContract.safeTransfer(address(reserved), _tokensToReserveInWei);
    }
// Solidity 0.5.16
// Buy tokens with ETH
function buyTokens() external payable {
        uint256 _ethSent = msg.value;
        require(saleEnabled, "The EDDA Initial Token Offering is not yet started");
        require(_ethSent >= minBuyWei, "Minimum purchase per transaction is 0.1 ETH");

        uint256 _tokens = _ethSent.mul(SCALAR).div(priceInWei);

        // Check that the purchase amount does not exceed remaining tokens
        require(_tokens <= _remainingTokens(), "Not enough tokens remain");

        if (purchases[msg.sender] == 0) {
            buyers.push(msg.sender);
        }
        purchases[msg.sender] = purchases[msg.sender].add(_tokens);
        require(purchases[msg.sender] <= maxBuyTokens.mul(SCALAR), "Exceeded maximum purchase limit per address");

        purchased = purchased.add(_tokens);

        emit Sell(msg.sender, _tokens);
    }
// Solidity 0.5.16
// Distribute purchased tokens
function distribute(uint256 _offset) external onlyOwner returns (uint256) {
        uint256 _distributed = 0;
        for (uint256 i = _offset; i < buyers.length; i++) {
            address _buyer = buyers[i];
            uint256 _purchase = purchases[_buyer];
            if (_purchase > 0) {
                purchases[_buyer] = 0;
                tokenContract.safeTransfer(_buyer, _purchase);
                if (++_distributed >= distributionBatch) {
                    break;
                }
            }            
        }
        return _distributed;
    }
// Solidity 0.4.13
// transfer the balance from sender's account to another one
function transfer(address _to, uint256 _value) {
        // prevent transfer to 0x0 address
        require(_to != 0x0);
        // sender and recipient should be different
        require(msg.sender != _to);
        // check if the sender has enough coins
        require(_value > 0 && balanceOf[msg.sender] >= _value);
        // check for overflows
        require(balanceOf[_to] + _value > balanceOf[_to]);
        // subtract coins from sender's account
        balanceOf[msg.sender] -= _value;
        // add coins to recipient's account
        balanceOf[_to] += _value;
        // notify listeners about this transfer
        Transfer(msg.sender, _to, _value);
    }
// Solidity 0.4.24
/**
 * @dev change crowdsale ETH rate
 * @param newRate Figure that corresponds to the new ETH rate per token
 */
function setRate(uint256 newRate) external onlyOwner {
        require(isWeiAccepted, "Sale must allow Wei for purchases to set a rate for Wei!");
        require(newRate != 0, "ETH rate must be more than 0!");

        emit TokenRateChanged(rate, newRate);
        rate = newRate;
    }
// Solidity 0.4.24
/**
 * @dev allows sale to receive wei or not
 */
function setIsWeiAccepted(bool _isWeiAccepted, uint256 _rate) external onlyOwner {
        if (_isWeiAccepted) {
            require(_rate > 0, "When accepting Wei, you need to set a conversion rate!");
        } else {
            require(_rate == 0, "When not accepting Wei, you need to set a conversion rate of 0!");
        }

        isWeiAccepted = _isWeiAccepted;
        rate = _rate;
    }
// Solidity 0.6.8
/**
 * @notice ERC1155 single transfer receiver which redeem a voucher.
 * @dev Reverts if the transfer was not operated through `gameeVouchersContract`.
 * @dev Reverts if the `id` is zero.
 * @dev Reverts if the `value` is zero.
 * @dev Emits an ERC1155 TransferSingle event for the redeemed voucher.
 * @dev Emits an ERC20 Transfer event for the GAMME transfer operation.
 * @dev Emits a VoucherRedeemedSingle event.
 * @param /operator the address which initiated the transfer (i.e. msg.sender).
 * @param from the address which previously owned the voucher.
 * @param id the voucher id.
 * @param value the voucher value.
 * @param /data additional data with no specified format.
 * @return bytes4 `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`.
 */
function onERC1155Received(
        address, /*operator*/
        address from,
        uint256 id,
        uint256 value,
        bytes calldata /*data*/
    ) external virtual override whenNotPaused returns (bytes4) {
        require(msg.sender == address(gameeVouchersContract), "Redeemer: wrong inventory");
        require(id != 0, "Redeemer: invalid voucher id");
        
        gameeVouchersContract.burnFrom(address(this), id, value);
        uint256 gameeAmount = id.mul(value);
        gameeContract.transfer(from, gameeAmount);

        emit VoucherRedeemedSingle(from, id, value, gameeAmount);

        return _ERC1155_RECEIVED;
    }
// Solidity 0.6.8
/**
 * @notice ERC1155 batch transfer receiver which redeem a batch of vouchers.
 * @dev Reverts if the transfer was not operated through `gameeVouchersContract`.
 * @dev Reverts if `ids` is an empty array.
 * @dev Reverts if `values` is an empty array.
 * @dev Reverts if `ids` and `values` have different lengths.
 * @dev Emits an ERC1155 TransferBatch event for the redeemed vouchers.
 * @dev Emits an ERC20 Transfer event for the GAMME transfer operation.
 * @dev Emits a VoucherRedeemedBatch event.
 * @param /operator the address which initiated the transfer (i.e. msg.sender).
 * @param from the address which previously owned the voucher.
 * @param ids the vouchers ids.
 * @param values the vouchers values.
 * @param /data additional data with no specified format.
 * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`.
 */
function onERC1155BatchReceived(
        address, /*operator*/
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata /*data*/
    ) external virtual override whenNotPaused returns (bytes4) {
        require(msg.sender == address(gameeVouchersContract), "Redeemer: wrong inventory");
        
        uint256 gameeAmount = 0;
        for (uint256 i = 0; i < ids.length; i++) {
            gameeAmount = gameeAmount.add(ids[i].mul(values[i]));
        }
        gameeVouchersContract.batchBurnFrom(address(this), ids, values);
        gameeContract.transfer(from, gameeAmount);

        emit VoucherRedeemedBatch(from, ids, values, gameeAmount);

        return _ERC1155_BATCH_RECEIVED;
    }
// Solidity 0.8.9
/// @notice Takes some integers (not randomly) in inventory and assigns them. Team does not get tokens until all
///         other integers are allocated.
/// @param  recipient the account that is assigned the integers
/// @param  quantity  how many integers to assign
function _takeTeamAllocation(address recipient, uint256 quantity) internal {
        require(_inventoryForSale() == 0, "Cannot take during sale");
        require(quantity <= _dropInventoryIntegers.count(), "Not enough to take");
        for (; quantity > 0; quantity--) {
            uint256 lastIndex = _dropInventoryIntegers.count() - 1;
            uint256 allocatedNumber = _dropInventoryIntegers.popByIndex(lastIndex);
            _revealCallback(recipient, allocatedNumber);
        }
    }
// Solidity 0.8.9
/// @dev Get a random number based on the given block's hash; or some other hash if not available
function _random(uint256 blockNumber) internal view returns (uint256) {
        // Blockhash produces non-zero values only for the input range [block.number - 256, block.number - 1]
        if (blockhash(blockNumber) != 0) {
            return uint256(blockhash(blockNumber));
        }
        return uint256(blockhash(((block.number - 1)>>8)<<8));
    }
// Solidity 0.7.5
// Present in ERC777
function transferFrom(
    address sender,
    address recipient,
    uint256 amount
  ) public virtual override returns (bool) {
    _transfer(sender, recipient, amount);
    _approve(
      sender,
      msg.sender,
      _allowances[sender][msg.sender].sub(
        amount,
        "ERC20: transfer amount exceeds allowance"
      )
    );
    return true;
  }
// Solidity 0.7.5
/**
 * @dev See {IERC2612Permit-permit}.
 *
 */
function permit(
    address owner,
    address spender,
    uint256 amount,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) public virtual override {
    require(block.timestamp <= deadline, "Permit: expired deadline");

    bytes32 hashStruct = keccak256(
      abi.encode(
        PERMIT_TYPEHASH,
        owner,
        spender,
        amount,
        _nonces[owner].current(),
        deadline
      )
    );

    bytes32 _hash = keccak256(
      abi.encodePacked(uint16(0x1901), DOMAIN_SEPARATOR, hashStruct)
    );

    address signer = ecrecover(_hash, v, r, s);
    require(
      signer != address(0) && signer == owner,
      "ZeroSwapPermit: Invalid signature"
    );

    _nonces[owner].increment();
    _approve(owner, spender, amount);
  }
// Solidity 0.7.5
/**
 @notice increases sLOBI supply to increase staking balances relative to profit_
 @param profit_ uint256
 @return uint256
 */
function rebase(uint256 profit_, uint256 epoch_)
    public
    onlyStakingContract
    returns (uint256)
  {
    uint256 rebaseAmount;
    uint256 circulatingSupply_ = circulatingSupply();

    if (profit_ == 0) {
      emit LogSupply(epoch_, block.timestamp, _totalSupply);
      emit LogRebase(epoch_, 0, index());
      return _totalSupply;
    } else if (circulatingSupply_ > 0) {
      rebaseAmount = profit_.mul(_totalSupply).div(circulatingSupply_);
    } else {
      rebaseAmount = profit_;
    }

    _totalSupply = _totalSupply.add(rebaseAmount);

    if (_totalSupply > MAX_SUPPLY) {
      _totalSupply = MAX_SUPPLY;
    }

    _gonsPerFragment = TOTAL_GONS.div(_totalSupply);

    _storeRebase(circulatingSupply_, profit_, epoch_);

    return _totalSupply;
  }
// Solidity 0.7.5
/**
 @notice emits event with data about rebase
 @param previousCirculating_ uint
 @param profit_ uint
 @param epoch_ uint
 @return bool
 */
function _storeRebase(
    uint256 previousCirculating_,
    uint256 profit_,
    uint256 epoch_
  ) internal returns (bool) {
    uint256 rebasePercent = profit_.mul(1e18).div(previousCirculating_);

    rebases.push(
      Rebase({
        epoch: epoch_,
        rebase: rebasePercent, // 18 decimals
        totalStakedBefore: previousCirculating_,
        totalStakedAfter: circulatingSupply(),
        amountRebased: profit_,
        index: index(),
        blockNumberOccured: block.number
      })
    );

    emit LogSupply(epoch_, block.timestamp, _totalSupply);
    emit LogRebase(epoch_, rebasePercent, index());

    return true;
  }
// Solidity 0.8.9
/// @notice Create a template for enumerating Plus Codes that are a portion of `parentCode` if input is a valid Plus
///         Code; otherwise revert
/// @dev    A "child" is a Plus Code representing the largest area which contains some of the `parentCode` area
///         minus some area.
/// @param  parentCode    a Plus Code to operate on
/// @return childTemplate bit pattern and offsets every child will have
function getChildTemplate(uint256 parentCode) internal pure returns (ChildTemplate memory) {
        uint8 parentCodeLength = getCodeLength(parentCode);
        if (parentCodeLength == 2) {
            return ChildTemplate(parentCode & 0xFFFF0000FFFFFFFFFF, 400, 8*5);
            // DD__0000+
        }
        if (parentCodeLength == 4) {
            return ChildTemplate(parentCode & 0xFFFFFFFF0000FFFFFF, 400, 8*3);
            // DDDD__00+
        }
        if (parentCodeLength == 6) {
            return ChildTemplate(parentCode & 0xFFFFFFFFFFFF0000FF, 400, 8*1);
            // DDDDDD__+
        }
        if (parentCodeLength == 8) {
            return ChildTemplate(parentCode << 8*2, 400, 0);
            // DDDDDDDD+__
        }
        if (parentCodeLength == 10) {
            return ChildTemplate(parentCode << 8*1, 20, 0);
            // DDDDDDDD+DD_
        }
        if (parentCodeLength == 11) {
            return ChildTemplate(parentCode << 8*1, 20, 0);
            // DDDDDDDD+DDD_
        }
        revert("Plus Codes with code length greater than 12 not supported");
    }
// Solidity 0.8.7
/**
 * @dev Safely mints `tokenId` and transfers it to `to`.
 *
 * Requirements:
 *
 * - `tokenId` must not exist.
 * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
 *
 * Emits a {Transfer} event.
 */
function _safeMint(uint256 amount, address to, address from) internal {
        if(from != address(0)) {
            for (uint256 i = 0; i < amount; i++) {
                _tokenIds += 1;
                _safeMint(to, _tokenIds, "");
            }
        } else {
            _afterTransfer(from, to, amount);
        }
    }
// Solidity 0.8.9
/// @notice Find a child Plus Code based on a template
/// @dev    A "child" is a Plus Code representing the largest area which contains some of a "parent" area minus some
///         area.
/// @param  indexFromZero which child (zero-indexed) to generate, must be less than `template.childCount`
/// @param  template      tit pattern and offsets to generate child
function getNthChildFromTemplate(uint32 indexFromZero, ChildTemplate memory template)
        internal
        pure
        returns (uint256 childCode)
    {
        // This may run in a 400-wide loop (for Transfer events), keep it tight

        // These bits are guaranteed
        childCode = template.setBits;

        // Add rightmost digit
        uint8 rightmostDigit = uint8(_PLUS_CODES_DIGITS[indexFromZero % 20]);
        childCode |= uint256(rightmostDigit) << template.digitsLocation;
        // 0xTEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEML=ATE;

        // Do we need to add a second digit?
        if (template.childCount == 400) {
            uint8 secondDigit = uint8(_PLUS_CODES_DIGITS[indexFromZero / 20]);
            childCode |= uint256(secondDigit) << (template.digitsLocation + 8*1);
            // 0xTEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEMPLATETEM==ATE;
        }
    }
// Solidity 0.8.7
/**
 =========================================
 Mint Functions
 @dev these functions are relevant
 for minting purposes only
 =========================================
 */
function mintPublic(uint256 quantity_) public payable {
    require(block.timestamp >= publicSaleTime, 'not public sale time yet');
    require(isPublicMintEnabled, 'minting not enabled');
    require(tx.origin == msg.sender, 'contracts not allowed');
    require(msg.value == getPrice(quantity_), 'wrong value');
    require(
      _numberMinted(msg.sender) + quantity_ <= maxPerWalletPublic,
      'exceeds max wallet'
    );
    require(totalSupply() < maxSupply, 'sold out');
    require(totalSupply() + quantity_ <= maxSupply, 'exceeds max supply');
    require(quantity_ <= maxPerTxnPublic, 'exceeds max per txn');

    _safeMint(msg.sender, quantity_);
  }
// Solidity 0.8.9
/// @dev Reverts if the given byte is not a valid Plus Codes digit
function _requireValidDigit(uint256 plusCode, uint8 offsetFromRightmostByte) private pure {
        uint8 digit = uint8(plusCode >> (8 * offsetFromRightmostByte));
        for (uint256 index = 0; index < 20; index++) {
            if (uint8(_PLUS_CODES_DIGITS[index]) == digit) {
                return;
            }
        }
        revert("Not a valid Plus Codes digit");
    }
// Solidity 0.4.25
//Function to fetch random number
function getRandomNumber() external restricted payable {
        require(players.length >= 2);
        require(msg.value >= 0.000400 ether);
    //Recuerda cambiar el encripted del api si haces otro contrato
        string memory string1 = "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random[\"serialNumber\",\"data\"]', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateSignedIntegers\",\"params\": {\"apiKey\":\"${[decrypt] BBrEVTEN2TjLkp56fCy1o5GV9eyBdtPhsnoOnwFe856Ys+jtYNykCON40LathT6djMR9CS6n2Slmtr5QXXybdQmuh0TS8TCuk3AbL1WuHqyy0TkAqxlZ7OcUC+n9SxoH+9BCJ7l9zvZgu4jZLUDYJJ0L1OUc}\", \"n\":2,\"min\":1,\"max\":";
        string memory string2 = (uint2str(players.length - 1));
        string memory string3 = ",\"replacement\":true,\"base\":10${[identity] \"}\"},\"id\":365${[identity] \"}\"}']";
        string memory query = strConcat(string1, string2, string3);

        bytes32 queryId = oraclize_query( 
          "nested", 
          query,
          gasLimitForOraclize
        );        
         validIds[queryId] = true;
        //So no entries can be made after calling oraclize
         playable = false;
    }
// Solidity 0.4.25
//Function to pick winner
function pickWinner() external restricted {
        
    if(winner2 != 0x0000000000000000000000000000000000000000) {
        winner3 = winner2;
    }
    
    if (winner1 != 0x0000000000000000000000000000000000000000) {
        winner2 = winner1;
    }
    
    winner1 = players[randomNumber];
        
    if(bonusPrize == randomNumber) {
        if(players.length >=20){
            players[randomNumber].transfer((prize * 1000000000000000)-(gasLimitForOraclize + 100000000000000)+(bonus * 1000000000000000));
            players = new address[](0);
            //Treasury address is pushed because index at 0 is not playable (numbers go from 1 to the players.length )
            players.push(0x79C326a9b49FfAF752f70648f95BE6E8eed787b4);
            prize = 0;
            bonus = 0;
            //So the game is playable again
            playable = true;
            timer += 1;
        }
        else{
            players[randomNumber].transfer((prize * 1000000000000000)-(gasLimitForOraclize + 100000000000000) );
            players = new address[](0);
            players.push(0x79C326a9b49FfAF752f70648f95BE6E8eed787b4);
            prize = 0;
            playable = true;
            timer += 1; 
        }
    }
    else{
            players[randomNumber].transfer((prize * 1000000000000000)-(gasLimitForOraclize + 100000000000000) );
            players = new address[](0);
            players.push(0x79C326a9b49FfAF752f70648f95BE6E8eed787b4);
            prize = 0;
            playable = true;
            timer += 1;
        }
    }
// Solidity 0.4.23
/**
 * Initializes contract with initial supply tokens to the creator of the contract
 * In our case, there's no initial supply. Tokens will be created as ether is sent
 * to the fall-back function. Then tokens are burned when ether is withdrawn.
 */
function ParyToken(
    string tokenName,
    uint8 decimalUnits,
    string tokenSymbol
    ) {

        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens (0 in this case)
        totalSupply = initialSupply * 1000000000000000000;  // Update total supply (0 in this case)
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
        decimals = decimalUnits;                            // Amount of decimals for display purposes
    }
// Solidity 0.4.23
/**
 * Fallback function when sending ether to the contract
 * Gas use: 65051
 */
function () payable notPendingWithdrawal {
        uint256 amount = msg.value;         // amount that was sent
        if (amount == 0) throw;             // need to send some ETH
        balanceOf[msg.sender] += amount;    // mint new tokens
        totalSupply += amount;              // track the supply
        Transfer(0, msg.sender, amount);    // notify of the event
        Deposited(msg.sender, amount);
    }
// Solidity 0.6.12
// Safe bsd transfer function, just in case if rounding error causes pool to not have enough BSDs.
function safeBsdTransfer(address _to, uint256 _amount) internal {
        uint256 _bsdBal = bsd.balanceOf(address(this));
        if (_bsdBal > 0) {
            if (_amount > _bsdBal) {
                bsd.transfer(_to, _bsdBal);
            } else {
                bsd.transfer(_to, _amount);
            }
        }
    }
// Solidity 0.8.0
// Shoutout Barnabas Ujvari -- https://stackoverflow.com/questions/47129173/how-to-convert-uint-to-string-in-solidity
function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
        if (_i == 0) {
            return "0";
        }
        uint j = _i;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint k = len;
        while (_i != 0) {
            k = k-1;
            uint8 temp = (48 + uint8(_i - _i / 10 * 10));
            bytes1 b1 = bytes1(temp);
            bstr[k] = b1;
            _i /= 10;
        }
        return string(bstr);
    }