Skip to content

Commit 4c58b63

Browse files
committed
refactor: remove some internal functions
1 parent 2b902cd commit 4c58b63

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

src/multichain/CrossChainRegistry.sol

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,24 @@ contract CrossChainRegistry is
199199
bytes32 operatorSetKey = operatorSet.key();
200200

201201
// Check if this is the first transport destination (create reservation if needed)
202-
if (!_activeTransportReservations.contains(operatorSetKey) && chainIDs.length > 0) {
202+
if (!_activeTransportReservations.contains(operatorSetKey)) {
203203
_activeTransportReservations.add(operatorSetKey);
204204
}
205205

206206
for (uint256 i = 0; i < chainIDs.length; i++) {
207-
_addTransportDestination(operatorSet, chainIDs[i]);
207+
uint32 chainID = chainIDs[i];
208+
209+
// Validate chainID
210+
require(chainID != 0, InvalidChainId());
211+
// Check if chainID is whitelisted
212+
require(_whitelistedChainIDs.contains(chainID), ChainIDNotWhitelisted());
213+
// Check if already added
214+
require(!_transportDestinations[operatorSetKey].contains(chainID), TransportDestinationAlreadyAdded());
215+
216+
// Add transport destination
217+
_transportDestinations[operatorSetKey].add(chainID);
218+
219+
emit TransportDestinationAdded(operatorSet, chainID);
208220
}
209221
}
210222

@@ -225,7 +237,17 @@ contract CrossChainRegistry is
225237
require(_activeTransportReservations.contains(operatorSetKey), TransportReservationDoesNotExist());
226238

227239
for (uint256 i = 0; i < chainIDs.length; i++) {
228-
_removeTransportDestination(operatorSet, chainIDs[i]);
240+
uint32 chainID = chainIDs[i];
241+
242+
// Validate chainID
243+
require(chainID != 0, InvalidChainId());
244+
// Check if transport destination exists
245+
require(_transportDestinations[operatorSetKey].contains(chainID), TransportDestinationNotFound());
246+
247+
// Remove transport destination
248+
_transportDestinations[operatorSetKey].remove(chainID);
249+
250+
emit TransportDestinationRemoved(operatorSet, chainID);
229251
}
230252

231253
// Check if all transport destinations have been removed
@@ -319,48 +341,6 @@ contract CrossChainRegistry is
319341
emit OperatorSetConfigSet(operatorSet, config);
320342
}
321343

322-
/**
323-
* @dev Internal function to add a transport destination for an operator set
324-
* @param operatorSet The operator set to add the transport destination for
325-
* @param chainID The chain ID to add the transport destination for
326-
*/
327-
function _addTransportDestination(OperatorSet calldata operatorSet, uint32 chainID) internal {
328-
// Validate chainID
329-
require(chainID != 0, InvalidChainId());
330-
// Check if chainID is whitelisted
331-
require(_whitelistedChainIDs.contains(chainID), ChainIDNotWhitelisted());
332-
333-
bytes32 operatorSetKey = operatorSet.key();
334-
335-
// Check if already added
336-
require(!_transportDestinations[operatorSetKey].contains(chainID), TransportDestinationAlreadyAdded());
337-
338-
// Add transport destination
339-
_transportDestinations[operatorSetKey].add(chainID);
340-
341-
emit TransportDestinationAdded(operatorSet, chainID);
342-
}
343-
344-
/**
345-
* @dev Internal function to remove a transport destination for an operator set
346-
* @param operatorSet The operator set to remove the transport destination for
347-
* @param chainID The chain ID to remove the transport destination for
348-
*/
349-
function _removeTransportDestination(OperatorSet calldata operatorSet, uint32 chainID) internal {
350-
// Validate chainID
351-
require(chainID != 0, InvalidChainId());
352-
353-
bytes32 operatorSetKey = operatorSet.key();
354-
355-
// Check if transport destination exists
356-
require(_transportDestinations[operatorSetKey].contains(chainID), TransportDestinationNotFound());
357-
358-
// Remove transport destination
359-
_transportDestinations[operatorSetKey].remove(chainID);
360-
361-
emit TransportDestinationRemoved(operatorSet, chainID);
362-
}
363-
364344
/**
365345
* @dev Internal helper function to convert EnumerableSet.UintSet to uint32[]
366346
* @param set The EnumerableSet.UintSet to convert

0 commit comments

Comments
 (0)