lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.8
/// @dev Transfers sender token to given address. Returns success.
/// @param _to Address of new token owner.
/// @param _value Bytes32 id of the token to transfer.
function transfer(address _to,
                      uint256 _value) public returns (bool success) {
        if (_value != 1) {
            // 1 is the only value that makes any sense here.
            return false;
        } else if (_to == 0x0) {
            // cannot transfer to the null address.
            return false;
        } else if (balances[msg.sender] == 0x0) {
            // msg.sender is not a token owner
            return false;
        } else if (balances[_to] != 0x0) {
            // cannot transfer to an address that already owns a token.
            return false;
        }

        balances[msg.sender] = 0;
        balances[_to] = 1;
        Transfer(msg.sender, _to, 1);
        TokenEventLib._Transfer(msg.sender, _to);

        return true;
    }
// Solidity 0.4.8
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address of token owner.
/// @param _to Address of new token owner.
/// @param _value Bytes32 id of the token to transfer.
function transferFrom(address _from,
                          address _to,
                          uint256 _value) public returns (bool success) {
        if (_value != 1) {
            // Cannot transfer anything other than 1 token.
            return false;
        } else if (_to == 0x0) {
            // Cannot transfer to the null address
            return false;
        } else if (balances[_from] == 0x0) {
            // Cannot transfer if _from is not a token owner
            return false;
        } else if (balances[_to] != 0x0) {
            // Cannot transfer to an existing token owner
            return false;
        } else if (approvals[_from][msg.sender] == 0) {
            // The approved token doesn't match the token being transferred.
            return false;
        }

        // null out the approval
        approvals[_from][msg.sender] = 0x0;

        // remove the token from the sender.
        balances[_from] = 0;

        // assign the token to the new owner
        balances[_to] = 1;

        // log the transfer
        Transfer(_from, _to, 1);
        TokenEventLib._Transfer(_from, _to);

        return true;
    }
// Solidity 0.4.8
/// @dev Sets approval spender to transfer ownership of token. Returns success.
/// @param _spender Address of spender..
/// @param _value Bytes32 id of token that can be spend.
function approve(address _spender,
                     uint256 _value) public returns (bool success) {
        if (_value != 1) {
            // cannot approve any value other than 1
            return false;
        } else if (_spender == 0x0) {
            // cannot approve the null address as a spender.
            return false;
        } else if (balances[msg.sender] == 0x0) {
            // cannot approve if not a token owner.
            return false;
        }

        approvals[msg.sender][_spender] = 1;

        Approval(msg.sender, _spender, 1);
        TokenEventLib._Approval(msg.sender, _spender);

        return true;
    }
// Solidity 0.6.12
// This function is for dev address migrate all balance to a multi sig address
function transferAll(address _to) public {
        _locks[_to] = _locks[_to].add(_locks[msg.sender]);

        if (_lastUnlockBlock[_to] < lockFromBlock) {
            _lastUnlockBlock[_to] = lockFromBlock;
        }

        if (_lastUnlockBlock[_to] < _lastUnlockBlock[msg.sender]) {
            _lastUnlockBlock[_to] = _lastUnlockBlock[msg.sender];
        }

        _locks[msg.sender] = 0;
        _lastUnlockBlock[msg.sender] = 0;

        _transfer(msg.sender, _to, balanceOf(msg.sender));
    }
// Solidity 0.6.12
/**
 * @notice function to propose
 *
 * @param targets - array of address
 * @param values - array of values
 * @param signatures - array of signatures
 * @param calldatas - array of data
 * @param description - array of descriptions
 *
 * @return id of proposal
 */
function propose(
        address[] memory targets,
        uint[] memory values,
        string[] memory signatures,
        bytes[] memory calldatas,
        string memory description
    )
        external
        onlyMember
        returns (uint)
    {
        require(
            targets.length == values.length &&
            targets.length == signatures.length &&
            targets.length == calldatas.length,
            "TokensFarmCongress::propose: proposal function information arity mismatch"
        );

        require(targets.length != 0, "TokensFarmCongress::propose: must provide actions");

        proposalCount++;

        Proposal memory newProposal = Proposal({
        id: proposalCount,
        proposer: msg.sender,
        targets: targets,
        values: values,
        signatures: signatures,
        calldatas: calldatas,
        forVotes: 0,
        againstVotes: 0,
        canceled: false,
        executed: false,
        timestamp: block.timestamp
        });

        proposals[newProposal.id] = newProposal;

        emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, description);
        return newProposal.id;
    }
