lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev Update base price assigned to a vendor by `_rpid`, `msg.sender`, `_dates`
 *      Throw when `msg.sender` is not a vendor
 *      Throw when `_rpid` not exist
 *      Throw when `_tokens`'s length is not equal to `_prices`'s length or `_tokens`'s length is equal to zero
 * @param _rpid The rate plan identifier
 * @param _inventory The amount that can be sold
 * @param _tokens The pricing currency token
 * @param _prices The currency token selling price  
 */
function updateBasePrice(uint256 _rpid, uint256[] _tokens, uint256[] _prices, uint16 _inventory) 
        external 
        ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) 
        returns(bool) {
        require(_tokens.length == _prices.length);
        require(_prices.length > 0);
        uint256 vendorId = dataSource.vendorIds(msg.sender);
        dataSource.updateBaseInventory(vendorId, _rpid, _inventory);
        for (uint256 tindex = 0; tindex < _tokens.length; tindex++) {
            dataSource.updateBasePrice(vendorId, _rpid, _tokens[tindex], _prices[tindex]);
        }
        // Event 
        emit RatePlanBasePriceChanged(_rpid);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Update inventory assigned to a vendor by `_rpid`, `msg.sender`, `_dates`
 *      Throw when `msg.sender` is not a vendor
 *      Throw when `_rpid` not exist
 *      Throw when `_dates`'s length lte 0
 * @param _rpid The rate plan identifier
 * @param _dates The prices to be modified of `_dates`
 * @param _inventory The amount that can be sold
 */
function updateInventories(uint256 _rpid, uint256[] _dates, uint16 _inventory) 
        external 
        ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) 
        returns(bool) {
        for (uint256 index = 0; index < _dates.length; index++) {
            _updateInventories(_rpid, _dates[index], _inventory);
        }

        // Event
        emit RatePlanInventoryChanged(_rpid);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Returns the inventories of `_vendor`'s RP(`_rpid`) on `_dates`
 *      Throw when `_rpid` not exist
 *      Throw when `_dates`'s count lte 0
 * @param _vendorId The vendor Id
 * @param _rpid The rate plan identifier
 * @param _dates The inventories to be returned of `_dates`
 * @return The inventories
 */
function inventoriesOfDate(uint256 _vendorId, uint256 _rpid, uint256[] _dates) 
        external 
        view
        ratePlanExist(_vendorId, _rpid) 
        returns(uint16[]) {
        require(_dates.length > 0);
        uint16[] memory result = new uint16[](_dates.length);
        for (uint256 index = 0; index < _dates.length; index++) {
            uint256 date = _dates[index];
            (uint16 inventory,) = dataSource.getInventory(_vendorId, _rpid, date);
            result[index] = inventory;
        }
        return result;
    }
// Solidity 0.4.24
/**
 * @dev Returns the prices of `_vendor`'s RP(`_rpid`) on `_dates`
 *      Throw when `_rpid` not exist
 *      Throw when `_dates`'s count lte 0
 * @param _vendorId The vendor Id
 * @param _rpid The rate plan identifier
 * @param _dates The inventories to be returned of `_dates`
 * @param _token The digital currency token
 * @return The prices
 */
function pricesOfDate(uint256 _vendorId, uint256 _rpid, uint256[] _dates, uint256 _token)
        external 
        view
        ratePlanExist(_vendorId, _rpid) 
        returns(uint256[]) {
        require(_dates.length > 0);
        uint256[] memory result = new uint256[](_dates.length);
        for (uint256 index = 0; index < _dates.length; index++) {
            (,, uint256 _price) = dataSource.getPrice(_vendorId, _rpid, _dates[index], _token);
            result[index] = _price;
        }
        return result;
    }
// Solidity 0.4.24
/**
 * @dev returns true if the node exists
 * @param self stored linked list from contract
 * @param _node a node to search for
 */
function nodeExists(LinkedList storage self, uint256 _node)
        internal
        view returns (bool) {
        if (self.list[_node][PREV] == HEAD && self.list[_node][NEXT] == HEAD) {
            if (self.list[HEAD][NEXT] == _node) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }
// Solidity 0.4.24
/**
 * @dev Can be used before `insert` to build an ordered list
 * @param self stored linked list from contract
 * @param _node an existing node to search from, e.g. HEAD.
 * @param _value value to seek
 * @param _direction direction to seek in
 * @return next first node beyond '_node' in direction `_direction`
 */
function getSortedSpot(LinkedList storage self, uint256 _node, uint256 _value, bool _direction)
        public 
        view 
        returns (uint256) {
        if (sizeOf(self) == 0) { 
            return 0; 
        }
        require((_node == 0) || nodeExists(self,_node));
        bool exists;
        uint256 next;
        (exists,next) = getAdjacent(self, _node, _direction);
        while  ((next != 0) && (_value != next) && ((_value < next) != _direction)) next = self.list[next][_direction];
        return next;
    }
// Solidity 0.4.24
/**
 * @dev Insert node `_new` beside existing node `_node` in direction `_direction`.
 * @param self stored linked list from contract
 * @param _node existing node
 * @param _new  new node to insert
 * @param _direction direction to insert node in
 */
function insert(LinkedList storage self, uint256 _node, uint256 _new, bool _direction) 
        internal 
        returns (bool) {
        if(!nodeExists(self,_new) && nodeExists(self,_node)) {
            uint256 c = self.list[_node][_direction];
            createLink(self, _node, _new, _direction);
            createLink(self, _new, c, _direction);
            self.length++;
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.24
/**
 * @dev Returns the node list and next node as a tuple
 * @param self stored linked list from contract
 * @param _node the begin id of the node to get
 * @param _limit the total nodes of one page
 * @param _direction direction to step in
 */
function getNodes(LinkedListLib.LinkedList storage self, uint256 _node, uint256 _limit, bool _direction) 
        private
        view 
        returns (uint256[], uint256) {
        bool exists;
        uint256 i = 0;
        uint256 ei = 0;
        uint256 index = 0;
        uint256 count = _limit;
        if(count > self.length) {
            count = self.length;
        }
        (exists, i) = self.getAdjacent(_node, _direction);
        if(!exists || count == 0) {
            return (new uint256[](0), 0);
        }else {
            uint256[] memory temp = new uint256[](count);
            if(_node != 0) {
                index++;
                temp[0] = _node;
            }
            while (i != 0 && index < count) {
                temp[index] = i;
                (exists,i) = self.getAdjacent(i, _direction);
                index++;
            }
            ei = i;
            if(index < count) {
                uint256[] memory result = new uint256[](index);
                for(i = 0; i < index; i++) {
                    result[i] = temp[i];
                }
                return (result, ei);
            }else {
                return (temp, ei);
            }
        }
    }
// Solidity 0.4.24
/**
 * @dev Authorize `_contract` to execute this contract's funs
 * @param _contract The contract address
 * @param _name The contract name
 */
function authorizeContract(address _contract, string _name) 
        public 
        onlyOwner 
        returns(bool) {
        uint256 codeSize;
        assembly { codeSize := extcodesize(_contract) }
        require(codeSize != 0);
        // Not exists
        require(authorizedContractIds[_contract] == 0);

        // Add
        uint256 id = authorizedContractList.push(false);
        authorizedContractIds[_contract] = id;
        authorizedContracts[id] = AuthorizedContract(_name, _contract);

        // Event
        emit ContractAuthorized(_contract);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Get the rate plan price by `_vendorId`, `_rpid`, `_date` and `_tokenId`
 * @param _vendorId The vendor id
 * @param _rpid The rate plan id
 * @param _date The date desc (20180723)
 * @param _tokenId The digital token id
 * @return The price info(inventory, init, price)
 */
function getPrice(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _tokenId) 
        public
        view 
        returns(uint16 _inventory, bool _init, uint256 _price) {
        _inventory = vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory;
        _init = vendors[_vendorId].ratePlans[_rpid].prices[_date].init;
        _price = vendors[_vendorId].ratePlans[_rpid].prices[_date].tokens[_tokenId];
        if(!_init) {
            // Get the base price
            _inventory = vendors[_vendorId].ratePlans[_rpid].basePrice.inventory;
            _price = vendors[_vendorId].ratePlans[_rpid].basePrice.tokens[_tokenId];
            _init = vendors[_vendorId].ratePlans[_rpid].basePrice.init;
        }
    }
// Solidity 0.4.24
/**
 * @dev Get token Info
 * @param _tokenId The token id
 * @return The token info(symbol, name, decimals)
 */
function getToken(uint256 _tokenId)
        public 
        view 
        returns(string _symbol, string _name, uint8 _decimals, address _token) {
        _token = tokenIndexToAddress[_tokenId];
        TripioToken tripio = TripioToken(_token);
        _symbol = tripio.symbol();
        _name = tripio.name();
        _decimals = tripio.decimals();
    }
// Solidity 0.4.24
/**
 * @dev Update price by `_vendorId`, `_rpid`, `_date`, `_tokenId` and `_price`
 * @param _vendorId The vendor id
 * @param _rpid The rate plan id
 * @param _date The date desc (20180723)
 * @param _tokenId The digital token id
 * @param _price The price to be updated
 */
function updatePrice(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _tokenId, uint256 _price)
        public
        onlyOwnerOrAuthorizedContract {
        if (vendors[_vendorId].ratePlans[_rpid].prices[_date].init) {
            vendors[_vendorId].ratePlans[_rpid].prices[_date].tokens[_tokenId] = _price;
        } else {
            vendors[_vendorId].ratePlans[_rpid].prices[_date] = Price(0, true);
            vendors[_vendorId].ratePlans[_rpid].prices[_date].tokens[_tokenId] = _price;
        }
    }
// Solidity 0.4.24
/**
 * @dev Reduce inventories
 * @param _vendorId The vendor id
 * @param _rpid The rate plan id
 * @param _date The date desc (20180723)
 * @param _inventory The amount to be reduced
 */
function reduceInventories(uint256 _vendorId, uint256 _rpid, uint256 _date, uint16 _inventory) 
        public  
        onlyOwnerOrAuthorizedContract {
        uint16 a = 0;
        if(vendors[_vendorId].ratePlans[_rpid].prices[_date].init) {
            a = vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory;
            require(_inventory <= a);
            vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory = a - _inventory;
        }else if(vendors[_vendorId].ratePlans[_rpid].basePrice.init){
            a = vendors[_vendorId].ratePlans[_rpid].basePrice.inventory;
            require(_inventory <= a);
            vendors[_vendorId].ratePlans[_rpid].basePrice.inventory = a - _inventory;
        }
    }
// Solidity 0.4.24
/**
 * @dev Add inventories
 * @param _vendorId The vendor id
 * @param _rpid The rate plan id
 * @param _date The date desc (20180723)
 * @param _inventory The amount to be add
 */
function addInventories(uint256 _vendorId, uint256 _rpid, uint256 _date, uint16 _inventory) 
        public  
        onlyOwnerOrAuthorizedContract {
        uint16 c = 0;
        if(vendors[_vendorId].ratePlans[_rpid].prices[_date].init) {
            c = _inventory + vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory;
            require(c >= _inventory);
            vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory = c;
        }else if(vendors[_vendorId].ratePlans[_rpid].basePrice.init) {
            c = _inventory + vendors[_vendorId].ratePlans[_rpid].basePrice.inventory;
            require(c >= _inventory);
            vendors[_vendorId].ratePlans[_rpid].basePrice.inventory = c;
        }
    }
// Solidity 0.4.24
/**
 * @dev Push rate plan to `_vendorId`'s rate plan list
 * @param _vendorId The vendor id
 * @param _name The name of rate plan
 * @param _ipfs The rate plan IPFS address
 * @param _direction direction to step in
 */
function pushRatePlan(uint256 _vendorId, string _name, bytes32 _ipfs, bool _direction) 
        public 
        onlyOwnerOrAuthorizedContract
        returns(uint256) {
        RatePlan memory rp = RatePlan(_name, uint256(now), _ipfs, Price(0, false));
        
        uint256 id = vendors[_vendorId].ratePlanList.push(_direction);
        vendors[_vendorId].ratePlans[id] = rp;
        return id;
    }
// Solidity 0.4.24
/**
 * @dev Generate room night token
 * @param _vendorId The vendor id
 * @param _rpid The rate plan id
 * @param _date The date desc (20180723)
 * @param _token The token id
 * @param _price The token price
 * @param _ipfs The rate plan IPFS address
 */
function generateRoomNightToken(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _token, uint256 _price, bytes32 _ipfs)
        public 
        onlyOwnerOrAuthorizedContract 
        returns(uint256) {
        roomnights.push(RoomNight(_vendorId, _rpid, _token, _price, now, _date, _ipfs));

        // Give the token to `_customer`
        uint256 rnid = uint256(roomnights.length - 1);
        return rnid;
    }
// Solidity 0.4.24
/**
 * @dev Create rate plan
 *      Only vendor can operate
 *      Throw when `_name`'s length lte 0 or mte 100.
 * @param _name The name of rate plan
 * @param _ipfs The address of the rate plan detail info on IPFS.
 */
function createRatePlan(string _name, bytes32 _ipfs) 
        external 
        // onlyVendor 
        returns(uint256) {
        // if vendor not exist create it
        if(dataSource.vendorIds(msg.sender) == 0) {
            dataSource.pushVendor("", msg.sender, false);
        }
        bytes memory nameBytes = bytes(_name);
        require(nameBytes.length > 0 && nameBytes.length < 200);
    
        uint256 vendorId = dataSource.vendorIds(msg.sender);
        uint256 id = dataSource.pushRatePlan(vendorId, _name, _ipfs, false);
        
        // Event 
        emit RatePlanCreated(msg.sender, _name, _ipfs);

        return id;
    }
// Solidity 0.4.24
/**
 * @dev Modify rate plan
 *      Throw when `_rpid` not exist
 * @param _rpid The rate plan identifier
 * @param _ipfs The address of the rate plan detail info on IPFS
 */
function modifyRatePlan(uint256 _rpid, string _name, bytes32 _ipfs) 
        external 
        onlyVendor 
        ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) 
        returns(bool) {

        uint256 vendorId = dataSource.vendorIds(msg.sender);
        dataSource.updateRatePlan(vendorId, _rpid, _name, _ipfs);

        // Event 
        emit RatePlanModified(msg.sender, _rpid, _name, _ipfs);
        return true;
    }
// Solidity 0.5.7
/// Forward a signed `transfer` call to the RSV contract if `sig` matches the signature.
/// Note that `amount` is not reduced by `fee`; the fee is taken separately.
function forwardTransfer(
        bytes calldata sig,
        address from,
        address to,
        uint256 amount,
        uint256 fee
    )
        external
    {
        bytes32 hash = keccak256(abi.encodePacked(
            address(trustedRSV),
            "forwardTransfer",
            from,
            to,
            amount,
            fee,
            nonce[from]
        ));
        nonce[from]++;

        address recoveredSigner = _recoverSignerAddress(hash, sig);
        require(recoveredSigner == from, "invalid signature");

        _takeFee(from, fee);

        require(
            trustedRSV.relayTransfer(from, to, amount), 
            "Reserve.sol relayTransfer failed"
        );
        emit TransferForwarded(sig, from, to, amount, fee);
    }
// Solidity 0.5.7
/// Forward a signed `transferFrom` call to the RSV contract if `sig` matches the signature.
/// Note that `fee` is not deducted from `amount`, but separate.
/// Allowance checking is left up to the Reserve contract to do.
function forwardTransferFrom(
        bytes calldata sig,
        address holder,
        address spender,
        address to,
        uint256 amount,
        uint256 fee
    )
        external
    {
        bytes32 hash = keccak256(abi.encodePacked(
            address(trustedRSV),
            "forwardTransferFrom",
            holder,
            spender,
            to,
            amount,
            fee,
            nonce[spender]
        ));
        nonce[spender]++;

        address recoveredSigner = _recoverSignerAddress(hash, sig);
        require(recoveredSigner == spender, "invalid signature");

        _takeFee(spender, fee);

        require(
            trustedRSV.relayTransferFrom(holder, spender, to, amount), 
            "Reserve.sol relayTransfer failed"
        );
        emit TransferFromForwarded(sig, holder, spender, to, amount, fee);
    }
// Solidity 0.4.19
//*** Accessories***/
function createAccessorySeries(uint8 _AccessorySeriesId, uint32 _maxTotal, uint _price) onlyCREATOR public returns(uint8) {
        
        if ((now > 1516642200) || (totalAccessorySeries >= 18)) {revert();}
        //This confirms that no one, even the develoopers, can create any accessorySeries after JAN/22/2018 @ 05:30pm (UTC) or more than the original 18 series. 
        AccessorySeries storage accessorySeries = AccessorySeriesCollection[_AccessorySeriesId];
        accessorySeries.AccessorySeriesId = _AccessorySeriesId;
        accessorySeries.maxTotal = _maxTotal;
        accessorySeries.price = _price;

        totalAccessorySeries += 1;
        return totalAccessorySeries;
    }
// Solidity 0.4.19
//*** Read Access ***//
function getAccessorySeries(uint8 _accessorySeriesId) constant public returns(uint8 accessorySeriesId, uint32 currentTotal, uint32 maxTotal, uint price) {
        AccessorySeries memory series = AccessorySeriesCollection[_accessorySeriesId];
        accessorySeriesId = series.AccessorySeriesId;
        currentTotal = series.currentTotal;
        maxTotal = series.maxTotal;
        price = series.price;
    }
// Solidity 0.8.10
/**
 * Add $CARROT claimable pots for hunters and foxes
 * @param amount $CARROT to add to the pot
 * @param includeHunters true if hunters take a cut of the spoils
 */
function _payTaxToPredators(uint128 amount, bool includeHunters) internal {
    uint128 amountDueFoxes = amount;

    // Hunters take their cut first
    if (includeHunters) {
      uint128 amountDueHunters = amount * hunterTaxCutPercentage / 100;
      amountDueFoxes -= amountDueHunters;

      // Update hunter pools
      if (totalMarksmanPointsStaked == 0) {
        unaccountedHunterRewards += amountDueHunters;
      } else {
        carrotPerMarksmanPoint += (amountDueHunters + unaccountedHunterRewards) / totalMarksmanPointsStaked;
        unaccountedHunterRewards = 0;
      }
    }

    // Update fox pools
    if (totalCunningPointsStaked == 0) {
      unaccountedFoxRewards += amountDueFoxes;
    } else {
      // makes sure to include any unaccounted $CARROT 
      carrotPerCunningPoint += (amountDueFoxes + unaccountedFoxRewards) / totalCunningPointsStaked;
      unaccountedFoxRewards = 0;
    }
  }
// Solidity 0.8.7
// Sets the USDC contract address, the Uniswap pool fee and accordingly includes the derived Uniswap liquidity pool address to the whitelistedWallets mapping
function setPoolParameters(address USDC, uint24 poolFee) public onlyOwner {
        addrUSDC = USDC;
        swapPoolFee = poolFee;
        whitelistedWallets[authorizedPool] = false;

        // taken from @uniswap/v3-periphery/contracts/libraries/PoolAddress.sol
        address token0 = address(this);
        address token1 = USDC;
        if (token0 > token1) (token0, token1) = (token1, token0);

        authorizedPool = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            0x1F98431c8aD98523631AE4a59f267346ea31F984,
                            keccak256(abi.encode(token0, token1, poolFee)),
                            bytes32(0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54)
                        )
                    )
                )
            )
        );
        whitelistedWallets[authorizedPool] = true;
    }
// Solidity 0.8.7
// Enables GoldPesa to set the "feeOnSwap" distribution details 
function setFeeSplits(FeeSplit[] memory _feeSplits) public onlyOwner {
        uint256 grandTotal = 0;
        for (uint256 i = 0; i < _feeSplits.length; i++) {
            FeeSplit memory f = _feeSplits[i];
            grandTotal += f.fee;
        }
        require(_feeSplits.length == 0 || grandTotal == 100);
        // temporarily allow 0 fee splits for tests for manual fee distribution
        delete feeSplits;
        for (uint256 i = 0; i < _feeSplits.length; i++) {
            feeSplits.push(_feeSplits[i]);
        }
        feeSplitsLength = _feeSplits.length;
    }
// Solidity 0.8.7
// Distributes the feeOnSwap amount collected during any swap transaction to the addresses defined in the "feeSplits" array
function distributeFee(uint256 amount) internal {
        uint256 grandTotal = 0;
        for (uint256 i = 0; i < feeSplits.length; i++) {
            FeeSplit storage f = feeSplits[i];
            uint256 distributeAmount = amount * f.fee / 100;
            IERC20(addrUSDC).transfer(f.recipient, distributeAmount);
            grandTotal += distributeAmount;
        }
        if (grandTotal != amount && feeSplits.length > 0) {
            FeeSplit storage f = feeSplits[0];
            IERC20(addrUSDC).transfer(f.recipient, amount - grandTotal);
        }
    }
// Solidity 0.8.7
// Internal mint function which cannot be called externally after the GPO contract is deployed ensuring that the GPO token hard cap of 100,000,000 is not breached
function _mint(address account, uint256 amount) internal virtual override {
        // Ensures that GPO token hard cap of 100,000,000 is not breached even if the mint function is called internally
        require(
            ERC20.totalSupply() + amount <= hardCapOnToken(),
            "ERC20Capped: cap exceeded"
        );
        super._mint(account, amount);
    }
// Solidity 0.8.7
// Enables GoldPesa to lock and unlock wallet address manually 
function lockUnlockWallet(address account, bool yesOrNo, uint256 amount) public authorizedLocker {
        lockedWallets[account] = yesOrNo;
        if (yesOrNo) {
            uint256 lockedValue = lockedWalletsAmount[account] + amount;
            require(lockedValue <= balanceOf(account));
            lockedWalletsAmount[account] = lockedValue;
        } else {
            lockedWalletsAmount[account] = 0;
        }
    }