lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
/// @dev Fuction for investor, minimun ether send is 0.1, one address can call one time in one session
/// @param _choose choise of investor, true is call, false is put
function invest (bool _choose)
        public
        payable
    {
        require(msg.value >= 100000000000000000 && session.investOpen); // msg.value >= 0.1 ether
        require(now < (session.timeOpen + timeInvestInMinute * 1 minutes));
        require(session.investorCount < MAX_INVESTOR && session.investedSession[msg.sender] != sessionId);
        session.investor[session.investorCount] = msg.sender;
        session.win[session.investorCount] = _choose;
        session.amountInvest[session.investorCount] = msg.value;
        session.investorCount += 1;
        session.investedSession[msg.sender] = sessionId;
        Invest(msg.sender, _choose, msg.value, now, sessionId);
    }
// Solidity 0.4.18
/// @dev get amount of ether to buy NAC for investor
/// @param _ether amount ether which investor invest
/// @param _rate rate between win and loss investor
/// @param _status true for investor win and false for investor loss
function getEtherToBuy (uint _ether, uint _rate, bool _status)
        public
        pure
        returns (uint)
    {
        if (_status) {
            return _ether * _rate / 100;
        } else {
            return _ether * (200 - _rate) / 100;
        }
    }
// Solidity 0.4.18
/// @dev close session, only escrow can call
/// @param _priceClose price of ETH in USD
function closeSession (uint _priceClose)
        public
        onlyEscrow
    {
        require(_priceClose != 0 && now > (session.timeOpen + timeOneSession * 1 minutes));
        require(!session.investOpen && session.isOpen);
        session.priceClose = _priceClose;
        bool result = (_priceClose>session.priceOpen)?true:false;
        uint etherToBuy;
        NamiCrowdSale namiContract = NamiCrowdSale(namiCrowdSaleAddr);
        uint price = namiContract.getPrice();
        for (uint i = 0; i < session.investorCount; i++) {
            if (session.win[i]==result) {
                etherToBuy = getEtherToBuy(session.amountInvest[i], rate, true);
            } else {
                etherToBuy = getEtherToBuy(session.amountInvest[i], rate, false);
            }
            namiContract.buy.value(etherToBuy)(session.investor[i]);
            // reset investor
            session.investor[i] = 0x0;
            session.win[i] = false;
            session.amountInvest[i] = 0;
        }
        session.isOpen = false;
        SessionClose(now, sessionId, _priceClose, price, rate);
        sessionId += 1;
        
        // require(!session.isReset && !session.isOpen);
        // reset state session
        session.priceOpen = 0;
        session.priceClose = 0;
        session.isReset = true;
        session.investOpen = false;
        session.investorCount = 0;
    }
// Solidity 0.4.18
// prevent lost ether
function() payable public {
        require(msg.value > 0);
        if (bid[msg.sender].price > 0) {
            bid[msg.sender].eth = (bid[msg.sender].eth).add(msg.value);
            etherBalance = etherBalance.add(msg.value);
            UpdateBid(msg.sender, bid[msg.sender].price, bid[msg.sender].eth);
        } else {
            // refund
            msg.sender.transfer(msg.value);
        }
        // test
        // address test = "0x70c932369fc1C76fde684FF05966A70b9c1561c1";
        // test.transfer(msg.value);
    }
// Solidity 0.4.18
// prevent lost token
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool success) {
        require(_value > 0 && _data.length == 0);
        if (ask[_from].price > 0) {
            ask[_from].volume = (ask[_from].volume).add(_value);
            nacBalance = nacBalance.add(_value);
            UpdateAsk(_from, ask[_from].price, ask[_from].volume);
            return true;
        } else {
            //refund
            ERC23 asset = ERC23(NamiAddr);
            asset.transfer(_from, _value);
            return false;
        }
    }
// Solidity 0.4.18
// function about ask Order-----------------------------------------------------------
// place ask order by send NAC to contract
function tokenFallbackExchange(address _from, uint _value, uint _price) onlyNami public returns (bool success) {
        require(_price > 0);
        if (_value > 0) {
            nacBalance = nacBalance.add(_value);
            ask[_from].volume = (ask[_from].volume).add(_value);
            ask[_from].price = _price;
            UpdateAsk(_from, _price, ask[_from].volume);
            return true;
        } else {
            ask[_from].price = _price;
            return false;
        }
    }
// Solidity 0.4.18
/// @dev Allows anyone to execute a confirmed transaction.
/// @param transactionId Transaction ID.
function executeTransaction(uint transactionId)
        public
        notExecuted(transactionId)
    {
        if (isConfirmed(transactionId)) {
            // Transaction tx = transactions[transactionId];
            transactions[transactionId].executed = true;
            // tx.executed = true;
            if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) {
                Execution(transactionId);
            } else {
                ExecutionFailure(transactionId);
                transactions[transactionId].executed = false;
            }
        }
    }
// Solidity 0.4.18
/// @dev Returns total number of transactions after filers are applied.
/// @param pending Include pending transactions.
/// @param executed Include executed transactions.
/// @return Total number of transactions after filters are applied.
function getTransactionCount(bool pending, bool executed)
        public
        constant
        returns (uint count)
    {
        for (uint i = 0; i < transactionCount; i++) {
            if (pending && !transactions[i].executed || executed && transactions[i].executed)
                count += 1;
        }
    }
// Solidity 0.8.10
// Purchases London Ticket
function TicketPurchase() public payable nonReentrant whenNotPaused
    {
        require(_SALE_IS_ACTIVE, "Sale must be active to mint Tickets");
        require(BrightList[msg.sender] > 0, "Ticket Amount Exceeds `msg.sender` Allowance");
        require(_TICKET_INDEX + 1 < _MAX_TICKETS, "Purchase Would Exceed Max Supply Of Tickets");
        require(_TICKET_PRICE == msg.value, "Ether Value Sent Is Not Correct. 1 ETH Per Ticket");
        if(!_ALLOW_MULTIPLE_PURCHASES) { require(!purchased[msg.sender], "Address Has Already Purchased"); }
        BrightList[msg.sender] -= 1;
        IERC721(_TICKET_TOKEN_ADDRESS).transferFrom(_BRT_MULTISIG, msg.sender, _TICKET_INDEX);
        _TICKET_INDEX += 1;
        purchased[msg.sender] = true;
        emit TicketPurchased(msg.sender, 1, _TICKET_INDEX);
    }
// Solidity 0.8.7
/**
 @dev Mint new token and maps to receiver
 */
function mint(uint256 amount, uint256 totalPrice, uint256 nonce, bytes memory signature)
    external
    payable
    whenNotPaused
  {
    require(!_nonceSpended[nonce], "WabiStore: Signature already used");
    require(signer.isValidSignatureNow(keccak256(abi.encodePacked(amount, msg.sender, totalPrice, nonce)), signature), "WabiStore: Invalid signature");
    _nonceSpended[nonce] = true;
    require(msg.value >= totalPrice, "WabiStore: msg.value is less than total price");
    wabiPunks.mint(amount, msg.sender);
  }
// Solidity 0.8.13
/**
 	 @dev only whitelisted can buy, maximum 1
 	 @param id - the ID of the token (eg: 1)
 	 @param proof - merkle proof
 	  */
function presaleBuy(uint256 id, bytes32[] calldata proof) external payable nonReentrant {
		require(pricesPresale[id] != 0, "not live");
		require(pricesPresale[id] == msg.value, "exact amount needed");
		require(block.timestamp >= presaleStartTime, "not live");
		require(usedAddresses[msg.sender] + 1 <= 1, "wallet limit reached");
		require(totalSupply(id) + 1 <= maxSuppliesPresale[id], "out of stock");
		require(isProofValid(msg.sender, 1, proof), "invalid proof");

		usedAddresses[msg.sender] += 1;
		_mint(msg.sender, id, 1, "");
	}
// Solidity 0.4.22
/**
 *   ######################
 *  #  private function  #
 * ######################
 */
function toCompare(uint f, uint s) internal view returns (bool) {

        if (admin.compareSymbol == "-=") {

            return f > s;
        } else if (admin.compareSymbol == "+=") {

            return f >= s;
        } else {

            return false;
        }
    }
// Solidity 0.4.23
/**
 @dev registers a new address for the contract name in the registry
 @param _contractName     contract name
 @param _contractAddress  contract address
 */