// Solidity 0.6.12
/**
 * @notice function to execute on what is voted
 *
 * @param proposalId - id of proposal
 */
function execute(
        uint proposalId
    )
        external
        onlyMember
        payable
    {
        // load the proposal
        Proposal storage proposal = proposals[proposalId];
        // Require that proposal is not previously executed neither cancelled
        require(!proposal.executed && !proposal.canceled, "Proposal was canceled or executed");
        // Mark that proposal is executed
        proposal.executed = true;
        // Require that votes in favor of proposal are greater or equal to minimalQuorum
        require(proposal.forVotes >= membersRegistry.getMinimalQuorum(), "Not enough votes in favor");

        for (uint i = 0; i < proposal.targets.length; i++) {
            bytes memory callData;

            if (bytes(proposal.signatures[i]).length == 0) {
                callData = proposal.calldatas[i];
            } else {
                callData = abi.encodePacked(
                    bytes4(keccak256(bytes(proposal.signatures[i]))),
                    proposal.calldatas[i]
                );
            }

            // solium-disable-next-line security/no-call-value
            (bool success,) = proposal.targets[i].call{value:proposal.values[i]}(callData);

            // Require that transaction went through
            require(
                success,
                "TokensFarmCongress::executeTransaction: Transaction execution reverted."
            );

            // Emit event that transaction is being executed
            emit ExecuteTransaction(
                proposal.targets[i],
                proposal.values[i],
                proposal.signatures[i],
                proposal.calldatas[i]
            );
        }

        // Emit event that proposal executed
        emit ProposalExecuted(proposalId);
    }
// Solidity 0.6.12
/**
 * @notice function to cancel proposal
 *
 * @param proposalId - id of proposal
 */
function cancel(
        uint proposalId
    )
        external
        onlyMember
    {
        Proposal storage proposal = proposals[proposalId];
        // Require that proposal is not previously executed neither cancelled
        require(!proposal.executed && !proposal.canceled, "TokensFarmCongress:cancel: Proposal already executed or canceled");
        // 3 days after proposal can get cancelled
        require(block.timestamp >= proposal.timestamp + 259200, "TokensFarmCongress:cancel: Time lock hasn't ended yet");
        // Proposal with reached minimalQuorum cant be cancelled
        require(proposal.forVotes < membersRegistry.getMinimalQuorum(), "TokensFarmCongress:cancel: Proposal already reached quorum");
        // Set that proposal is cancelled
        proposal.canceled = true;
        // Emit event
        emit ProposalCanceled(proposalId);
    }
// Solidity 0.6.12
/**
 * @notice function to see what was voted on
 *
 * @param proposalId - id proposal
 *
 * @return targets
 * @return values
 * @return signatures
 * @return calldatas
 */
function getActions(
        uint proposalId
    )
        external
        view
        returns (
            address[] memory targets,
            uint[] memory values,
            string[] memory signatures,
            bytes[] memory calldatas
        )
    {
        Proposal storage p = proposals[proposalId];
        return (p.targets, p.values, p.signatures, p.calldatas);
    }
// Solidity 0.5.4
/**
 	 * @dev Return purchase receipt info at a given ID
 	 * @param _purchaseReceiptId The ID of the purchased content
 	 * @return The ID of the content host
 	 * @return The ID of the staked content
 	 * @return The ID of the content
 	 * @return address of the buyer
 	 * @return price of the content
 	 * @return amount paid by AO
 	 * @return amount paid by Buyer
 	 * @return request node's public key
 	 * @return request node's public address
 	 * @return created on timestamp
 	 */
function getById(bytes32 _purchaseReceiptId) external view returns (bytes32, bytes32, bytes32, address, uint256, uint256, uint256, string memory, address, uint256) {
		// Make sure the purchase receipt exist
		require (this.isExist(_purchaseReceiptId));
		PurchaseReceipt memory _purchaseReceipt = purchaseReceipts[purchaseReceiptIndex[_purchaseReceiptId]];
		return (
			_purchaseReceipt.contentHostId,
			_purchaseReceipt.stakedContentId,
			_purchaseReceipt.contentId,
			_purchaseReceipt.buyer,
			_purchaseReceipt.price,
			_purchaseReceipt.amountPaidByBuyer,
			_purchaseReceipt.amountPaidByAO,
			_purchaseReceipt.publicKey,
			_purchaseReceipt.publicAddress,
			_purchaseReceipt.createdOnTimestamp
		);
	}
// Solidity 0.5.4
/**
 	 * @dev Check whether or not the passed params valid
 	 * @param _buyer The address of the buyer
 	 * @param _contentHostId The ID of hosted content
 	 * @param _publicKey The public key of the request node
 	 * @param _publicAddress The public address of the request node
 	 * @return true if yes, false otherwise
 	 */
function _canBuy(address _buyer,
		bytes32 _contentHostId,
		string memory _publicKey,
		address _publicAddress
	) internal view returns (bool) {
		(bytes32 _stakedContentId,,address _host,,) = _aoContentHost.getById(_contentHostId);

		// Make sure the content host exist
		return (_aoContentHost.isExist(_contentHostId) &&
			_buyer != address(0) &&
			_buyer != _host &&
			AOLibrary.isName(_buyer) &&
			bytes(_publicKey).length > 0 &&
			_publicAddress != address(0) &&
			_aoStakedContent.isActive(_stakedContentId) &&
			buyerPurchaseReceipts[_buyer][_contentHostId][0] == 0
		);
	}
// Solidity 0.4.18
// Constructor function sets the BCDC Multisig address and
// total number of locked tokens to transfer
function BCDCVault(address _bcdcMultisig,uint256 _numBlocksLockedForDev,uint256 _numBlocksLockedForFounders) {
        // If it's not bcdcMultisig address then throw
        if (_bcdcMultisig == 0x0) throw;
        // Initalized bcdcToken
        bcdcToken = BCDCToken(msg.sender);
        // Initalized bcdcMultisig address
        bcdcMultisig = _bcdcMultisig;
        // Mark it as BCDCVault
        isBCDCVault = true;
        //Initalized numBlocksLockedDev and numBlocksLockedFounders with block number
        numBlocksLockedDev = _numBlocksLockedForDev;
        numBlocksLockedFounders = _numBlocksLockedForFounders;
        // Initalized unlockedBlockForDev with block number
        // according to current block
        unlockedBlockForDev = safeAdd(block.number, numBlocksLockedDev); // 30 days of blocks later
        // Initalized unlockedBlockForFounders with block number
        // according to current block
        unlockedBlockForFounders = safeAdd(block.number, numBlocksLockedFounders); // 365 days of blocks later
    }
// Solidity 0.4.18
// Transfer Development Team Tokens To MultiSigWallet - 30 Days Locked
function unlockForDevelopment() external {
        // If it has not reached 30 days mark do not transfer
        if (block.number < unlockedBlockForDev) throw;
        // If it is already unlocked then do not allowed
        if (unlockedAllTokensForDev) throw;
        // Mark it as unlocked
        unlockedAllTokensForDev = true;
        // Will fail if allocation (and therefore toTransfer) is 0.
        uint256 totalBalance = bcdcToken.balanceOf(this);
        // transfer half of token to development team
        uint256 developmentTokens = safeDiv(safeMul(totalBalance, 50), 100);
        if (!bcdcToken.transfer(bcdcMultisig, developmentTokens)) throw;
    }
// Solidity 0.4.18
//  Transfer Founders Team Tokens To MultiSigWallet - 365 Days Locked
function unlockForFounders() external {
        // If it has not reached 365 days mark do not transfer
        if (block.number < unlockedBlockForFounders) throw;
        // If it is already unlocked then do not allowed
        if (unlockedAllTokensForFounders) throw;
        // Mark it as unlocked
        unlockedAllTokensForFounders = true;
        // Will fail if allocation (and therefore toTransfer) is 0.
        if (!bcdcToken.transfer(bcdcMultisig, bcdcToken.balanceOf(this))) throw;
        // So that ether will not be trapped here.
        if (!bcdcMultisig.send(this.balance)) throw;
    }
// Solidity 0.4.18
//  Transfer `value` BCDC tokens from sender's account
// `msg.sender` to provided account address `to`.
// @dev Required state: Success
// @param to The address of the recipient
// @param value The number of BCDC tokens to transfer
// @return Whether the transfer was successful or not
function transfer(address to, uint value) returns (bool ok) {
        if (getState() != State.Success) throw; // Abort if crowdfunding was not a success.
        uint256 senderBalance = balances[msg.sender];
        if ( senderBalance >= value && value > 0) {
            senderBalance = safeSub(senderBalance, value);
            balances[msg.sender] = senderBalance;
            balances[to] = safeAdd(balances[to], value);
            Transfer(msg.sender, to, value);
            return true;
        }
        return false;
    }
// Solidity 0.4.18
// Sale of the tokens. Investors can call this method to invest into BCDC Tokens
// Only when it's in funding mode. In case of emergecy it will be halted.
function() payable stopIfHalted external {
        // Allow only to invest in funding state
        if (getState() != State.Funding) throw;

        // Sorry !! We do not allow to invest with 0 as value
        if (msg.value == 0) throw;

        // multiply by exchange rate to get newly created token amount
        uint256 createdTokens = safeMul(msg.value, tokensPerEther);

        // Wait we crossed maximum token sale goal. It's successful token sale !!
        if (safeAdd(createdTokens, totalSupply) > tokenSaleMax) throw;

        // Call to Internal function to assign tokens
        assignTokens(msg.sender, createdTokens);

        // Track the investment for each address till crowdsale ends
        investment[msg.sender] = safeAdd(investment[msg.sender], msg.value);
    }
// Solidity 0.4.18
// To allocate tokens to Project Fund - eg. RecycleToCoin before Token Sale
// Tokens allocated to these will not be count in totalSupply till the Token Sale Success and Finalized in finalizeCrowdfunding()
function preAllocation() onlyOwner stopIfHalted external {
        // Allow only in Pre Funding Mode
        if (getState() != State.PreFunding) throw;
        // Check if BCDC Reserve Fund is set or not
        if (bcdcReserveFund == 0x0) throw;
        // To prevent multiple call by mistake
        if (preallocated) throw;
        preallocated = true;
        // 25% of overall Token Supply to project reseve fund
        uint256 projectTokens = safeDiv(safeMul(maxTokenSupply, reservedPercentTotal), 100);
        // At this time we will not add to totalSupply because these are not part of Sale
        // It will be added in totalSupply once the Token Sale is Finalized
        balances[bcdcReserveFund] = projectTokens;
        // Log the event
        Transfer(0, bcdcReserveFund, projectTokens);
    }
// Solidity 0.4.18
// BCDC accepts Early Investment through manual process in Fiat Currency
// BCDC Team will assign the tokens to investors manually through this function
function earlyInvestment(address earlyInvestor, uint256 assignedTokens) onlyOwner stopIfHalted external {
        // Allow only in Pre Funding Mode And Funding Mode
        if (getState() != State.PreFunding && getState() != State.Funding) throw;
        // Check if earlyInvestor address is set or not
        if (earlyInvestor == 0x0) throw;
        // By mistake tokens mentioned as 0, save the cost of assigning tokens.
        if (assignedTokens == 0 ) throw;

        // Call to Internal function to assign tokens
        assignTokens(earlyInvestor, assignedTokens);

        // Track the investment for each address
        // Refund for this investor is taken care by out side the contract.because they are investing in their fiat currency
        //investment[earlyInvestor] = safeAdd(investment[earlyInvestor], etherValue);
    }
// Solidity 0.4.18
// Function will transfer the tokens to investor's address
// Common function code for Early Investor and Crowdsale Investor
function assignTokens(address investor, uint256 tokens) internal {
        // Creating tokens and  increasing the totalSupply
        totalSupply = safeAdd(totalSupply, tokens);

        // Assign new tokens to the sender
        balances[investor] = safeAdd(balances[investor], tokens);

        // Finally token created for sender, log the creation event
        Transfer(0, investor, tokens);
    }
// Solidity 0.4.18
// Call this function to get the refund of investment done during Crowdsale
// Refund can be done only when Min Goal has not reached and Crowdsale is over
function refund() external {
        // Abort if not in Funding Failure state.
        if (getState() != State.Failure) throw;

        uint256 bcdcValue = balances[msg.sender];
        if (bcdcValue == 0) throw;
        balances[msg.sender] = 0;
        totalSupply = safeSub(totalSupply, bcdcValue);

        uint256 ethValue = investment[msg.sender];
        investment[msg.sender] = 0;
        Refund(msg.sender, ethValue);
        if (!msg.sender.send(ethValue)) throw;
    }
// Solidity 0.4.18
// This will return the current state of Token Sale
// Read only method so no transaction fees
function getState() public constant returns (State){
      if (block.number < fundingStartBlock) return State.PreFunding;
      else if (block.number <= fundingEndBlock && totalSupply < tokenSaleMax) return State.Funding;
      else if (totalSupply >= tokenSaleMin || upgradeAgentStatus) return State.Success;
      else return State.Failure;
    }
// Solidity 0.4.18
/// @notice Upgrade tokens to the new token contract.
/// @dev Required state: Success
/// @param value The number of tokens to upgrade
function upgrade(uint256 value) external {
        if (!upgradeAgentStatus) throw;
        /*if (getState() != State.Success) throw; // Abort if not in Success state.*/
        if (upgradeAgent.owner() == 0x0) throw; // need a real upgradeAgent address
        if (finalizedUpgrade) throw; // cannot upgrade if finalized

        // Validate input value.
        if (value == 0) throw;
        if (value > balances[msg.sender]) throw;

        // update the balances here first before calling out (reentrancy)
        balances[msg.sender] = safeSub(balances[msg.sender], value);
        totalSupply = safeSub(totalSupply, value);
        totalUpgraded = safeAdd(totalUpgraded, value);
        upgradeAgent.upgradeFrom(msg.sender, value);
        Upgrade(msg.sender, upgradeAgent, value);
    }
// Solidity 0.4.18
/// @notice Set address of upgrade target contract and enable upgrade
/// process.
/// @dev Required state: Success
/// @param agent The address of the UpgradeAgent contract
function setUpgradeAgent(address agent) external {
        if (getState() != State.Success) throw; // Abort if not in Success state.
        if (agent == 0x0) throw; // don't set agent to nothing
        if (msg.sender != upgradeMaster) throw; // Only a master can designate the next agent
        upgradeAgent = UpgradeAgent(agent);
        if (!upgradeAgent.isUpgradeAgent()) throw;
        // this needs to be called in success condition to guarantee the invariant is true
        upgradeAgentStatus = true;
        upgradeAgent.setOriginalSupply();
        UpgradeAgentSet(upgradeAgent);
    }
// Solidity 0.4.18
/// @notice Set address of upgrade target contract and enable upgrade
/// process.
/// @dev Required state: Success
/// @param master The address that will manage upgrades, not the upgradeAgent contract address
function setUpgradeMaster(address master) external {
        if (getState() != State.Success) throw; // Abort if not in Success state.
        if (master == 0x0) throw;
        if (msg.sender != upgradeMaster) throw; // Only a master can designate the next master
        upgradeMaster = master;
    }
// Solidity 0.4.18
// This method is only use for transfer bcdctoken from bcdcReserveFund
// @dev Required state: is bcdcReserveFund set
// @param to The address of the recipient
// @param value The number of BCDC tokens to transfer
// @return Whether the transfer was successful or not
function reserveTokenClaim(address claimAddress,uint256 token) onlyBcdcReserve returns (bool ok){
      // Check if BCDC Reserve Fund is set or not
      if ( bcdcReserveFund == 0x0) throw;
      uint256 senderBalance = balances[msg.sender];
      if(senderBalance >= token && token>0){
        senderBalance = safeSub(senderBalance, token);
        balances[msg.sender] = senderBalance;
        balances[claimAddress] = safeAdd(balances[claimAddress], token);
        Transfer(msg.sender, claimAddress, token);
        return true;
      }
      return false;
    }
// Solidity 0.4.18
// This method is for getting bcdctoken as rewards
// @param tokens The number of tokens back for rewards
function backTokenForRewards(uint256 tokens) external{
  		// Check that token available for transfer
  		if(balances[msg.sender] < tokens && tokens <= 0) throw;

  		// Debit tokens from msg.sender
  		balances[msg.sender] = safeSub(balances[msg.sender], tokens);

  		// Credit tokens into bcdcReserveFund
  		balances[bcdcReserveFund] = safeAdd(balances[bcdcReserveFund], tokens);
  		Transfer(msg.sender, bcdcReserveFund, tokens);
  	}
// Solidity 0.4.25
// Return the current schedule based on the timestamp
// applicable based on startPeriod and endPeriod
function getCurrentSchedule()
        public
        view
        returns (uint)
    {
        require(now <= schedules[6].endPeriod, "Mintable periods have ended");

        for (uint i = 0; i < INFLATION_SCHEDULES_LENGTH; i++) {
            if (schedules[i].startPeriod <= now && schedules[i].endPeriod >= now) {
                return i;
            }
        }
    }