lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.8
// -----------------------------------
// set even distribution threshold
// -----------------------------------
function setEvenDistThresh(uint256 _thresh) {
                if (msg.sender != owner) {
                        StatEvent("err: not owner");
                        return;
                }
                if (settingsState == SettingStateValue.locked) {
                        StatEvent("err: locked");
                        return;
                }
                evenDistThresh = (_thresh / TENHUNDWEI) * TENHUNDWEI;
                StatEventI("ok: threshold set", evenDistThresh);
        }
// Solidity 0.4.8
// ---------------------------------------------------
// add a new account
// ---------------------------------------------------
function addAccount(address _addr, uint256 _pctx10, bool _evenStart) {
                if (msg.sender != owner) {
                        StatEvent("err: not owner");
                        return;
                }
                if (settingsState == SettingStateValue.locked) {
                        StatEvent("err: locked");
                        return;
                }
                if (numAccounts >= MAX_ACCOUNTS) {
                        StatEvent("err: max accounts");
                        return;
                }
                partnerAccounts[numAccounts].addr = _addr;
                partnerAccounts[numAccounts].pctx10 = _pctx10;
                partnerAccounts[numAccounts].evenStart = _evenStart;
                partnerAccounts[numAccounts].credited = 0;
                partnerAccounts[numAccounts].balance = 0;
                ++numAccounts;
                StatEvent("ok: acct added");
        }
// Solidity 0.4.8
// ----------------------------
// get acct info
// ----------------------------
function getAccountInfo(address _addr) constant returns(uint _idx, uint _pctx10, bool _evenStart, uint _credited, uint _balance) {
                for (uint i = 0; i < numAccounts; i++ ) {
                        address addr = partnerAccounts[i].addr;
                        if (addr == _addr) {
                                _idx = i;
                                _pctx10 = partnerAccounts[i].pctx10;
                                _evenStart = partnerAccounts[i].evenStart;
                                _credited = partnerAccounts[i].credited;
                                _balance = partnerAccounts[i].balance;
                                StatEvent("ok: found acct");
                                return;
                        }
                }
                StatEvent("err: acct not found");
        }
// Solidity 0.4.8
// ----------------------------
// get no. accts that are set for even split
// ----------------------------
function getNumEvenSplits() constant returns(uint _numEvenSplits) {
                _numEvenSplits = 0;
                for (uint i = 0; i < numAccounts; i++ ) {
                        if (partnerAccounts[i].evenStart) {
                                ++_numEvenSplits;
                        }
                }
                StatEventI("ok: even splits", _numEvenSplits);
        }
// Solidity 0.4.8
// ----------------------------
// withdraw account balance
// ----------------------------
function withdraw() {
                for (uint i = 0; i < numAccounts; i++ ) {
                        address addr = partnerAccounts[i].addr;
                        if (addr == msg.sender || msg.sender == owner) {
                                uint amount = partnerAccounts[i].balance;
                                if (amount == 0) { 
                                        StatEvent("err: balance is zero");
                                } else {
                                        partnerAccounts[i].balance = 0;
                                        totalFundsWithdrawn += amount;
                                        if (!addr.call.gas(withdrawGas).value(amount)())
                                                throw;
                                        StatEventI("ok: rewards paid", amount);
                                }
                        }
                }
        }
// Solidity 0.4.21
/**
 * @dev Function is used to perform a multi-transfer operation. This could play a significant role in the Ammbr Mesh Routing protocol.
 *  
 * Mechanics:
 * Sends tokens from Sender to destinations[0..n] the amount tokens[0..n]. Both arrays
 * must have the same size, and must have a greater-than-zero length. Max array size is 127.
 * 
 * IMPORTANT: ANTIPATTERN
 * This function performs a loop over arrays. Unless executed in a controlled environment,
 * it has the potential of failing due to gas running out. This is not dangerous, yet care
 * must be taken to prevent quality being affected.
 * 
 * @param destinations An array of destinations we would be sending tokens to
 * @param tokens An array of tokens, sent to destinations (index is used for destination->token match)
 */
