Skip to main content

setTerminalsOf

Contract: JBDirectory​‌

Interface: IJBDirectory

Set a project's terminals.

Only a project owner, an operator, or its controller can set its terminals.

Definition

function setTerminalsOf(uint256 _projectId, IJBPaymentTerminal[] calldata _terminals)
external
override
requirePermissionAllowingOverride(
projects.ownerOf(_projectId),
_projectId,
JBOperations.SET_TERMINALS,
msg.sender == address(controllerOf[_projectId])
) { ... }
  • Arguments:
    • _projectId is the ID of the project having terminals set.
    • _terminals is the terminals to set.
  • Through the requirePermissionAllowingOverride modifier, the function is only accessible by the project's owner, from an operator that has been given the JBOperations.SET_TERMINALS permission by the project owner for the provided _projectId, or by the project's controller.
  • The function overrides a function definition from the IJBDirectory interface.
  • The function doesn't return anything.

Body

  1. 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);

    External references:

  2. Make sure the project's current funding cycle is set to allow setting terminals, or the request to set the terminals 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:

  3. 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);

    External references:

  4. Delete the project's current set of terminals from storage.

    // Set the stored terminals for the project.
    _terminalsOf[_projectId] = _terminals;

    Internal references:

  5. Make sure the same terminal isn't being set multiple times.

    // Make sure duplicates were not added.
    if (_terminals.length > 1)
    for (uint256 _i; _i < _terminals.length; ) {
    for (uint256 _j = _i + 1; _j < _terminals.length; ) {
    if (_terminals[_i] == _terminals[_j]) revert DUPLICATE_TERMINALS();

    unchecked {
    ++_j;
    }
    }

    unchecked {
    ++_i;
    }
    }
  6. Emit a SetTerminals event with the relevant parameters.

    emit SetTerminals(_projectId, _terminals, msg.sender);

    Event references: