lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.21
/* Cancel an existing vote by the sender on a motion
 * to confiscate the target balance. */
function cancelVote(uint motionID)
        external
    {
        // An account may cancel its vote either before the confirmation phase
        // when the motion is still open, or after the confirmation phase,
        // when the motion has concluded.
        // But the totals must not change during the confirmation phase itself.
        require(!motionConfirming(motionID));

        Vote senderVote = vote[msg.sender][motionID];

        // If the sender has not voted then there is no need to update anything.
        require(senderVote != Vote.Abstention);

        // If we are not voting, there is no reason to update the vote totals.
        if (motionVoting(motionID)) {
            if (senderVote == Vote.Yea) {
                votesFor[motionID] = safeSub(votesFor[motionID], voteWeight[msg.sender][motionID]);
            } else {
                // Since we already ensured that the vote is not an abstention,
                // the only option remaining is Vote.Nay.
                votesAgainst[motionID] = safeSub(votesAgainst[motionID], voteWeight[msg.sender][motionID]);
            }
            // A cancelled vote is only meaningful if a vote is running
            emit VoteCancelled(msg.sender, msg.sender, motionID, motionID);
        }

        delete voteWeight[msg.sender][motionID];
        delete vote[msg.sender][motionID];
    }
// Solidity 0.4.21
// Return the fee charged on top in order to transfer _value worth of tokens.
function transferFeeIncurred(uint value)
        public
        view
        returns (uint)
    {
        return safeMul_dec(value, transferFeeRate);
        // Transfers less than the reciprocal of transferFeeRate should be completely eaten up by fees.
        // This is on the basis that transfers less than this value will result in a nil fee.
        // Probably too insignificant to worry about, but the following code will achieve it.
        //      if (fee == 0 && transferFeeRate != 0) {
        //          return _value;
        //      }
        //      return fee;
    }
// Solidity 0.4.21
/* Whatever calls this should have either the optionalProxy or onlyProxy modifier,
 * and pass in messageSender. */
function _transfer_byProxy(address sender, address to, uint value)
        internal
        returns (bool)
    {
        require(to != address(0));

        // The fee is deducted from the sender's balance, in addition to
        // the transferred quantity.
        uint fee = transferFeeIncurred(value);
        uint totalCharge = safeAdd(value, fee);

        // Insufficient balance will be handled by the safe subtraction.
        state.setBalanceOf(sender, safeSub(state.balanceOf(sender), totalCharge));
        state.setBalanceOf(to, safeAdd(state.balanceOf(to), value));
        state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), fee));

        emit Transfer(sender, to, value);
        emit TransferFeePaid(sender, fee);
        emit Transfer(sender, address(this), fee);

        return true;
    }
// Solidity 0.4.21
/* Withdraw tokens from the fee pool into a given account. */
function withdrawFee(address account, uint value)
        external
        returns (bool)
    {
        require(msg.sender == feeAuthority && account != address(0));
        
        // 0-value withdrawals do nothing.
        if (value == 0) {
            return false;
        }

        // Safe subtraction ensures an exception is thrown if the balance is insufficient.
        state.setBalanceOf(address(this), safeSub(state.balanceOf(address(this)), value));
        state.setBalanceOf(account, safeAdd(state.balanceOf(account), value));

        emit FeesWithdrawn(account, account, value);
        emit Transfer(address(this), account, value);

        return true;
    }
// Solidity 0.4.21
/* Donate tokens from the sender's balance into the fee pool. */
function donateToFeePool(uint n)
        external
        optionalProxy
        returns (bool)
    {
        address sender = messageSender;

        // Empty donations are disallowed.
        uint balance = state.balanceOf(sender);
        require(balance != 0);

        // safeSub ensures the donor has sufficient balance.
        state.setBalanceOf(sender, safeSub(balance, n));
        state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), n));

        emit FeesDonated(sender, sender, n);
        emit Transfer(sender, address(this), n);

        return true;
    }
// Solidity 0.4.21
/* True if the contract is self-destructible. 
 * This is true if either the complete liquidation period has elapsed,
 * or if all tokens have been returned to the contract and it has been
 * in liquidation for at least a week.
 * Since the contract is only destructible after the liquidationTimestamp,
 * a fortiori canSelfDestruct() implies isLiquidating(). */
function canSelfDestruct()
        public
        view
        returns (bool)
    {
        // Not being in liquidation implies the timestamp is uint max, so it would roll over.
        // We need to check whether we're in liquidation first.
        if (isLiquidating()) {
            // These timestamps and durations have values clamped within reasonable values and
            // cannot overflow.
            bool totalPeriodElapsed = liquidationTimestamp + liquidationPeriod < now;
            // Total supply of 0 means all tokens have returned to the pool.
            bool allTokensReturned = (liquidationTimestamp + 1 weeks < now) && (totalSupply == 0);
            return totalPeriodElapsed || allTokensReturned;
        }
        return false;
    }
// Solidity 0.4.21
/* Update the current ether price and update the last updated time,
 * refreshing the price staleness.
 * Also checks whether the contract's collateral levels have fallen to low,
 * and initiates liquidation if that is the case.
 * Exceptional conditions:
 *     Not called by the oracle.
 *     Not the most recently sent price. */
function updatePrice(uint price, uint timeSent)
        external
        postCheckAutoLiquidate
    {
        // Should be callable only by the oracle.
        require(msg.sender == oracle);
        // Must be the most recently sent price, but not too far in the future.
        // (so we can't lock ourselves out of updating the oracle for longer than this)
        require(lastPriceUpdate < timeSent && timeSent < now + 10 minutes);

        etherPrice = price;
        lastPriceUpdate = timeSent;
        emit PriceUpdated(price);
    }
// Solidity 0.4.21
/* Issues n nomins into the pool available to be bought by users.
 * Must be accompanied by $n worth of ether.
 * Exceptional conditions:
 *     Not called by contract owner.
 *     Insufficient backing funds provided (post-issuance collateralisation below minimum requirement).
 *     Price is stale. */
function replenishPool(uint n)
        external
        payable
        notLiquidating
        optionalProxy_onlyOwner
    {
        // Price staleness check occurs inside the call to fiatBalance.
        // Safe additions are unnecessary here, as either the addition is checked on the following line
        // or the overflow would cause the requirement not to be satisfied.
        require(fiatBalance() >= safeMul_dec(safeAdd(_nominCap(), n), MINIMUM_ISSUANCE_RATIO));
        nominPool = safeAdd(nominPool, n);
        emit PoolReplenished(n, msg.value);
    }
// Solidity 0.4.21
/* Sends n nomins to the sender from the pool, in exchange for
 * $n plus the fee worth of ether.
 * Exceptional conditions:
 *     Insufficient or too many funds provided.
 *     More nomins requested than are in the pool.
 *     n below the purchase minimum (1 cent).
 *     contract in liquidation.
 *     Price is stale. */
function buy(uint n)
        external
        payable
        notLiquidating
        optionalProxy
    {
        // Price staleness check occurs inside the call to purchaseEtherCost.
        require(n >= MINIMUM_PURCHASE &&
                msg.value == purchaseCostEther(n));
        address sender = messageSender;
        // sub requires that nominPool >= n
        nominPool = safeSub(nominPool, n);
        state.setBalanceOf(sender, safeAdd(state.balanceOf(sender), n));
        emit Purchased(sender, sender, n, msg.value);
        emit Transfer(0, sender, n);
        totalSupply = safeAdd(totalSupply, n);
    }
// Solidity 0.4.21
/* Sends n nomins to the pool from the sender, in exchange for
 * $n minus the fee worth of ether.
 * Exceptional conditions:
 *     Insufficient nomins in sender's wallet.
 *     Insufficient funds in the pool to pay sender.
 *     Price is stale if not in liquidation. */
function sell(uint n)
        external
        optionalProxy
    {

        // Price staleness check occurs inside the call to saleProceedsEther,
        // but we allow people to sell their nomins back to the system
        // if we're in liquidation, regardless.
        uint proceeds;
        if (isLiquidating()) {
            proceeds = saleProceedsEtherAllowStale(n);
        } else {
            proceeds = saleProceedsEther(n);
        }

        require(address(this).balance >= proceeds);

        address sender = messageSender;
        // sub requires that the balance is greater than n
        state.setBalanceOf(sender, safeSub(state.balanceOf(sender), n));
        nominPool = safeAdd(nominPool, n);
        emit Sold(sender, sender, n, proceeds);
        emit Transfer(sender, 0, n);
        totalSupply = safeSub(totalSupply, n);
        sender.transfer(proceeds);
    }