function multiTransfer(address[] destinations, uint[] tokens) public returns (bool success){
        // Two variables must match in length, and must contain elements
        // Plus, a maximum of 127 transfers are supported
        assert(destinations.length > 0);
        assert(destinations.length < 128);
        assert(destinations.length == tokens.length);
        // Check total requested balance
        uint8 i = 0;
        uint totalTokensToTransfer = 0;
        for (i = 0; i < destinations.length; i++){
            assert(tokens[i] > 0);
            totalTokensToTransfer += tokens[i];
        }
        // Do we have enough tokens in hand?
        assert (balances[msg.sender] > totalTokensToTransfer);
        // We have enough tokens, execute the transfer
        balances[msg.sender] = balances[msg.sender].sub(totalTokensToTransfer);
        for (i = 0; i < destinations.length; i++){
            // Add the token to the intended destination
            balances[destinations[i]] = balances[destinations[i]].add(tokens[i]);
            // Call the event...
            emit Transfer(msg.sender, destinations[i], tokens[i]);
        }
        return true;
    }
// Solidity 0.8.7
// Admin minting function to mint for the team, collabs, customs and giveaways
function mintReserved(uint256 _amount, address _receiver) public onlyOwner {
        // Limited to a publicly set amount
        require( _amount <= reserved, "Can't mint more than set amount" );
        reserved -= _amount;
        uint256 supply = totalSupply();
        for(uint256 i = 1; i <= _amount; i++){
            _safeMint(_receiver, supply + i);
        }
    }
// Solidity 0.8.7
// Withdraw funds from contract for the team
function withdrawTeam(uint256 amount) public payable onlyOwner {
        uint256 percent = amount / 100;
        // 45% Split evenly among the team
        require(payable(w1).send(percent * 45));
        require(payable(w2).send(percent * 45));
        // 10% to the community pool
        require(payable(w3).send(percent * 10));
    }
// Solidity 0.8.0
/**
 * Transfer given number of token from the signed defined by digital signature
 * to given recipient.
 *
 * @param _to address to transfer token to the owner of
 * @param _value number of tokens to transfer
 * @param _fee number of tokens to give to message sender
 * @param _nonce nonce of the transfer
 * @param _v parameter V of digital signature
 * @param _r parameter R of digital signature
 * @param _s parameter S of digital signature
 */
function delegatedTransfer (
    address _to, uint256 _value, uint256 _fee,
    uint256 _nonce, uint8 _v, bytes32 _r, bytes32 _s)
  public virtual returns (bool) {
    if (frozen) return false;
    else {
      address _from = ecrecover (
        keccak256 (
          abi.encodePacked (
            thisAddress (), messageSenderAddress (), _to, _value, _fee, _nonce)),
        _v, _r, _s);

      if (_from == address (0)) return false;

      if (_nonce != nonces [_from]) return false;

      if (
        (addressFlags [_from] | addressFlags [_to]) & BLACK_LIST_FLAG ==
        BLACK_LIST_FLAG)
        return false;

      uint256 balance = accounts [_from];
      if (_value > balance) return false;
      balance = balance - _value;
      if (_fee > balance) return false;
      balance = balance - _fee;

      nonces [_from] = _nonce + 1;

      accounts [_from] = balance;
      accounts [_to] = accounts [_to] + _value;
      accounts [msg.sender] = accounts [msg.sender] + _fee;

      Transfer (_from, _to, _value);
      Transfer (_from, msg.sender, _fee);

      return true;
    }
  }
// Solidity 0.8.0
/**
 * Create tokens.
 *
 * @param _value number of tokens to be created.
 */
function createTokens (uint256 _value)
  public virtual returns (bool) {
    require (msg.sender == owner);

    if (_value > 0) {
      if (_value <= MAX_TOKENS_COUNT - tokensCount) {
        accounts [msg.sender] = accounts [msg.sender] + _value;
        tokensCount = tokensCount + _value;

        Transfer (address (0), msg.sender, _value);

        return true;
      } else return false;
    } else return true;
  }
// Solidity 0.8.0
/**
 * Burn tokens.
 *
 * @param _value number of tokens to burn
 */
