跳到主要内容

_addTerminalIfNeeded

Contract: JBDirectory​‌

Interface: IJBDirectory

Add a terminal to a project's list of terminals if it hasn't been already.

Definition

function _addTerminalIfNeeded(uint256 _projectId, IJBPaymentTerminal _terminal) private { ... }
  • Arguments:
    • _projectId is the ID of the project having a terminal added.
    • _terminal is the terminal to add.
  • The function is private to this contract.
  • The function doesn't return anything.

Body

  1. Nothing to do if the terminal is already a terminal of the project.

    // Check that the terminal has not already been added.
    if (isTerminalOf(_projectId, _terminal)) return;

    Internal references:

  2. Get a reference to the project's current funding cycle.

    // Get a reference to the project's current funding cycle.
    JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);

    Internal references:

    External references:

  3. Make sure the project's current funding cycle is set to allow setting its terminals, or the request to set the controller is coming from the project's current controller.

    // Setting terminals must be allowed if not called from the current controller.
    if (
    msg.sender != address(controllerOf[_projectId]) && !_fundingCycle.global().allowSetTerminals
    ) revert SET_TERMINALS_NOT_ALLOWED();

    Library references:

    Internal references:

  4. Add the terminal.

    // Add the new terminal.
    _terminalsOf[_projectId].push(_terminal);

    Internal references:

  5. Emit a AddTerminal event with the relevant parameters.

    emit AddTerminal(_projectId, _terminal, msg.sender);

    Event references: