lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.19
/**
 	 * @dev Internal function to add a token ID to the list of a given address
 	 * @param _to address representing the new owner of the given token ID
 	 * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
 	 */
function addToken(address[16] _contracts, address _to, uint256 _tokenId) private {
		var ownStorage = BdpOwnershipStorage(BdpContracts.getBdpOwnershipStorage(_contracts));

		require(ownStorage.getTokenOwner(_tokenId) == address(0));

		// Set token owner
		ownStorage.setTokenOwner(_tokenId, _to);

		// Add token to tokenIds list
		var tokenIdsLength = ownStorage.pushTokenId(_tokenId);
		ownStorage.setTokenIdsIndex(_tokenId, tokenIdsLength.sub(1));

		uint256 ownedTokensLength = ownStorage.getOwnedTokensLength(_to);

		// Add token to ownedTokens list
		ownStorage.pushOwnedToken(_to, _tokenId);
		ownStorage.setOwnedTokensIndex(_tokenId, ownedTokensLength);

		// Increment total owned area
		var (area,,) = BdpCalculator.calculateArea(_contracts, _tokenId);
		ownStorage.incrementOwnedArea(_to, area);
	}
// Solidity 0.4.19
/**
 	 * @dev Remove token from ownedTokens list
 	 * Note that this will handle single-element arrays. In that case, both ownedTokenIndex and lastOwnedTokenIndex are going to
 	 * be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
 	 * the lastOwnedToken to the first position, and then dropping the element placed in the last position of the list
 	 */
function removeFromOwnedToken(BdpOwnershipStorage _ownStorage, address _from, uint256 _tokenId) private {
		var ownedTokenIndex = _ownStorage.getOwnedTokensIndex(_tokenId);
		var lastOwnedTokenIndex = _ownStorage.getOwnedTokensLength(_from).sub(1);
		var lastOwnedToken = _ownStorage.getOwnedToken(_from, lastOwnedTokenIndex);
		_ownStorage.setOwnedToken(_from, ownedTokenIndex, lastOwnedToken);
		_ownStorage.setOwnedToken(_from, lastOwnedTokenIndex, 0);
		_ownStorage.decrementOwnedTokensLength(_from);
		_ownStorage.setOwnedTokensIndex(_tokenId, 0);
		_ownStorage.setOwnedTokensIndex(lastOwnedToken, ownedTokenIndex);
	}
// Solidity 0.4.19
// BdpControllerHelper
function () public {
		address _impl = BdpContracts.getBdpControllerHelper(contracts);
		require(_impl != address(0));
		bytes memory data = msg.data;

		assembly {
			let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0)
			let size := returndatasize
			let ptr := mload(0x40)
			returndatacopy(ptr, 0, size)
			switch result
			case 0 { revert(ptr, size) }
			default { return(ptr, size) }
		}
	}
// Solidity 0.8.12
/**
 * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
 * revert reason using the provided one.
 *
 * _Available since v4.3._
 */
function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
// Solidity 0.8.12
/**
 * @dev Destroys `tokenId`.
 * The approval is cleared when the token is burned.
 *
 * Requirements:
 *
 * - `tokenId` must exist.
 *
 * Emits a {Transfer} event.
 */
function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId); // internal owner

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        // Clear metadata (if any)
        if (bytes(_tokenURIs[tokenId]).length != 0) {
            delete _tokenURIs[tokenId];
        }

        _holderTokens[owner].remove(tokenId);

        _tokenOwners.remove(tokenId);

        emit Transfer(owner, address(0), tokenId);
    }
// Solidity 0.4.24
// Initializes contract
function WatermelonBlockToken(address _icoAddr, address _teamAddr, address _emergencyAddr) {
        icoAddr = _icoAddr;
        teamAddr = _teamAddr;
        emergencyAddr = _emergencyAddr;

        balances[icoAddr] = tokensICO;
        balances[teamAddr] = teamReserve;

        // seed investors
        address investor_1 = 0xF735e4a0A446ed52332AB891C46661cA4d9FD7b9;
        balances[investor_1] = 20000000e6;
        var lockupTime = lockStartTime.add(1 years);
        lockup = Lockup({lockupTime:lockupTime,lockupAmount:balances[investor_1]});
        lockupParticipants[investor_1] = lockup;

        address investor_2 = 0x425207D7833737b62E76785A3Ab3f9dEce3953F5;
        balances[investor_2] = 8000000e6;
        lockup = Lockup({lockupTime:lockupTime,lockupAmount:balances[investor_2]});
        lockupParticipants[investor_2] = lockup;

        var leftover = seedInvestorsReserve.sub(balances[investor_1]).sub(balances[investor_2]);
        balances[emergencyAddr] = emergencyReserve.add(leftover);
    }
// Solidity 0.4.24
// Send some of your tokens to a given address
function transfer(address _to, uint _value) returns(bool) {
        if (lockupParticipants[msg.sender].lockupAmount > 0) {
            if (now < lockupParticipants[msg.sender].lockupTime) {
                require(balances[msg.sender].sub(_value) >= lockupParticipants[msg.sender].lockupAmount);
            }
        }
        if (msg.sender == teamAddr) {
            for (uint i = 0; i < lockupTeamDate.length; i++) {
                if (now < lockupTeamDate[i])
                    require(balances[msg.sender].sub(_value) >= lockupTeamSum[i]);
            }
        }
        balances[msg.sender] = balances[msg.sender].sub(_value); // Subtract from the sender
        balances[_to] = balances[_to].add(_value); // Add the same to the recipient
        Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
        return true;
    }
// Solidity 0.4.24
// A contract or person attempts to get the tokens of somebody else.
// This is only allowed if the token holder approved.
function transferFrom(address _from, address _to, uint _value) returns(bool) {
        if (lockupParticipants[_from].lockupAmount > 0) {
            if (now < lockupParticipants[_from].lockupTime) {
                require(balances[_from].sub(_value) >= lockupParticipants[_from].lockupAmount);
            }
        }
        if (_from == teamAddr) {
            for (uint i = 0; i < lockupTeamDate.length; i++) {
                if (now < lockupTeamDate[i])
                    require(balances[_from].sub(_value) >= lockupTeamSum[i]);
            }
        }
        var _allowed = allowed[_from][msg.sender];
        balances[_from] = balances[_from].sub(_value); // Subtract from the sender
        balances[_to] = balances[_to].add(_value); // Add the same to the recipient
        allowed[_from][msg.sender] = _allowed.sub(_value);
        Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.6.12
// >>> approve other rewards on dex
// function _approveDex() internal override { super._approveDex(); }
// >>> include other rewards
// function _migrateRewards(address _newStrategy) internal override { super._migrateRewards(_newStrategy); }
// >>> include all other rewards in eth besides _claimableBasicInETH()
// function _claimableInETH() internal override view returns (uint256 _claimable) { _claimable = super._claimableInETH(); }
function _setPathTarget(uint _tokenId, uint _id) internal {
        if (_id == 0) { 
            pathTarget[_tokenId] = usdt;
        }
        else if (_id == 1) {
            pathTarget[_tokenId] = wbtc;
        }
        else {
            pathTarget[_tokenId] = weth;
        }
    }
// Solidity 0.4.26
/// @dev Sets the reference to the plugin contract.
/// @param _address - Address of plugin contract.
function addPlugin(address _address) external onlyOwner
    {
        PluginInterface candidateContract = PluginInterface(_address);

        // verify that a contract is what we expect
        require(candidateContract.isPluginInterface());

        // Set the new contract address
        plugins[_address] = candidateContract;
        pluginsArray.push(candidateContract);
    }
// Solidity 0.4.26
/// @dev Remove plugin and calls onRemove to cleanup
function removePlugin(address _address) external onlyOwner
    {
        plugins[_address].onRemove();
        delete plugins[_address];

        uint256 kindex = 0;
        while (kindex < pluginsArray.length)
        {
            if (address(pluginsArray[kindex]) == _address)
            {
                pluginsArray[kindex] = pluginsArray[pluginsArray.length-1];
                pluginsArray.length--;
            }
            else
            {
                kindex++;
            }
        }
    }
// Solidity 0.4.26
/// @dev Common function to be used also in backend
function getSigner(
        address _pluginAddress,
        uint40 _signId,
        uint40 _cutieId,
        uint128 _value,
        uint256 _parameter,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    )
    public pure returns (address)
    {
        bytes32 msgHash = hashArguments(_pluginAddress, _signId, _cutieId, _value, _parameter);
        return ecrecover(msgHash, _v, _r, _s);
    }
// Solidity 0.4.26
/// @dev Put a cutie up for plugin feature with signature.
///  Can be used for items equip, item sales and other features.
///  Signatures are generated by Operator role.
function runPluginSigned(
        address _pluginAddress,
        uint40 _signId,
        uint40 _cutieId,
        uint128 _value,
        uint256 _parameter,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    )
        external
//        whenNotPaused
        payable
    {
        require (isValidSignature(_pluginAddress, _signId, _cutieId, _value, _parameter, _v, _r, _s));

        require(address(plugins[_pluginAddress]) != address(0));

        require (usedSignes[_signId] == address(0));

        require (_signId >= minSignId);
        // value can also be zero for free calls

        require (_value <= msg.value);

        usedSignes[_signId] = msg.sender;

        if (_cutieId > 0)
        {
            // If cutie is already on any auction or in adventure, this will throw
            // as it will be owned by the other contract.
            // If _cutieId is 0, then cutie is not used on this feature.

            coreContract.checkOwnerAndApprove(msg.sender, _cutieId, _pluginAddress);
        }

        emit SignUsed(_signId, msg.sender);

        // Plugin contract throws if inputs are invalid and clears
        // transfer after escrowing the cutie.
        plugins[_pluginAddress].runSigned.value(_value)(
            _cutieId,
            _parameter,
            msg.sender
        );
    }
// Solidity 0.4.26
/// @dev Put a cutie up for plugin feature.
function runPlugin(
        address _pluginAddress,
        uint40 _cutieId,
        uint256 _parameter
    ) external payable
    {
        // If cutie is already on any auction or in adventure, this will throw
        // because it will be owned by the other contract.
        // If _cutieId is 0, then cutie is not used on this feature.
        require(address(plugins[_pluginAddress]) != address(0));
        if (_cutieId > 0)
        {
            coreContract.checkOwnerAndApprove(msg.sender, _cutieId, _pluginAddress);
        }

        // Plugin contract throws if inputs are invalid and clears
        // transfer after escrowing the cutie.
        plugins[_pluginAddress].run.value(msg.value)(
            _cutieId,
            _parameter,
            msg.sender
        );
    }
// Solidity 0.8.0
// private sale (25% discount)
function presale(uint256 amount) public payable returns (bool) {
        if (block.timestamp < startTimeStamp || block.timestamp >= endTimeStamp) {
            return false;
        }

        uint256 presaleAmount = amount * 10 ** 18;
        lvnContract.presale(msg.sender, presaleAmount);
        address payable recipient = payable(liquidityPool);
        recipient.transfer(msg.value);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev registers a name.  UI will always display the last name you registered.
 * but you will still own all previously registered names to use as affiliate 
 * links.
 * - must pay a registration fee.
 * - name must be unique
 * - names will be converted to lowercase
 * - name cannot start or end with a space 
 * - cannot have more than 1 space in a row
 * - cannot be only numbers
 * - cannot start with 0x 
 * - name must be at least 1 char
 * - max length of 32 characters long
 * - allowed characters: a-z, 0-9, and space
 * -functionhash- 0x921dec21 (using ID for affiliate)
 * -functionhash- 0x3ddd4698 (using address for affiliate)
 * -functionhash- 0x685ffd83 (using name for affiliate)
 * @param _nameString players desired name
 * @param _affCode affiliate ID, address, or name of who refered you
 * @param _all set to true if you want this to push your info to all games 
 * (this might cost a lot of gas)
 */
function registerNameXID(string _nameString, uint256 _affCode, bool _all)
        isHuman()
        public
        payable 
    {
        // make sure name fees paid
        require (msg.value >= registrationFee_, "umm.....  you have to pay the name fee");
        
        // filter name + condition checks
        bytes32 _name = NameFilter.nameFilter(_nameString);
        
        // set up address 
        address _addr = msg.sender;
        
        // set up our tx event data and determine if player is new or not
        bool _isNewPlayer = determinePID(_addr);
        
        // fetch player id
        uint256 _pID = pIDxAddr_[_addr];
        
        // manage affiliate residuals
        // if no affiliate code was given, no new affiliate code was given, or the 
        // player tried to use their own pID as an affiliate code, lolz
        if (_affCode != 0 && _affCode != plyr_[_pID].laff && _affCode != _pID) 
        {
            // update last affiliate 
            plyr_[_pID].laff = _affCode;
        } else if (_affCode == _pID) {
            _affCode = 0;
        }
        
        // register name 
        registerNameCore(_pID, _addr, _affCode, _name, _isNewPlayer, _all);
    }
// Solidity 0.4.24
/**
 * @dev players, if you registered a profile, before a game was released, or
 * set the all bool to false when you registered, use this function to push
 * your profile to a single game.  also, if you've  updated your name, you
 * can use this to push your name to games of your choosing.
 * -functionhash- 0x81c5b206
 * @param _gameID game id 
 */
function addMeToGame(uint256 _gameID)
        isHuman()
        public
    {
        require(_gameID <= gID_, "silly player, that game doesn't exist yet");
        address _addr = msg.sender;
        uint256 _pID = pIDxAddr_[_addr];
        require(_pID != 0, "hey there buddy, you dont even have an account");
        uint256 _totalNames = plyr_[_pID].names;
        
        // add players profile and most recent name
        games_[_gameID].receivePlayerInfo(_pID, _addr, plyr_[_pID].name, plyr_[_pID].laff);
        
        // add list of all names
        if (_totalNames > 1)
            for (uint256 ii = 1; ii <= _totalNames; ii++)
                games_[_gameID].receivePlayerNameList(_pID, plyrNameList_[_pID][ii]);
    }
// Solidity 0.4.24
/**
 * @dev players, use this to push your player profile to all registered games.
 * -functionhash- 0x0c6940ea
 */
function addMeToAllGames()
        isHuman()
        public
    {
        address _addr = msg.sender;
        uint256 _pID = pIDxAddr_[_addr];
        require(_pID != 0, "hey there buddy, you dont even have an account");
        uint256 _laff = plyr_[_pID].laff;
        uint256 _totalNames = plyr_[_pID].names;
        bytes32 _name = plyr_[_pID].name;
        
        for (uint256 i = 1; i <= gID_; i++)
        {
            games_[i].receivePlayerInfo(_pID, _addr, _name, _laff);
            if (_totalNames > 1)
                for (uint256 ii = 1; ii <= _totalNames; ii++)
                    games_[i].receivePlayerNameList(_pID, plyrNameList_[_pID][ii]);
        }
                
    }
// Solidity 0.4.24
/**
 * @dev players use this to change back to one of your old names.  tip, you'll
 * still need to push that info to existing games.
 * -functionhash- 0xb9291296
 * @param _nameString the name you want to use 
 */
function useMyOldName(string _nameString)
        isHuman()
        public 
    {
        // filter name, and get pID
        bytes32 _name = _nameString.nameFilter();
        uint256 _pID = pIDxAddr_[msg.sender];
        
        // make sure they own the name 
        require(plyrNames_[_pID][_name] == true, "umm... thats not a name you own");
        
        // update their current name 
        plyr_[_pID].name = _name;
    }
// Solidity 0.5.11
/**
 * @dev Custom accessor to create a unique token
 * @param _to address of diamond owner
 * @param _issuer string the issuer agency name
 * @param _report string the issuer agency unique Nr.
 * @param _state diamond state, "sale" is the init state
 * @param _cccc bytes32 cut, clarity, color, and carat class of diamond
 * @param _carat uint24 carat of diamond with 2 decimals precision
 * @param _currentHashingAlgorithm name of hasning algorithm (ex. 20190101)
 * @param _custodian the custodian of minted dpass
 * @return Return Diamond tokenId of the diamonds list
 */
function mintDiamondTo(
        address _to,
        address _custodian,
        bytes3 _issuer,
        bytes16 _report,
        bytes8 _state,
        bytes20 _cccc,
        uint24 _carat,
        bytes32 _attributesHash,
        bytes8 _currentHashingAlgorithm
    )
        public auth
        returns(uint)
    {
        require(ccccs[_cccc], "dpass-wrong-cccc");
        _addToDiamondIndex(_issuer, _report);

        Diamond memory _diamond = Diamond({
            issuer: _issuer,
            report: _report,
            state: _state,
            cccc: _cccc,
            carat: _carat,
            currentHashingAlgorithm: _currentHashingAlgorithm
        });
        uint _tokenId = diamonds.push(_diamond) - 1;
        proof[_tokenId][_currentHashingAlgorithm] = _attributesHash;
        custodian[_tokenId] = _custodian;

        _mint(_to, _tokenId);
        emit LogDiamondMinted(_to, _tokenId, _issuer, _report, _state);
        return _tokenId;
    }
// Solidity 0.5.11
/**
 * @dev Gets the Diamond at a given _tokenId of all the diamonds in this contract
 * Reverts if the _tokenId is greater or equal to the total number of diamonds
 * @param _tokenId uint representing the index to be accessed of the diamonds list
 * @return Returns all the relevant information about a specific diamond
 */
function getDiamondInfo(uint _tokenId)
        public
        view
        ifExist(_tokenId)
        returns (
            address[2] memory ownerCustodian,
            bytes32[6] memory attrs,
            uint24 carat_
        )
    {
        Diamond storage _diamond = diamonds[_tokenId];
        bytes32 attributesHash = proof[_tokenId][_diamond.currentHashingAlgorithm];

        ownerCustodian[0] = ownerOf(_tokenId);
        ownerCustodian[1] = custodian[_tokenId];

        attrs[0] = _diamond.issuer;
        attrs[1] = _diamond.report;
        attrs[2] = _diamond.state;
        attrs[3] = _diamond.cccc;
        attrs[4] = attributesHash;
        attrs[5] = _diamond.currentHashingAlgorithm;

        carat_ = _diamond.carat;
    }
// Solidity 0.4.26
/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold
function sell(uint256 amount) public {
        address myAddress = this;
        require(myAddress.balance >= amount * sellPrice);      // checks if the contract has enough ether to buy
        _transfer(msg.sender, this, amount);              // makes the transfers
        msg.sender.transfer(amount * sellPrice);          // sends ether to the seller. It's important to do this last to avoid recursion attacks
    }
// Solidity 0.4.24
// Separate function as it is used by derived contracts too
function _removeBid(uint bidId) internal {
    Bid memory thisBid = bids[ bidId ];
    bids[ thisBid.prev ].next = thisBid.next;
    bids[ thisBid.next ].prev = thisBid.prev;

    delete bids[ bidId ]; // clearning storage
    delete contributors[ msg.sender ]; // clearning storage
    // cannot delete from accountsList - cannot shrink an array in place without spending shitloads of gas
  }
// Solidity 0.4.24
// We are  starting from TAIL and going upwards
// This is to simplify the case of increasing bids (can go upwards, cannot go lower)
// NOTE: blockSize gas limit in case of so many bids (wishful thinking)
function searchInsertionPoint(uint _contribution, uint _startSearch) view public returns (uint) {
    require(_contribution > bids[_startSearch].value, "your contribution and _startSearch does not make sense, it will search in a wrong direction");

    Bid memory lowerBid = bids[_startSearch];
    Bid memory higherBid;

    while(true) { // it is guaranteed to stop as we set the HEAD bid with very high maximum valuation
      higherBid = bids[lowerBid.next];

      if (_contribution < higherBid.value) {
        return higherBid.prev;
      } else {
        lowerBid = higherBid;
      }
    }
  }
// Solidity 0.4.24
/**
 * @dev Inits the wallet by setting the owner and authorising a list of modules.
 * @param _owner The owner.
 * @param _modules The modules to authorise.
 */
function init(address _owner, address[] _modules) external {
        require(owner == address(0) && modules == 0, "BW: wallet already initialised");
        require(_modules.length > 0, "BW: construction requires at least 1 module");
        owner = _owner;
        modules = _modules.length;
        for(uint256 i = 0; i < _modules.length; i++) {
            require(authorised[_modules[i]] == false, "BW: module is already added");
            authorised[_modules[i]] = true;
            Module(_modules[i]).init(this);
            emit AuthorisedModule(_modules[i], true);
        }
    }
// Solidity 0.4.24
/**
 * @dev Enables/Disables a module.
 * @param _module The target module.
 * @param _value Set to true to authorise the module.
 */
function authoriseModule(address _module, bool _value) external moduleOnly {
        if (authorised[_module] != _value) {
            if(_value == true) {
                modules += 1;
                authorised[_module] = true;
                Module(_module).init(this);
            }
            else {
                modules -= 1;
                require(modules > 0, "BW: wallet must have at least one module");
                delete authorised[_module];
            }
            emit AuthorisedModule(_module, _value);
        }
    }
// Solidity 0.5.12
/**
 * Initializes this wrapper contract
 * 
 * Should set cards, proto, quality, and uniswap exchange
 *
 * Should fail if already initialized by checking if cardWrapperFatory is set
 *
 */
function init(ICards _cards, uint16 _proto, uint8 _quality, IUniswapExchange _uniswapExchange) public {
        require(address(cardWrapperFactory) == address(0x0), 'CardWrapper:Already initialized');
        cardWrapperFactory = CardERC20WrapperFactory(msg.sender);
        uniswapExchange = _uniswapExchange;
        cards = _cards;
        proto = _proto;
        quality = _quality;
    }