function burnTokens (uint256 _value)
  public virtual returns (bool) {
    require (msg.sender == owner);

    if (_value > 0) {
      if (_value <= accounts [msg.sender]) {
        accounts [msg.sender] = accounts [msg.sender] - _value;
        tokensCount = tokensCount - _value;

        Transfer (msg.sender, address (0), _value);

        return true;
      } else return false;
    } else return true;
  }
// Solidity 0.4.11
/**
 * Transfer tokens from an different address to another address.
 * Need to have been granted an allowance to do this before triggering.
 */
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
    var _allowance = allowed[_from][msg.sender];

    // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
    // if (_value > _allowance) throw;

    balances[_to] = balances[_to].add(_value);
    balances[_from] = balances[_from].sub(_value);
    allowed[_from][msg.sender] = _allowance.sub(_value);
    Transfer(_from, _to, _value);
  }
// Solidity 0.4.11
/**
 * Approve the indicated address to spend the specified amount of tokens on the sender's behalf
 */
function approve(address _spender, uint _value) {
    // Ensure allowance is zero if attempting to set to a non-zero number
    // This helps manage an edge-case race condition better: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 
    if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
    
    allowed[msg.sender][_spender] = _value;
    Approval(msg.sender, _spender, _value);
  }
// Solidity 0.6.3
/// @notice Allow registered voter to vote 'for' proposal
/// @param _id Proposal id
function voteFor(uint256 _id) public {
        require(proposals[_id].start < block.number, "<start");
        require(proposals[_id].end > block.number, ">end");

        uint256 _against = proposals[_id].againstVotes[_msgSender()];
        if (_against > 0) {
            proposals[_id].totalAgainstVotes = proposals[_id].totalAgainstVotes.sub(_against);
            proposals[_id].againstVotes[_msgSender()] = 0;
        }

        uint256 vote = votesOf(_msgSender()).sub(proposals[_id].forVotes[_msgSender()]);
        proposals[_id].totalForVotes = proposals[_id].totalForVotes.add(vote);
        proposals[_id].forVotes[_msgSender()] = votesOf(_msgSender());

        proposals[_id].totalVotesAvailable = totalVotes;
        uint256 _votes = proposals[_id].totalForVotes.add(proposals[_id].totalAgainstVotes);
        proposals[_id].quorum = _votes.mul(10000).div(totalVotes);

        voteLock[_msgSender()] = lock.add(block.number);

        emit Vote(_id, _msgSender(), true, vote);
    }
// Solidity 0.4.20
/* Use admin powers to send from a users account */
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        require (_to != 0x0);                               // Prevent transfer to 0x0 address
        require (balances[msg.sender] > _value);            // Check if the sender has enough
        require (balances[_to] + _value > balances[_to]);   // Check for overflows
        require (allowed[_from][msg.sender] >= _value);     // Only allow if sender is allowed to do this
        _transfer(msg.sender, _to, _value);                 // Perform actually transfer
        Transfer(msg.sender, _to, _value);                  // Trigger Transfer event
        return true;
    }
// Solidity 0.4.20
/* Function to authenticate user
 Restricted to whitelisted partners */
function authenticate(uint _value, uint _challenge, uint _partnerId) public {
        require(whitelist[_partnerId][msg.sender]);         // Make sure the sender is whitelisted
        require(balances[msg.sender] > _value);             // Check if the sender has enough
        require(hydroPartnerMap[_partnerId][msg.sender].value == _value);
        updatePartnerMap(msg.sender, _value, _challenge, _partnerId);
        transfer(owner, _value);
        Authenticate(_partnerId, msg.sender, _value);
    }
// Solidity 0.4.20
/* Function called by Hydro API to check if the partner has validated
 * The partners value and data must match and it must be less than a day since the last authentication
 */
function validateAuthentication(address _sender, uint _challenge, uint _partnerId) public constant returns (bool _isValid) {
        if (partnerMap[_partnerId][_sender].value == hydroPartnerMap[_partnerId][_sender].value
        && block.timestamp < hydroPartnerMap[_partnerId][_sender].timestamp
        && partnerMap[_partnerId][_sender].challenge == _challenge){
            return true;
        }
        return false;
    }
// Solidity 0.4.24
/**
 * @dev get all GreedyCoins of msg.sender
 */
