lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.25
// Ethereum Token Definition
function approveAndCall( address spender,
                           uint256 value,
                           bytes context ) public
  returns (bool success)
  {
    if ( approve(spender, value) )
    {
      tokenRecipient recip = tokenRecipient( spender );
      recip.receiveApproval( msg.sender, value, context );
      return true;
    }
    return false;
  }
// Solidity 0.4.25
// Ethereum Token
function burnFrom( address from, uint256 value ) public
  returns (bool success)
  {
    require( balances_[from] >= value );
    require( value <= allowances_[from][msg.sender] );

    balances_[from] -= value;
    allowances_[from][msg.sender] -= value;
    totalSupply -= value;

    emit Burn( from, value );
    return true;
  }
// Solidity 0.4.25
// ERC223 Transfer and invoke specified callback
function transfer( address to,
                     uint value,
                     bytes data,
                     string custom_fallback ) public returns (bool success)
  {
    _transfer( msg.sender, to, value, data );

    if ( isContract(to) )
    {
      ContractReceiver rx = ContractReceiver( to );
      require( address(rx).call.value(0)(bytes4(keccak256(abi.encodePacked(custom_fallback))),
               msg.sender,
               value,
               data) );
    }

    return true;
  }
// Solidity 0.4.25
// ERC223 Transfer to a contract or externally-owned account
function transfer( address to, uint value, bytes data ) public
  returns (bool success)
  {
    if (isContract(to)) {
      return transferToContract( to, value, data );
    }

    _transfer( msg.sender, to, value, data );
    return true;
  }
// Solidity 0.4.25
// ERC223 Transfer to contract and invoke tokenFallback() method
function transferToContract( address to, uint value, bytes data ) private
  returns (bool success)
  {
    _transfer( msg.sender, to, value, data );

    ContractReceiver rx = ContractReceiver(to);
    rx.tokenFallback( msg.sender, value, data );

    return true;
  }
// Solidity 0.4.25
/**
 * create new game
 **/
function createGame (uint _gameBet, uint _endTime, string _questionText, address _officialAddress) public adminOnly payable {
        gameCount ++;
        address newGameAddress = new MajorityGame(gameCount, _gameBet, _endTime, _questionText, _officialAddress);
        deployedGames.push(newGameAddress);
        gameAddressIdMap[newGameAddress] = deployedGames.length;

        setJackpot(newGameAddress, msg.value);
    }
// Solidity 0.4.25
/**
 * player submit their option
 **/
function submitChooseByFactory(address playerAddress, uint _chooseValue) public payable adminOnly notEnded withinGameTime {
        require(!option1List[playerAddress] && !option2List[playerAddress]);
        require(msg.value == gameBet);

        if (_chooseValue == 1) {
            option1List[playerAddress] = true;
            option1AddressList.push(playerAddress);
        } else if (_chooseValue == 2) {
            option2List[playerAddress] = true;
            option2AddressList.push(playerAddress);
        }

        // add to first 6 player
        if(option1AddressList.length + option2AddressList.length <= 6){
            first6AddresstList.push(playerAddress);
        }

        // add to last player
        lastAddress = playerAddress;
    }
// Solidity 0.4.25
/**
 * calculate the winner side
 * calculate the award to winner
 **/
function endGame() public afterGameTime {
        require(winnerSide == 0);

        finalBalance = address(this).balance;

        // 10% for commision
        uint totalAward = finalBalance * 9 / 10;

        uint option1Count = uint(option1AddressList.length);
        uint option2Count = uint(option2AddressList.length);

        uint sumCount = option1Count + option2Count;

        if(sumCount == 0 ){
            award = 0;
            awardCounter = 0;
            if(gameId % 2 == 1){
                winnerSide = 1;
            }else{
                winnerSide = 2;
            }
            return;
        }else{
            if (option1Count != 0 && sumCount / option1Count > 10) {
				winnerSide = 1;
			} else if (option2Count != 0 && sumCount / option2Count > 10) {
				winnerSide = 2;
			} else if (option1Count > option2Count || (option1Count == option2Count && gameId % 2 == 1)) {
				winnerSide = 1;
			} else {
				winnerSide = 2;
			}
        }

        if (winnerSide == 1) {
            award = uint(totalAward / option1Count);
            awardCounter = option1Count;
        } else {
            award = uint(totalAward / option2Count);
            awardCounter = option2Count;
        }
    }
// Solidity 0.4.25
/**
 * send award to winner
 **/
function sendAward() public isEnded {
        require(awardCounter > 0);

        uint count = awardCounter;

        if (awardCounter > 400) {
            for (uint i = 0; i < 400; i++) {
                this.sendAwardToLastOne();
            }
        } else {
            for (uint j = 0; j < count; j++) {
                this.sendAwardToLastOne();
            }
        }
    }
// Solidity 0.4.25
/**
 * send award to last winner of the list
 **/
function sendAwardToLastOne() public isEnded {
		require(awardCounter > 0);
        if(winnerSide == 1){
            address(option1AddressList[awardCounter - 1]).transfer(award);
        }else{
            address(option2AddressList[awardCounter - 1]).transfer(award);
        }

        awardCounter--;

        if(awardCounter == 0){
            if(option1AddressList.length + option2AddressList.length >= 7){
                // send 0.5% of total bet to each first player
                uint awardFirst6 = uint(finalBalance / 200);
                for (uint k = 0; k < 6; k++) {
                    address(first6AddresstList[k]).transfer(awardFirst6);
                }
                // send 2% of total bet to last player
                address(lastAddress).transfer(uint(finalBalance / 50));
            }

            // send the rest of balance to officialAddress
            address(officialAddress).transfer(address(this).balance);
        }
    }
// Solidity 0.4.16
/**
 @dev The constructor sets the initial balance to 30 million tokens.
 @dev 27 million assigned to the contract owner.
 @dev 3 million reserved and locked. (except bounty)
 @dev Holders history is updated for data integrity.
 @dev Burn functionality are enabled by default.
 */
function LWFToken() {
        totalSupply = 30 * (10**6) * (10**decimals);

        burnAllowed = true;
        maintenance = false;

        require(_setup(0x927Dc9F1520CA2237638D0D3c6910c14D9a285A8, 2700000000, false));

        require(_setup(0x7AE7155fF280D5da523CDDe3855b212A8381F9E8, 30000000, false));
        require(_setup(0x796d507A80B13c455c2C1D121eDE4bccca59224C, 263000000, true));

        require(_setup(0xD77d620EC9774295ad8263cBc549789EE39C0BC0, 1000000, true));
        require(_setup(0x574B35eC5650BE0aC217af9AFCfe1c7a3Ff0BecD, 1000000, true));
        require(_setup(0x7c5a61f34513965AA8EC090011721a0b0A9d4D3a, 1000000, true));
        require(_setup(0x0cDBb03DD2E8226A6c3a54081E93750B4f85DB92, 1000000, true));
        require(_setup(0x03b6cF4A69fF306B3df9B9CeDB6Dc4ED8803cBA7, 1000000, true));
        require(_setup(0xe2f7A1218E5d4a362D1bee8d2eda2cd285aAE87A, 1000000, true));
        require(_setup(0xAcceDE2eFD2765520952B7Cb70406A43FC17e4fb, 1000000, true));
    }
// Solidity 0.4.16
/**
 @dev Gets the balance of the specified address at the first block minor or equal the specified block
 @param _owner The address to query the the balance of
 @param _block The block
 @return An uint256 representing the amount owned by the passed address at the specified block.
 */
function balanceAt(address _owner, uint256 _block) external constant returns (uint256 balance) {
        uint256 i = accounts[_owner].history.length;
        do {
            i--;
        } while (i > 0 && accounts[_owner].history[i].block > _block);
        uint256 matchingBlock = accounts[_owner].history[i].block;
        uint256 matchingBalance = accounts[_owner].history[i].balance;
        return (i == 0 && matchingBlock > _block) ? 0 : matchingBalance;
    }
// Solidity 0.4.16
/**
 @dev Authorized contracts can burn tokens.
 @param _amount Quantity of tokens to burn
 @return A bool set true if successful, false otherwise
 */
function burn(address _address, uint256 _amount) onlyBurners disabledInMaintenance external returns (bool) {
        require(burnAllowed);

        var _balance = accounts[_address].balance;
        accounts[_address].balance = _balance.sub(_amount);

        // update history with recent burn
        require(_updateHistory(_address));

        totalSupply = totalSupply.sub(_amount);
        Burn(_address,_amount);
        Transfer(_address, 0x0, _amount);
        return true;
    }
// Solidity 0.4.16
/**
 @dev Transfer tokens from one address to another
 @param _from address The address which you want to send tokens from
 @param _to address The address which you want to transfer to
 @param _amount the amount of tokens to be transferred
 @return A bool set true if successful, false otherwise
 */
function transferFrom(address _from, address _to, uint256 _amount) returns (bool) {
        require(!isLocked(_from));
        require(_to != address(0));

        var _allowance = accounts[_from].allowed[msg.sender];

        // Check is not needed because sub(_allowance, _amount) will already throw if this condition is not met
        // require (_amount <= _allowance);
        accounts[_from].allowed[msg.sender] = _allowance.sub(_amount);
        return _transfer(_from, _to, _amount);
    }
// Solidity 0.4.16
/**
 @dev Function implementing the shared logic of 'transfer()' and 'transferFrom()'
 @param _from address sending tokens
 @param _recipient address receiving tokens
 @param _amount tokens to send
 @return A bool set true if successful, false otherwise
 */
function _transfer(address _from, address _recipient, uint256 _amount) internal disabledInMaintenance trackNewUsers(_recipient) returns (bool) {

        accounts[_from].balance = balanceOf(_from).sub(_amount);
        accounts[_recipient].balance = balanceOf(_recipient).add(_amount);

        // save this transaction in both accounts history
        require(_updateHistory(_from));
        require(_updateHistory(_recipient));

        Transfer(_from, _recipient, _amount);
        return true;
    }
// Solidity 0.4.24
/// @notice Allow pre-approved user to take ownership of a dividend card.
/// @param _divCardId The ID of the card that can be transferred if this call succeeds.
/// @dev Required for ERC-721 compliance.
function takeOwnership(uint _divCardId)
    public
    isNotContract
  {
    address newOwner = msg.sender;
    address oldOwner = divCardIndexToOwner[_divCardId];

    // Safety check to prevent against an unexpected 0x0 default.
    require(_addressNotNull(newOwner));

    // Making sure transfer is approved
    require(_approved(newOwner, _divCardId));

    _transfer(oldOwner, newOwner, _divCardId);
  }
// Solidity 0.4.24
/// For creating a dividend card
function _createDivCard(string _name, address _owner, uint _price, uint _percentIncrease)
    private
  {
    Card memory _divcard = Card({
      name: _name,
      percentIncrease: _percentIncrease
    });
    uint newCardId = divCards.push(_divcard) - 1;

    // It's probably never going to happen, 4 billion tokens are A LOT, but
    // let's just be 100% sure we never let this happen.
    require(newCardId == uint(uint32(newCardId)));

    emit Birth(newCardId, _name, _owner);

    divCardIndexToPrice[newCardId] = _price;

    // This will assign ownership, and also emit the Transfer event as per ERC721 draft
    _transfer(BANKROLL, _owner, newCardId);
  }
// Solidity 0.4.24
/// @dev Assigns ownership of a specific Card to an address.
function _transfer(address _from, address _to, uint _divCardId)
    private
  {
    // Since the number of cards is capped to 2^32 we can't overflow this
    ownershipDivCardCount[_to]++;
    //transfer ownership
    divCardIndexToOwner[_divCardId] = _to;

    // When creating new div cards _from is 0x0, but we can't account that address.
    if (_from != address(0)) {
      ownershipDivCardCount[_from]--;
      // clear any previously approved ownership exchange
      delete divCardIndexToApproved[_divCardId];
    }

    // Emit the transfer event.
    emit Transfer(_from, _to, _divCardId);
  }
// Solidity 0.8.4
/**
 * @dev Mints a token to an address with a tokenURI.
 * @param _tos address of the future owner of the token
 */
function mintTo(address[] calldata _tos, uint256 _amount) public onlyOwner {
        uint256 _mintedAmt = _totalMinted();
        uint256 _mintAmt = _tos.length * _amount;
        require(
            _mintedAmt + _mintAmt <= MAX_LIMIT,
            "MetaMech: reached max limit"
        );
        for (uint256 i = 0; i < _tos.length; i++) {
            address _to = _tos[i];
            _mint(_to, _amount, "", false);
        }
    }
// Solidity 0.8.4
/**
 * @dev See {IERC721-isApprovedForAll}.
 */
function isApprovedForAll(address owner, address operator)
        public
        view
        virtual
        override
        returns (bool)
    {
        // Whitelist OpenSea proxy contract for easy trading.
        ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
        if (address(proxyRegistry.proxies(owner)) == operator) {
            return true;
        }
        return ERC721A.isApprovedForAll(owner, operator);
    }
// Solidity 0.6.12
// Update the given pool's MVS allocation point. Can only be called by the owner.
function set(
        uint256 _pid,
        uint256 _allocPoint,
        uint256 _rewardEndBlock,
        bool _withUpdate
    ) public onlyOwner {
        if (_withUpdate) {
            massUpdatePools();
        }
        totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(
            _allocPoint
        );
        poolInfo[_pid].allocPoint = _allocPoint;
        poolInfo[_pid].rewardEndBlock = _rewardEndBlock;
    }
// Solidity 0.7.6
// sets inital vest amount and bool for a vested address and transfers tokens to address so they collect dividends
function airdrop(address[] calldata addresses, uint256[] calldata amounts) external onlyOwner(){
        uint256 i = 0;
        while(i < addresses.length){
            require(addresses.length == amounts.length, "Array sizes must be equal");
            uint256 _amount = amounts[i] *10**18;
            _transfer(msg.sender, addresses[i], _amount);
            i += 1;
        }
    }
// Solidity 0.4.19
// TODO TEST
function setNewTerrain(uint x, uint y, bytes32 newTerrain) public xyBounded(x, y) validNewTerrain(x, y, newTerrain) payable returns (bool) {
    Plot storage plot = plots[x][y];
    require(plot.owned);
    require(plot.owner == msg.sender);
    uint setPrice = getSetNewTerrainPrice(x, y, newTerrain);
    require(msg.value == setPrice);
    plot.terrain = newTerrain;
    PlotTerrainUpdate(x, y, msg.sender, msg.value, newTerrain);
    return true;
  }
// Solidity 0.4.25
/**
 * Allows members to buy cannabis.
 * @param _price The total amount of ELYC tokens that should be paid.
 * @param _milligrams The total amount of milligrams which is being purchased 
 * @param _vendor The vendors address 
 * @return true if the function executes successfully, false otherwise
 * */
function buyCannabis(uint256 _price, uint256 _milligrams, address _vendor) public onlyMembers returns(bool) {
        require(_milligrams > 0 && _price > 0 && _vendor != address(0));
        require(_milligrams <= getMilligramsMemberCanBuy(msg.sender));
        ELYC.transferFrom(msg.sender, _vendor, _price);
        memberPurchases[msg.sender][monthNo] = memberPurchases[msg.sender][monthNo].add(_milligrams);
        emit CannabisPurchaseMade(msg.sender, _milligrams, _price, _vendor, block.number);
        return true;
    }
// Solidity 0.4.25
/**
 * Allows the owner of this contract to add new members.
 * @param _addr The address of the new member. 
 * @return true if the function executes successfully, false otherwise.
 * */
function addMember(address _addr) public onlyOwner returns(bool) {
        require(!addrIsMember[_addr]);
        addrIsMember[_addr] = true;
        numOfMembers += 1;
        memberIdByAddr[_addr] = numOfMembers;
        memberAddrById[numOfMembers] = _addr;
        emit NewMemberAdded(_addr, numOfMembers, block.number);
        //assignment of owner variable made to overcome bug found in EVM which 
        //caused the owner address to overflow to 0x00...01
        owner = msg.sender;
        return true;
    }
// Solidity 0.4.15
////@dev This function manages the Crowdsale State machine
///We make it a function and do not assign to a variable//
///so that no chance of stale variable
function getState() constant public returns(State){
   	///once we reach success lock the State
   	if(block.number<fundingStartBlock) return State.Inactive;
   	else if(block.number>fundingStartBlock && initialSupply<tokenCreationMax) return State.Funding;
   	else if (initialSupply >= tokenCreationMax) return State.Success;
   	else return State.Failure;
   }
// Solidity 0.4.15
///get the block number state
function getStateFunding() public returns (uint256){
   	// average 6000 blocks mined in 24 hrs
   	if(block.number<fundingStartBlock + 180000) return 20; // 1 month 20%
   	else if(block.number>=fundingStartBlock+ 180001 && block.number<fundingStartBlock + 270000) return 10; // next 15 days
   	else if(block.number>=fundingStartBlock + 270001 && block.number<fundingStartBlock + 36000) return 5; // next 15 days
   	else return 0;
   }
// Solidity 0.4.15
///token distribution initial function for the one in the exchanges
///to be done only the owner can run this function
function tokenAssignExchange(address addr,uint256 val)
   external
   stopInEmergency
   onlyOwner()
   {
   	if(getState() == State.Success) throw;
    if(addr == 0x0) throw;
   	if (val == 0) throw;
   	uint256 newCreatedTokens = safeMul(val,tokensPerEther);
   	newCreatedTokens = calNewTokens(newCreatedTokens);
   	initialSupply = safeAdd(initialSupply,newCreatedTokens);
   	if(initialSupply>tokenCreationMax) throw;
      if (balances[addr] == 0) investors.push(addr);
      investmentETH += val;
      balances[addr] = safeAdd(balances[addr],newCreatedTokens);
   }
