Skip to content

Commit

Permalink
misc: disable() action split into enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
vicnaum committed Dec 23, 2024
1 parent 06eb2f9 commit 31e20f7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
8 changes: 5 additions & 3 deletions contracts/actions/account/base/BaseAccountAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ abstract contract BaseAccountAction is BaseAction, IAccountAction {
return _execute(originalMsgSender, account, params);
}

function disable(
function setDisabled(
address originalMsgSender,
address account,
bool isDisabled,
KeyValue[] calldata params
) external override onlyActionHub returns (bytes memory) {
return _disable(originalMsgSender, account, params);
return _setDisabled(originalMsgSender, account, isDisabled, params);
}

function _configure(
Expand All @@ -47,9 +48,10 @@ abstract contract BaseAccountAction is BaseAction, IAccountAction {
KeyValue[] calldata params
) internal virtual returns (bytes memory);

function _disable(
function _setDisabled(
address, /* originalMsgSender */
address, /* account */
bool, /* isDisabled */
KeyValue[] calldata /* params */
) internal virtual returns (bytes memory) {
revert();
Expand Down
8 changes: 5 additions & 3 deletions contracts/actions/post/base/BasePostAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ abstract contract BasePostAction is BaseAction, IPostAction {
return _execute(originalMsgSender, feed, postId, params);
}

function disable(
function setDisabled(
address originalMsgSender,
address feed,
uint256 postId,
bool isDisabled,
KeyValue[] calldata params
) external override onlyActionHub returns (bytes memory) {
return _disable(originalMsgSender, feed, postId, params);
return _setDisabled(originalMsgSender, feed, postId, isDisabled, params);
}

function _configure(
Expand All @@ -52,10 +53,11 @@ abstract contract BasePostAction is BaseAction, IPostAction {
KeyValue[] calldata params
) internal virtual returns (bytes memory);

function _disable(
function _setDisabled(
address, /* originalMsgSender */
address, /* feed */
uint256, /* postId */
bool, /* isDisabled */
KeyValue[] calldata /* params */
) internal virtual returns (bytes memory) {
revert();
Expand Down
44 changes: 40 additions & 4 deletions contracts/dashboard/actions/ActionHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ interface IPostAction {
KeyValue[] calldata params
) external returns (bytes memory);

function disable(
function setDisabled(
address originalMsgSender,
address feed,
uint256 postId,
bool isDisabled,
KeyValue[] calldata params
) external returns (bytes memory);
}
Expand All @@ -40,9 +41,10 @@ interface IAccountAction {
KeyValue[] calldata params
) external returns (bytes memory);

function disable(
function setDisabled(
address originalMsgSender,
address account,
bool isDisabled,
KeyValue[] calldata params
) external returns (bytes memory);
}
Expand Down Expand Up @@ -80,6 +82,15 @@ contract ActionHub {
bytes returnData
);

event Lens_ActionHub_PostAction_Enabled(
address indexed action,
address indexed msgSender,
address feed,
uint256 indexed postId,
KeyValue[] params,
bytes returnData
);

event Lens_ActionHub_AccountAction_Universal(address indexed action);

event Lens_ActionHub_AccountAction_Configured(
Expand All @@ -94,6 +105,10 @@ contract ActionHub {
address indexed action, address indexed msgSender, address indexed account, KeyValue[] params, bytes returnData
);

event Lens_ActionHub_AccountAction_Enabled(
address indexed action, address indexed msgSender, address indexed account, KeyValue[] params, bytes returnData
);

function signalUniversalPostAction(address action) external {
bytes memory returnData = IPostAction(action).configure(address(0), address(0), 0, new KeyValue[](0));
require(abi.decode(returnData, (bytes32)) == UNIVERSAL_ACTION_MAGIC_VALUE);
Expand Down Expand Up @@ -128,11 +143,22 @@ contract ActionHub {
uint256 postId,
KeyValue[] calldata params
) external payable returns (bytes memory) {
bytes memory returnData = IPostAction(action).disable(msg.sender, feed, postId, params);
bytes memory returnData = IPostAction(action).setDisabled(msg.sender, feed, postId, true, params);
emit Lens_ActionHub_PostAction_Disabled(action, msg.sender, feed, postId, params, returnData);
return returnData;
}

function enablePostAction(
address action,
address feed,
uint256 postId,
KeyValue[] calldata params
) external payable returns (bytes memory) {
bytes memory returnData = IPostAction(action).setDisabled(msg.sender, feed, postId, false, params);
emit Lens_ActionHub_PostAction_Enabled(action, msg.sender, feed, postId, params, returnData);
return returnData;
}

function signalUniversalAccountAction(address action) external {
bytes memory returnData = IAccountAction(action).configure(address(0), address(0), new KeyValue[](0));
require(abi.decode(returnData, (bytes32)) == UNIVERSAL_ACTION_MAGIC_VALUE);
Expand Down Expand Up @@ -164,8 +190,18 @@ contract ActionHub {
address account,
KeyValue[] calldata params
) external payable returns (bytes memory) {
bytes memory returnData = IAccountAction(action).disable(msg.sender, account, params);
bytes memory returnData = IAccountAction(action).setDisabled(msg.sender, account, true, params);
emit Lens_ActionHub_AccountAction_Disabled(action, msg.sender, account, params, returnData);
return returnData;
}

function enableAccountAction(
address action,
address account,
KeyValue[] calldata params
) external payable returns (bytes memory) {
bytes memory returnData = IAccountAction(action).setDisabled(msg.sender, account, false, params);
emit Lens_ActionHub_AccountAction_Enabled(action, msg.sender, account, params, returnData);
return returnData;
}
}

0 comments on commit 31e20f7

Please sign in to comment.