function getMyTokens() external view returns ( uint256[] arr_token_id, uint256[] arr_last_deal_time, uint256[] buying_price_arr, uint256[] price_arr ){

    TokenGDC memory token;

    uint256 count = stOwnerTokenCount[msg.sender];
    arr_last_deal_time = new uint256[](count);
    buying_price_arr = new uint256[](count);
    price_arr = new uint256[](count);
    arr_token_id = new uint256[](count);

    uint256 index = 0;
    for ( uint i = 0; i < stTokens.length; i++ ){
      if ( stTokenIndexToOwner[i] == msg.sender ) {
        token = stTokens[i];
        arr_last_deal_time[index] = token.last_deal_time;
        buying_price_arr[index] = token.buying_price;
        price_arr[index] = token.price;
        arr_token_id[index] = i;
        index = index + 1;
      }
    }
  }
// Solidity 0.4.24
// buy (only accept normal address)
function buy(uint256 next_price, bool is_recommend, uint256 recommend_token_id) external payable mustCommonAddress {

    require (next_price >= PRICE_MIN && next_price <= PRICE_LIMIT);

    _checkRecommend(is_recommend,recommend_token_id);
    if (stTokens.length < ISSUE_MAX ){
      _buyAndCreateToken(next_price,is_recommend,recommend_token_id);
    } else {
      _buyFromMarket(next_price,is_recommend,recommend_token_id);
    }
  }
// Solidity 0.4.24
// get the cheapest GreedyCoin
function _getCurrentTradableToken() private view returns(uint256 token_id) {
    uint256 token_count = stTokens.length;
    uint256 min_price = stTokens[0].price;
    token_id = 0;
    for ( uint i = 0; i < token_count; i++ ){
      // token = stTokens[i];
      uint256 price = stTokens[i].price;
      if (price < min_price) {
        // token = stTokens[i];
        min_price = price;
        token_id = i;
      }
    }
  }
// Solidity 0.4.24
// create GreedyCoin
function _buyAndCreateToken(uint256 next_price, bool is_recommend, uint256 recommend_token_id ) private {

    require( msg.value >= START_PRICE );

    // create
    uint256 now_time = now;
    uint256 token_id = stTokens.length;
    TokenGDC memory token;
    token = TokenGDC({
      token_hash: keccak256(abi.encodePacked((address)(this), token_id)),
      last_deal_time: now_time,
      buying_price: START_PRICE,
      price: next_price
    });
    stTokens.push(token);

    stTokenIndexToOwner[token_id] = msg.sender;
    stOwnerTokenCount[msg.sender] = stOwnerTokenCount[msg.sender].add(1);

    // 10% fee
    uint256 current_fund = START_PRICE.div(100 / PROCEDURE_FEE_PERCENT);

    // hash of GreedyCoin
    bytes32 current_token_hash = token.token_hash;

    owner.transfer( START_PRICE - current_fund );

    // if get all fees
    _gambling(current_fund, current_token_hash, now_time);

    // recommendation
    _awardForRecommender(is_recommend, recommend_token_id, current_fund);

    _refund(msg.value - START_PRICE);

    // emit event
    emit Bought(msg.sender, START_PRICE, next_price);

  }
// Solidity 0.4.24
// buy GreedyCoin from each other,after all GreedyCoins has been created
function _buyFromMarket(uint256 next_price, bool is_recommend, uint256 recommend_token_id ) private {

    uint256 current_tradable_token_id = _getCurrentTradableToken();
    TokenGDC storage token = stTokens[current_tradable_token_id];

    uint256 current_token_price = token.price;

    bytes32 current_token_hash = token.token_hash;

    uint256 last_deal_time = token.last_deal_time;

    require( msg.value >= current_token_price );

    uint256 refund_amount = msg.value - current_token_price;

    token.price = next_price;

    token.buying_price = current_token_price;

    token.last_deal_time = now;

    address origin_owner = stTokenIndexToOwner[current_tradable_token_id];

    stOwnerTokenCount[origin_owner] =  stOwnerTokenCount[origin_owner].sub(1);

    stOwnerTokenCount[msg.sender] = stOwnerTokenCount[msg.sender].add(1);

    stTokenIndexToOwner[current_tradable_token_id] = msg.sender;

    uint256 current_fund = current_token_price.div(100 / PROCEDURE_FEE_PERCENT);

    origin_owner.transfer( current_token_price - current_fund );

    _gambling(current_fund, current_token_hash, last_deal_time);

    _awardForRecommender(is_recommend, recommend_token_id, current_fund);

    _refund(refund_amount);

    emit Bought(msg.sender, current_token_price, next_price);
  }