function registerAddress(bytes32 _contractName, address _contractAddress)
        public
        ownerOnly
        validAddress(_contractAddress)
    {
        require(_contractName.length > 0); // validate input

        if (items[_contractName].contractAddress == address(0)) {
            // add the contract name to the name list
            uint256 i = contractNames.push(bytes32ToString(_contractName));
            // update the item's index in the list
            items[_contractName].nameIndex = i - 1;
        }

        // update the address in the registry
        items[_contractName].contractAddress = _contractAddress;

        // dispatch the address update event
        emit AddressUpdate(_contractName, _contractAddress);
    }
// Solidity 0.4.23
/**
 @dev removes an existing contract address from the registry
 @param _contractName contract name
 */
function unregisterAddress(bytes32 _contractName) public ownerOnly {
        require(_contractName.length > 0); // validate input
        require(items[_contractName].contractAddress != address(0));

        // remove the address from the registry
        items[_contractName].contractAddress = address(0);

        // if there are multiple items in the registry, move the last element to the deleted element's position
        // and modify last element's registryItem.nameIndex in the items collection to point to the right position in contractNames
        if (contractNames.length > 1) {
            string memory lastContractNameString = contractNames[contractNames.length - 1];
            uint256 unregisterIndex = items[_contractName].nameIndex;

            contractNames[unregisterIndex] = lastContractNameString;
            bytes32 lastContractName = stringToBytes32(lastContractNameString);
            RegistryItem storage registryItem = items[lastContractName];
            registryItem.nameIndex = unregisterIndex;
        }

        // remove the last element from the name list
        contractNames.length--;
        // zero the deleted element's index
        items[_contractName].nameIndex = 0;

        // dispatch the address update event
        emit AddressUpdate(_contractName, address(0));
    }
// Solidity 0.7.6
/// @notice Grant a role to a delegate
/// @dev Granting a role to a delegate will give delegate permission to call
///      contract functions associated with the role. Only owner can grant
///      role and the must be predefined and not granted to the delegate
///      already. on success, `RoleGranted` event would be fired and
///      possibly `DelegateAdded` as well if this is the first role being
///      granted to the delegate.
/// @param role the role to be granted
/// @param delegate the delegate to be granted role
function grantRole(bytes32 role, address delegate)
        external
        onlyOwner
        roleDefined(role)
    {
        require(!_hasRole(role, delegate), "role already granted");

        delegateToRoles[delegate].add(role);

        // We need to emit `DelegateAdded` before `RoleGranted` to allow
        // subgraph event handler to process in sensible order.
        if (delegateSet.add(delegate)) {
            emit DelegateAdded(delegate, _msgSender());
        }

        emit RoleGranted(role, delegate, _msgSender());
    }
// Solidity 0.7.6
/// @notice Revoke a role from a delegate
/// @dev Revoking a role from a delegate will remove the permission the
///      delegate has to call contract functions associated with the role.
///      Only owner can revoke the role.  The role has to be predefined and
///      granted to the delegate before revoking, otherwise the function
///      will be reverted. `RoleRevoked` event would be fired and possibly
///      `DelegateRemoved` as well if this is the last role the delegate
///      owns.
/// @param role the role to be granted
/// @param delegate the delegate to be granted role
function revokeRole(bytes32 role, address delegate)
        external
        onlyOwner
        roleDefined(role)
    {
        require(_hasRole(role, delegate), "role has not been granted");

        delegateToRoles[delegate].remove(role);

        // We need to make sure `RoleRevoked` is fired before `DelegateRemoved`
        // to make sure the event handlers in subgraphs are triggered in the
        // right order.
        emit RoleRevoked(role, delegate, _msgSender());

        if (delegateToRoles[delegate].length() == 0) {
            delegateSet.remove(delegate);
            emit DelegateRemoved(delegate, _msgSender());
        }
    }
// Solidity 0.7.6
/// @notice Batch execute multiple transaction via Gnosis Safe
/// @dev This is batch version of the `execTransaction` function to allow
///      the delegates to bundle multiple calls into a single transaction and
///      sign only once. Batch execute the transactions, one failure cause the
///      batch reverted. Only delegates are allowed to call this.
/// @param toList list of contract addresses to be called
/// @param dataList list of input data associated with each contract call
function batchExecTransactions(
        address[] calldata toList,
        bytes[] calldata dataList
    ) external onlyDelegate {
        require(
            toList.length > 0 && toList.length == dataList.length,
            "invalid inputs"
        );

        for (uint256 i = 0; i < toList.length; i++) {
            _execTransaction(toList[i], dataList[i]);
        }
    }
