setTerminalsOf
Contract: JBDirectory
Interface: IJBDirectory
- Step by step
 - Code
 - Errors
 - Events
 - Bug bounty
 
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:
_projectIdis the ID of the project having terminals set._terminalsis the terminals to set.
 - Through the 
requirePermissionAllowingOverridemodifier, the function is only accessible by the project's owner, from an operator that has been given theJBOperations.SET_TERMINALSpermission by the project owner for the provided_projectId, or by the project's controller. - The function overrides a function definition from the 
IJBDirectoryinterface. - The function doesn't return anything.
 
Body
- 
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:
 - 
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:
JBFundingCycleMetadataResolver.setTerminalsAllowed(...)
Internal references:
 - 
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:
 - 
Delete the project's current set of terminals from storage.
// Set the stored terminals for the project.
_terminalsOf[_projectId] = _terminals;Internal references:
 - 
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;
}
} - 
Emit a
SetTerminalsevent with the relevant parameters.emit SetTerminals(_projectId, _terminals, msg.sender);Event references:
 
/**
  @notice
  Set a project's terminals.
  @dev
  Only a project owner, an operator, or its controller can set its terminals.
  @param _projectId The ID of the project having terminals set.
  @param _terminals The terminal to set.
*/
function setTerminalsOf(uint256 _projectId, IJBPaymentTerminal[] calldata _terminals)
  external
  override
  requirePermissionAllowingOverride(
    projects.ownerOf(_projectId),
    _projectId,
    JBOperations.SET_TERMINALS,
    msg.sender == address(controllerOf[_projectId])
  )
{
  // Get a reference to the project's current funding cycle.
  JBFundingCycle memory _fundingCycle = fundingCycleStore.currentOf(_projectId);
  // 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();
  // Set the stored terminals for the project.
  _terminalsOf[_projectId] = _terminals;
  // 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;
      }
    }
  emit SetTerminals(_projectId, _terminals, msg.sender);
}
| String | Description | 
|---|---|
ADD_TERMINAL_ZERO_ADDRESS | Thrown if a provided terminal to add is the zero address. | 
DUPLICATE_TERMINALS | Thrown if the same terminal is being set multiple times. | 
SET_TERMINALS_NOT_ALLOWED | Thrown if the provided project isn't currently allowed to set its terminals. | 
| Name | Data | 
|---|---|
SetTerminals | 
  | 
| Category | Description | Reward | 
|---|---|---|
| Optimization | Help make this operation more efficient. | 0.5ETH | 
| Low severity | Identify a vulnerability in this operation that could lead to an inconvenience for a user of the protocol or for a protocol developer. | 1ETH | 
| High severity | Identify a vulnerability in this operation that could lead to data corruption or loss of funds. | 5+ETH |