Skip to content

Commit

Permalink
feat: add decodeAccessControlParameters to IAccessModule (#57)
Browse files Browse the repository at this point in the history
* feat: add decodeAccessControlParameters to IAccessModule

* feat: update MockAccessModule
  • Loading branch information
xorsal authored Nov 15, 2024
1 parent 5880af4 commit 819e5fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 10 additions & 0 deletions solidity/interfaces/modules/access/IAccessModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ interface IAccessModule is IModule {
* @return _hasAccess True if the caller has access to the user
*/
function hasAccess(bytes calldata _data) external returns (bool _hasAccess);

/**
* @notice Decodes the access control parameters
* @param _data The encoded access control parameters
* @return _params The decoded access control parameters
*/
function decodeAccessControlParameters(bytes calldata _data)
external
pure
returns (AccessControlParameters memory _params);
}
16 changes: 11 additions & 5 deletions solidity/test/mocks/contracts/MockAccessModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
import {Module} from '../../../contracts/Module.sol';

import {IOracle} from '../../../interfaces/IOracle.sol';
import {IAccessController} from '../../../interfaces/access/IAccessController.sol';
import {IAccessModule, IMockAccessModule} from '../interfaces/IMockAccessModule.sol';

contract MockAccessModule is Module, IMockAccessModule {
Expand All @@ -20,16 +21,21 @@ contract MockAccessModule is Module, IMockAccessModule {
function moduleName() external view returns (string memory _moduleName) {}

function hasAccess(bytes memory _data) external view returns (bool _hasAccess) {
IAccessModule.AccessControlParameters memory _accessControlData = decodeAccesControlData(_data);
IAccessModule.AccessControlParameters memory _accessControlData = decodeAccessControlParameters(_data);
_hasAccess = callerHasAccess[_accessControlData.sender];
}

function decodeAccesControlData(bytes memory _data)
function decodeAccessControlParameters(bytes memory _data)
public
pure
override
returns (IAccessModule.AccessControlParameters memory _accessControlData)
returns (IAccessModule.AccessControlParameters memory _params)
{
_accessControlData = abi.decode(_data, (IAccessModule.AccessControlParameters));
_params = abi.decode(_data, (IAccessModule.AccessControlParameters));
}

function decodeAccesControlData(IAccessController.AccessControl calldata _accessControl)
external
view
returns (bytes memory _data)
{}
}
6 changes: 3 additions & 3 deletions solidity/test/mocks/interfaces/IMockAccessModule.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IAccessModule} from '../../../interfaces/modules/access/IAccessModule.sol';
import {IAccessController, IAccessModule} from '../../../interfaces/modules/access/IAccessModule.sol';

interface IMockAccessModule is IAccessModule {
function decodeAccesControlData(bytes calldata _data)
function decodeAccesControlData(IAccessController.AccessControl calldata _accessControl)
external
view
returns (AccessControlParameters memory _accessControlData);
returns (bytes memory _data);
}

0 comments on commit 819e5fe

Please sign in to comment.