// Solidity 0.4.21
/* If a confiscation court motion has passed and reached the confirmation
 * state, the court may transfer the target account's balance to the fee pool
 * and freeze its participation in further transactions. */
function confiscateBalance(address target)
        external
    {
        // Should be callable only by the confiscation court.
        require(Court(msg.sender) == court);
        
        // A motion must actually be underway.
        uint motionID = court.targetMotionID(target);
        require(motionID != 0);

        // These checks are strictly unnecessary,
        // since they are already checked in the court contract itself.
        // I leave them in out of paranoia.
        require(court.motionConfirming(motionID));
        require(court.motionPasses(motionID));
        require(!frozen[target]);

        // Confiscate the balance in the account and freeze it.
        uint balance = state.balanceOf(target);
        state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), balance));
        state.setBalanceOf(target, 0);
        frozen[target] = true;
        emit AccountFrozen(target, target, balance);
        emit Transfer(target, address(this), balance);
    }
// Solidity 0.4.21
/* Anything calling this must apply the onlyProxy or optionalProxy modifiers.*/
function _transfer_byProxy(address sender, address to, uint value)
        internal
        returns (bool)
    {
        require(to != address(0));

        // Insufficient balance will be handled by the safe subtraction.
        state.setBalanceOf(sender, safeSub(state.balanceOf(sender), value));
        state.setBalanceOf(to, safeAdd(state.balanceOf(to), value));

        emit Transfer(sender, to, value);

        return true;
    }
// Solidity 0.4.21
/* Obtain the index of the next schedule entry that will vest for a given user. */
function getNextVestingIndex(address account)
        public
        view
        returns (uint)
    {
        uint len = numVestingEntries(account);
        for (uint i = 0; i < len; i++) {
            if (getVestingTime(account, i) != 0) {
                return i;
            }
        }
        return len;
    }
// Solidity 0.4.21
/* Add a new vesting entry at a given time and quantity to an account's schedule.
 * A call to this should be accompanied by either enough balance already available
 * in this contract, or a corresponding call to havven.endow(), to ensure that when
 * the funds are withdrawn, there is enough balance, as well as correctly calculating
 * the fees.
 * Note; although this function could technically be used to produce unbounded
 * arrays, it's only in the foundation's command to add to these lists. */
function appendVestingEntry(address account, uint time, uint quantity)
        public
        onlyOwner
        setupFunction
    {
        // No empty or already-passed vesting entries allowed.
        require(now < time);
        require(quantity != 0);
        totalVestedBalance = safeAdd(totalVestedBalance, quantity);
        require(totalVestedBalance <= havven.balanceOf(this));

        if (vestingSchedules[account].length == 0) {
            totalVestedAccountBalance[account] = quantity;
        } else {
            // Disallow adding new vested havvens earlier than the last one.
            // Since entries are only appended, this means that no vesting date can be repeated.
            require(getVestingTime(account, numVestingEntries(account) - 1) < time);
            totalVestedAccountBalance[account] = safeAdd(totalVestedAccountBalance[account], quantity);
        }

        vestingSchedules[account].push([time, quantity]);
    }
// Solidity 0.4.21
/* Allow a user to withdraw any tokens that have vested. */
function vest() 
        external
    {
        uint total;
        for (uint i = 0; i < numVestingEntries(msg.sender); i++) {
            uint time = getVestingTime(msg.sender, i);
            // The list is sorted; when we reach the first future time, bail out.
            if (time > now) {
                break;
            }
            uint qty = getVestingQuantity(msg.sender, i);
            if (qty == 0) {
                continue;
            }

            vestingSchedules[msg.sender][i] = [0, 0];
            total = safeAdd(total, qty);
            totalVestedAccountBalance[msg.sender] = safeSub(totalVestedAccountBalance[msg.sender], qty);
        }

        if (total != 0) {
            totalVestedBalance = safeSub(totalVestedBalance, total);
            havven.transfer(msg.sender, total);
            emit Vested(msg.sender, msg.sender,
                   now, total);
        }
    }
// Solidity 0.4.21
/* Allow the owner of this contract to endow any address with havvens
 * from the initial supply. Since the entire initial supply resides
 * in the havven contract, this disallows the foundation from withdrawing
 * fees on undistributed balances. This function can also be used
 * to retrieve any havvens sent to the Havven contract itself. */
function endow(address account, uint value)
        external
        optionalProxy_onlyOwner
        returns (bool)
    {

        // Use "this" in order that the havven account is the sender.
        // That this is an explicit transfer also initialises fee entitlement information.
        return _transfer(this, account, value);
    }
// Solidity 0.4.21
/* Override ERC20 transferFrom function in order to perform
 * fee entitlement recomputation whenever balances are updated. */
function transferFrom(address from, address to, uint value)
        external
        preCheckFeePeriodRollover
        optionalProxy
        returns (bool)
    {
        uint senderPreBalance = state.balanceOf(from);
        uint recipientPreBalance = state.balanceOf(to);

        // Perform the transfer: if there is a problem,
        // an exception will be thrown in this call.
        _transferFrom_byProxy(messageSender, from, to, value);

        // Zero-value transfers still update fee entitlement information,
        // and may roll over the fee period.
        adjustFeeEntitlement(from, senderPreBalance);
        adjustFeeEntitlement(to, recipientPreBalance);

        return true;
    }
// Solidity 0.4.21
/* Compute the last period's fee entitlement for the message sender
 * and then deposit it into their nomin account. */
function withdrawFeeEntitlement()
        public
        preCheckFeePeriodRollover
        optionalProxy
    {
        address sender = messageSender;

        // Do not deposit fees into frozen accounts.
        require(!nomin.frozen(sender));

        // check the period has rolled over first
        rolloverFee(sender, lastTransferTimestamp[sender], state.balanceOf(sender));

        // Only allow accounts to withdraw fees once per period.
        require(!hasWithdrawnLastPeriodFees[sender]);

        uint feesOwed;

        if (escrow != HavvenEscrow(0)) {
            feesOwed = escrow.totalVestedAccountBalance(sender);
        }

        feesOwed = safeDiv_dec(safeMul_dec(safeAdd(feesOwed, lastAverageBalance[sender]),
                                           lastFeesCollected),
                               totalSupply);

        hasWithdrawnLastPeriodFees[sender] = true;
        if (feesOwed != 0) {
            nomin.withdrawFee(sender, feesOwed);
            emit FeesWithdrawn(sender, sender, feesOwed);
        }
    }
// Solidity 0.4.21
/* Update the fee entitlement since the last transfer or entitlement
 * adjustment. Since this updates the last transfer timestamp, if invoked
 * consecutively, this function will do nothing after the first call. */
function adjustFeeEntitlement(address account, uint preBalance)
        internal
    {
        // The time since the last transfer clamps at the last fee rollover time if the last transfer
        // was earlier than that.
        rolloverFee(account, lastTransferTimestamp[account], preBalance);

        currentBalanceSum[account] = safeAdd(
            currentBalanceSum[account],
            safeMul(preBalance, now - lastTransferTimestamp[account])
        );

        // Update the last time this user's balance changed.
        lastTransferTimestamp[account] = now;
    }
// Solidity 0.4.21
/* If the fee period has rolled over, then
 * save the start times of the last fee period,
 * as well as the penultimate fee period.
 */
function checkFeePeriodRollover()
        internal
    {
        // If the fee period has rolled over...
        if (feePeriodStartTime + targetFeePeriodDurationSeconds <= now) {
            lastFeesCollected = nomin.feePool();

            // Shift the three period start times back one place
            penultimateFeePeriodStartTime = lastFeePeriodStartTime;
            lastFeePeriodStartTime = feePeriodStartTime;
            feePeriodStartTime = now;
            
            emit FeePeriodRollover(now);
        }
    }
// Solidity 0.4.19
//Event on blockchain which notify client
//===================events definition end==================
//===================Contract Initialization Sequence Definition start===================
function FloodDragon (
            uint256 initialSupply,
            string tokenName,
            string tokenSymbol
        ) public {
        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
        
    }