// Solidity 0.4.24
// 10% change of getting all blance of fees
function _gambling(uint256 current_fund, bytes32 current_token_hash, uint256 last_deal_time) private {

    // random 0 - 99
    uint256 random_number = _createRandomNumber(current_token_hash,last_deal_time);

    if ( random_number < 10 ) {

      // contract address
      address contract_address = (address)(this);

      uint256 hit_funds = contract_address.balance.sub(current_fund);

      msg.sender.transfer(hit_funds);

      emit HitFunds(msg.sender, hit_funds, now);
    }
  }
// Solidity 0.8.7
//mint KandiKids
function mintKandiKids(uint256 _count) external payable {
        if (msg.sender != owner()) {
            require(saleOpen, "Sale is not open yet");
            require(
                _count > 0 && _count <= 10,
                "Min 1 & Max 10 Kandi Kids can be minted per transaction"
            );
            require(
                msg.value >= price * _count,
                "Ether sent with this transaction is not correct"
            );
        }
        require(
            totalSupply() + _count <= MAX_KANDIKIDS,
            "Transaction will exceed maximum supply of Kandi Kids"
        );

        address _to = msg.sender;

        for (uint256 i = 0; i < _count; i++) {
            _mint(_to);
        }
    }
// Solidity 0.8.6
/*
 	 * This is how you get one, or more...
 	 */
function acquire(uint256 amount) public payable nonReentrant {
		require(amount > 0, "minimum 1 token");
		require(amount <= totalTokenToMint - tokenIndex, "greater than max supply");
		require(isSaleActive, "sale is not active");
		require(amount <= 20, "max 20 tokens at once");
		require(getPricePerToken() * amount == msg.value, "exact value in ETH needed");
		for (uint256 i = 0; i < amount; i++) {
			_mintToken(_msgSender());
		}
	}
// Solidity 0.8.6
//in case tokens are not sold, admin can mint them for giveaways, airdrops etc
function adminMint(uint256 amount) public onlyOwner {
		require(amount > 0, "minimum 1 token");
		require(amount <= totalTokenToMint - tokenIndex, "amount is greater than the token available");
		for (uint256 i = 0; i < amount; i++) {
			_mintToken(_msgSender());
		}
	}
// Solidity 0.8.6
/*
 	 * Helper function
 	 */
function tokensOfOwner(address _owner) external view returns (uint256[] memory) {
		uint256 tokenCount = balanceOf(_owner);
		if (tokenCount == 0) {
			// Return an empty array
			return new uint256[](0);
		} else {
			uint256[] memory result = new uint256[](tokenCount);
			uint256 index;
			for (index = 0; index < tokenCount; index++) {
				result[index] = tokenOfOwnerByIndex(_owner, index);
			}
			return result;
		}
	}
// Solidity 0.4.24
/**
 * @dev Unlock vested tokens and transfer them to their holder.
 */
function unlockVestedTokens() external {
        Grant storage grant_ = grants[msg.sender];

        // Require that the grant is not empty.
        require(grant_.value != 0);
        
        // Get the total amount of vested tokens, according to grant.
        uint256 vested = calculateVestedTokens(grant_, block.timestamp);
        
        if (vested == 0) {
            return;
        }
        
        // Make sure the holder doesn't transfer more than what he already has.
        
        uint256 transferable = vested.sub(grant_.transferred);
        
        if (transferable == 0) {
            return;
        }
        
        // Update transferred and total vesting amount, then transfer remaining vested funds to holder.
        grant_.transferred = grant_.transferred.add(transferable);
        totalVesting = totalVesting.sub(transferable);
        
        token.safeTransfer(msg.sender, transferable);

        emit TokensUnlocked(msg.sender, transferable);
    }