// Solidity 0.7.6
/// @dev The internal implementation of `execTransaction` and
///      `batchExecTransactions`, that invokes gnosis safe to forward to
///      transaction to target contract method `to`::`func`, where `func` is
///      the function selector contained in first 4 bytes of `data`.  The
///      function checks if the calling delegate has the required permission
///      to call the designated contract function before invoking Gnosis
///      Safe.
/// @param to The target contract to be called by Gnosis Safe
/// @param data The input data to be called by Gnosis Safe
function _execTransaction(address to, bytes memory data) internal {
        bytes4 selector;
        assembly {
            selector := mload(add(data, 0x20))
        }

        require(
            _hasPermission(_msgSender(), to, selector),
            "permission denied"
        );

        // execute the transaction from Gnosis Safe, note this call will bypass
        // safe owners confirmation.
        require(
            GnosisSafe(payable(owner())).execTransactionFromModule(
                to,
                0,
                data,
                Enum.Operation.Call
            ),
            "failed in execution in safe"
        );

        emit ExecTransaction(to, 0, Enum.Operation.Call, data, _msgSender());
    }
// Solidity 0.7.6
/// @dev Internal function to check if a delegate has the permission to call a given contract function
/// @param delegate the delegate to be checked
/// @param to the target contract
/// @param selector the function selector of the contract function to be called
/// @return true|false
function _hasPermission(
        address delegate,
        address to,
        bytes4 selector
    ) internal view returns (bool) {
        bytes32[] memory roles = getRolesByDelegate(delegate);
        EnumerableSet.Bytes32Set storage funcRoles = funcToRoles[to][selector];
        for (uint256 index = 0; index < roles.length; index++) {
            if (funcRoles.contains(roles[index])) {
                return true;
            }
        }
        return false;
    }
// Solidity 0.7.6
/// @notice Associate a role with given contract funcs
/// @dev only owners are allowed to call this function, the given role has
///      to be predefined. On success, the role will be associated with the
///      given contract function, `AssocContractFuncs` event will be fired.
/// @param role the role to be associated
/// @param _contract the contract address to be associated with the role
/// @param funcList the list of contract functions to be associated with the role
function assocRoleWithContractFuncs(
        bytes32 role,
        address _contract,
        string[] calldata funcList
    ) external onlyOwner roleDefined(role) {
        require(funcList.length > 0, "empty funcList");

        for (uint256 index = 0; index < funcList.length; index++) {
            bytes4 funcSelector = bytes4(keccak256(bytes(funcList[index])));
            bytes32 funcSelector32 = bytes32(funcSelector);
            funcToRoles[_contract][funcSelector32].add(role);
            contractToFuncs[_contract].add(funcSelector32);
        }

        contractSet.add(_contract);

        emit AssocContractFuncs(role, _contract, funcList, _msgSender());
    }
// Solidity 0.7.6
/// @notice Dissociate a role from given contract funcs
/// @dev only owners are allowed to call this function, the given role has
///      to be predefined. On success, the role will be disassociated from
///      the given contract function, `DissocContractFuncs` event will be
///      fired.
/// @param role the role to be disassociated
/// @param _contract the contract address to be disassociated from the role
/// @param funcList the list of contract functions to be disassociated from the role
function dissocRoleFromContractFuncs(
        bytes32 role,
        address _contract,
        string[] calldata funcList
    ) external onlyOwner roleDefined(role) {
        require(funcList.length > 0, "empty funcList");

        for (uint256 index = 0; index < funcList.length; index++) {
            bytes4 funcSelector = bytes4(keccak256(bytes(funcList[index])));
            bytes32 funcSelector32 = bytes32(funcSelector);
            funcToRoles[_contract][funcSelector32].remove(role);

            if (funcToRoles[_contract][funcSelector32].length() <= 0) {
                contractToFuncs[_contract].remove(funcSelector32);
            }
        }

        if (contractToFuncs[_contract].length() <= 0) {
            contractSet.remove(_contract);
        }

        emit DissocContractFuncs(role, _contract, funcList, _msgSender());
    }
