Skip to content

Commit bc810db

Browse files
JoeysantoroAmxxfrangio
authored
Use a customizable _execute function in TimelockController (OpenZeppelin#3317)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
1 parent dd01889 commit bc810db

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
* `ERC2981`: make `royaltiInfo` public to allow super call in overrides. ([#3305](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3305))
5+
* `TimelockController`: Migrate `_call` to `_execute` and allow inheritance and overriding similar to `Governor`. ([#3317](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3317))
56

67
## Unreleased
78

contracts/governance/TimelockController.sol

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma solidity ^0.8.0;
66
import "../access/AccessControl.sol";
77
import "../token/ERC721/IERC721Receiver.sol";
88
import "../token/ERC1155/IERC1155Receiver.sol";
9+
import "../utils/Address.sol";
910

1011
/**
1112
* @dev Contract module which acts as a timelocked controller. When set as the
@@ -288,13 +289,15 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
288289
function execute(
289290
address target,
290291
uint256 value,
291-
bytes calldata data,
292+
bytes calldata payload,
292293
bytes32 predecessor,
293294
bytes32 salt
294295
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
295-
bytes32 id = hashOperation(target, value, data, predecessor, salt);
296+
bytes32 id = hashOperation(target, value, payload, predecessor, salt);
297+
296298
_beforeCall(id, predecessor);
297-
_call(id, 0, target, value, data);
299+
_execute(target, value, payload);
300+
emit CallExecuted(id, 0, target, value, payload);
298301
_afterCall(id);
299302
}
300303

@@ -318,13 +321,30 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
318321
require(targets.length == payloads.length, "TimelockController: length mismatch");
319322

320323
bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);
324+
321325
_beforeCall(id, predecessor);
322326
for (uint256 i = 0; i < targets.length; ++i) {
323-
_call(id, i, targets[i], values[i], payloads[i]);
327+
address target = targets[i];
328+
uint256 value = values[i];
329+
bytes calldata payload = payloads[i];
330+
_execute(target, value, payload);
331+
emit CallExecuted(id, i, target, value, payload);
324332
}
325333
_afterCall(id);
326334
}
327335

336+
/**
337+
* @dev Execute an operation's call.
338+
*/
339+
function _execute(
340+
address target,
341+
uint256 value,
342+
bytes calldata data
343+
) internal virtual {
344+
(bool success, ) = target.call{value: value}(data);
345+
require(success, "TimelockController: underlying transaction reverted");
346+
}
347+
328348
/**
329349
* @dev Checks before execution of an operation's calls.
330350
*/
@@ -341,24 +361,6 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
341361
_timestamps[id] = _DONE_TIMESTAMP;
342362
}
343363

344-
/**
345-
* @dev Execute an operation's call.
346-
*
347-
* Emits a {CallExecuted} event.
348-
*/
349-
function _call(
350-
bytes32 id,
351-
uint256 index,
352-
address target,
353-
uint256 value,
354-
bytes calldata data
355-
) private {
356-
(bool success, ) = target.call{value: value}(data);
357-
require(success, "TimelockController: underlying transaction reverted");
358-
359-
emit CallExecuted(id, index, target, value, data);
360-
}
361-
362364
/**
363365
* @dev Changes the minimum timelock duration for future operations.
364366
*

0 commit comments

Comments
 (0)