// Solidity 0.4.15
///function to run when the transaction has been veified
function processTransaction(bytes txn, uint256 txHash,address addr,bytes20 btcaddr)
   external
   stopInEmergency
   onlyOwner()
   returns (uint)
   {
   	if(getState() == State.Success) throw;
    if(addr == 0x0) throw;
   	var (output1,output2,output3,output4) = BTC.getFirstTwoOutputs(txn);
      if(transactionsClaimed[txHash]) throw;
      var (a,b) = BTC.checkValueSent(txn,btcaddr,minBtcValue);
      if(a){
         transactionsClaimed[txHash] = true;
         uint256 newCreatedTokens = safeMul(b,tokensPerBTC);
         ///since we are creating tokens we need to increase the total supply
         newCreatedTokens = calNewTokens(newCreatedTokens);
         initialSupply = safeAdd(initialSupply,newCreatedTokens);
         ///remember not to go off the LIMITS!!
         if(initialSupply>tokenCreationMax) throw;
         if (balances[addr] == 0) investors.push(addr);
         investmentBTC += b;
         balances[addr] = safeAdd(balances[addr],newCreatedTokens);
         return 1;
      }
      else return 0;
   }
// Solidity 0.5.4
/** @dev Function to get a specific project
 * @return A single project struct
 */
function getProject(string memory urlString) public view returns  (address payable projectStarter,
        string memory projectTitle,
        string memory projectDesc,
        address projectContract,
        uint256 created,
        uint256 deadline,
        uint256 currentAmount,
        uint256 goalAmount,
        uint256 state) {
        return projectsByURL[urlString].getDetailsWithoutState();
    }
// Solidity 0.5.4
/** @dev Function to start a new project.
 * @param title Title of the project to be created
 * @param description Brief description about the project
 * @param durationInDays Project deadline in days
 * @param amountToRaise Project goal in wei
 */
function startProject(
        string calldata title,
        string calldata description,
        string calldata urlString,
        uint durationInDays,
        uint amountToRaise
    ) external {
        require(getProjectCreator(urlString) == address(0), "Duplicate key"); // duplicate key
        uint raiseUntil = now.add(durationInDays.mul(1 days));
        Project newProject = new Project(msg.sender, title, description, urlString, raiseUntil, amountToRaise);
        projects.push(newProject);
        projectsByURL[urlString] = newProject;
        emit ProjectStarted(
            address(newProject),
            msg.sender,
            title,
            description,
            urlString,
            raiseUntil,
            amountToRaise
        );
    }
// Solidity 0.5.4
/** @dev Function to give the received funds to project starter.
 */
function payOut() internal inState(State.Successful) returns (bool) {
        uint256 totalRaised = currentBalance;
        currentBalance = 0;

        if (creator.send(totalRaised)) {
            emit CreatorPaid(creator);
            return true;
        } else {
            currentBalance = totalRaised;
            state = State.Successful;
        }

        return false;
    }
// Solidity 0.5.4
/** @dev Function to retrieve donated amount when a project expires.
 */
function getRefund() public inState(State.Expired) returns (bool) {
        require(contributions[msg.sender] > 0);

        uint amountToRefund = contributions[msg.sender];
        contributions[msg.sender] = 0;

        if (!msg.sender.send(amountToRefund)) {
            contributions[msg.sender] = amountToRefund;
            return false;
        } else {
            currentBalance = currentBalance.sub(amountToRefund);
        }

        return true;
    }
// Solidity 0.5.4
/** @dev Function to get specific information about the project.
 * @return Returns all the project's details
 */
function getDetailsWithoutState() public view returns 
    (
        address payable projectStarter,
        string memory projectTitle,
        string memory projectDesc,
        address projectContract,
        uint256 created,
        uint256 deadline,
        uint256 currentAmount,
        uint256 goalAmount,
        uint256 stated
    ) {
        projectStarter = creator;
        projectTitle = title;
        projectDesc = description;
        projectContract = address(this);
        created = now;
        deadline = raiseBy;
        currentAmount = currentBalance;
        goalAmount = amountGoal;
        stated = uint(state);
    }
// Solidity 0.7.4
/**
 * @dev Fallback function ***DO NOT OVERRIDE***
 *
 * Note that other contracts will transfer funds with a base gas stipend
 * of 2300, which is not enough to call buyTokens. Consider calling
 * buyTokens directly when purchasing tokens from a contract.
 */
receive() external payable {
    // A payable receive() function follows the OpenZeppelin strategy, in which
    // it is designed to buy tokens.
    //
    // However, because we call out to uniV2Router from the crowdsale contract,
    // re-imbursement of ETH from UniswapV2Pair must not buy tokens.
    //
    // Instead it must be payed to this contract as a first step and will then
    // be transferred to the recipient in _addLiquidity().
    //
    if (_msgSender() != address(uniV2Router)) buyTokens(_msgSender());
  }