// Solidity 0.8.13
/**
 	 @dev everyone can buy
 	 @param qty - the quantity that a user wants to buy
 	  */
function publicBuy(uint256 id, uint256 qty) external payable nonReentrant {
		require(prices[id] != 0, "not live");
		require(prices[id] * qty == msg.value, "exact amount needed");
		require(qty <= 5, "max 5 at once");
		require(totalSupply(id) + qty <= maxSupplies[id], "out of stock");
		require(block.timestamp >= publicStartTime, "not live");

		_mint(msg.sender, id, qty, "");
	}
// Solidity 0.5.2
// Operation for multiplication
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
        if (a == 0) {
            return 0;
        }

        c = a * b;
        assert(c / a == b);
        return c;
    }
// Solidity 0.5.2
// ERC20 Transfer function
function transfer(address _to, uint256 _value) public returns (bool success) {
        require(_to != address(0));
        require(balanceOf[msg.sender] >= _value);
        require(balanceOf[_to].add(_value) >= balanceOf[_to]);
        balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
        balanceOf[_to] = balanceOf[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.5.2
// ERC20 Transfer from wallet
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_from != address(0) && _to != address(0));
        require(balanceOf[_from] >= _value);
        require(balanceOf[_to].add(_value) >= balanceOf[_to]);
        require(allowance[_from][msg.sender] >= _value);
        balanceOf[_to] = balanceOf[_to].add(_value);
        balanceOf[_from] = balanceOf[_from].sub(_value);
        allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.5.2
// Approve to allow tranfer tokens
function approve(address _spender, uint256 _value) public returns (bool success) {
        require(_spender != address(0));
        require(_value <= balanceOf[msg.sender]);
        require(_value == 0 || allowance[msg.sender][_spender] == 0);
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }
// Solidity 0.8.9
/**
 * @dev Presale mint
 */
function presaleMint(bytes32[] calldata _merkleProof, uint16 _mintAmount)
        external
        payable
        onlyAllowValidCountAndActiveSale(_mintAmount)
    {
        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        require(
            MerkleProof.verify(_merkleProof, merkleRoot, leaf),
            "Not on the list"
        );
        require(costPresale.mul(_mintAmount) == msg.value, "Wrong amount");
        require(!publicSaleEnabled && presaleEnabled, "Presale closed");
        require(
            addressMints[_msgSender()] + _mintAmount <=
                maxTokensPerWalletPresale,
            "Exceeds max"
        );
        _mintNFT(_msgSender(), _mintAmount);
    }
// Solidity 0.8.9
/**
 * @dev Returns list of token ids owned by address
 */
function walletOfOwner(address _owner)
        external
        view
        returns (uint256[] memory)
    {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        uint256 k = 0;
        for (uint256 i = 1; i <= totalTokens; i++) {
            if (_exists(i) && _owner == ownerOf(i)) {
                tokenIds[k] = i;
                k++;
            }
        }
        delete k;
        return tokenIds;
    }
// Solidity 0.8.9
/**
 * @dev Returns the URI to the tokens metadata
 */
function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        if (revealed == false) {
            return _notRevealedURI;
        }

        string memory baseURI = _baseURI();
        return
            bytes(baseURI).length > 0
                ? string(
                    abi.encodePacked(
                        baseURI,
                        tokenId.toString(),
                        _baseExtension
                    )
                )
                : "";
    }
// Solidity 0.8.9
/**
 * @dev Burn tokens in mutiples of 5
 */
function burn(uint256[] memory _tokenIds) external {
        require(burnEnabled, "Burn disabled");
        require(_tokenIds.length % 5 == 0, "Multiples of 5");
        for (uint256 i = 0; i < _tokenIds.length; i++) {
            require(
                _isApprovedOrOwner(_msgSender(), _tokenIds[i]),
                "ERC721Burnable: caller is not owner nor approved"
            );
        }
        require(
            totalBurned() + _tokenIds.length <= totalBurnTokens,
            "Exceeds burn limit"
        );
        for (uint256 i = 0; i < _tokenIds.length; i++) {
            _burn(_tokenIds[i]);
            _totalBurnSupply++;
            addressBurns[_msgSender()] += 1;
        }
    }