// Solidity 0.4.19
/*
 	*	Funtion: Transfer funtions
 	*	Type:Internal
 	*	Parameters:
 			@_from:	address of sender's account
 			@_to:	address of recipient's account
 			@_value:transaction amount
 	*/
function _transfer(address _from, address _to, uint _value) internal {
		//Fault-tolerant processing
		require(_to != 0x0);						//
        require(balanceOf[_from] >= _value);
        require(balanceOf[_to] + _value > balanceOf[_to]);

        //Execute transaction
		uint previousBalances = balanceOf[_from] + balanceOf[_to];
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        Transfer(_from, _to, _value);
		
		//Verify transaction
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
    }
// Solidity 0.8.8
//@return 1~6
function getOccupationType(uint256 tokenId) public view returns (uint256) {
        uint256 rand = random(string(abi.encodePacked("Occupation", toString(tokenId))));
        uint256 score = rand % 100;

        uint i = 0;
        for(; i < roleScoreMatch.length; i++){
            if(score <= roleScoreMatch[i]){
                break;
            }
        }
        return i+1;
    }
// Solidity 0.6.6
/*
 * @dev Returns the length of a null-terminated bytes32 string.
 * @param self The value to find the length of.
 * @return The length of the string, from 0 to 32.
 */
function len(bytes32 self) internal pure returns (uint) {
        uint ret;
        if (self == 0)
            return 0;
        if (uint256(self) & 0xffffffffffffffffffffffffffffffff == 0) {
            ret += 16;
            self = bytes32(uint(self) / 0x100000000000000000000000000000000);
        }
        if (uint256(self) & 0xffffffffffffffff == 0) {
            ret += 8;
            self = bytes32(uint(self) / 0x10000000000000000);
        }
        if (uint256(self) & 0xffffffff == 0) {
            ret += 4;
            self = bytes32(uint(self) / 0x100000000);
        }
        if (uint256(self) & 0xffff == 0) {
            ret += 2;
            self = bytes32(uint(self) / 0x10000);
        }
        if (uint256(self) & 0xff == 0) {
            ret += 1;
        }
        return 32 - ret;
    }
// Solidity 0.6.6
/*
 * @dev Returns a slice containing the entire bytes32, interpreted as a
 *      null-terminated utf-8 string.
 * @param self The bytes32 value to convert to a slice.
 * @return A new slice containing the value of the input argument up to the
 *         first null.
 */
function toSliceB32(bytes32 self) internal pure returns (slice memory ret) {
        // Allocate space for `self` in memory, copy it there, and point ret at it
        assembly {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x20))
            mstore(ptr, self)
            mstore(add(ret, 0x20), ptr)
        }
        ret._len = len(self);
    }
// Solidity 0.6.6
/*
 * @dev Copies a slice to a new string.
 * @param self The slice to copy.
 * @return A newly allocated string containing the slice's text.
 */
function toString(slice memory self) internal pure returns (string memory) {
        string memory ret = new string(self._len);
        uint retptr;
        assembly { retptr := add(ret, 32) }

        memcpy(retptr, self._ptr, self._len);
        return ret;
    }
// Solidity 0.6.6
/*
 * @dev Returns the length in runes of the slice. Note that this operation
 *      takes time proportional to the length of the slice; avoid using it
 *      in loops, and call `slice.empty()` if you only need to know whether
 *      the slice is empty or not.
 * @param self The slice to operate on.
 * @return The length of the slice in runes.
 */
function len(slice memory self) internal pure returns (uint l) {
        // Starting at ptr-31 means the LSB will be the byte we care about
        uint ptr = self._ptr - 31;
        uint end = ptr + self._len;
        for (l = 0; ptr < end; l++) {
            uint8 b;
            assembly { b := and(mload(ptr), 0xFF) }
            if (b < 0x80) {
                ptr += 1;
            } else if(b < 0xE0) {
                ptr += 2;
            } else if(b < 0xF0) {
                ptr += 3;
            } else if(b < 0xF8) {
                ptr += 4;
            } else if(b < 0xFC) {
                ptr += 5;
            } else {
                ptr += 6;
            }
        }
    }