Last active
April 27, 2022 23:44
-
-
Save CJ42/0885a7e8b1c9dff0d150cf806e99605b to your computer and use it in GitHub Desktop.
code from the KeyManager contract from LUKSO to explain omitting parentheses in if statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: Apache-2.0 | |
pragma solidity ^0.8.6; | |
// imports and errors declarations omitted for brievity ... | |
/** | |
* @title Core implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage | |
* @author Fabian Vogelsteller, Jean Cavallera | |
* @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below | |
*/ | |
abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165 { | |
// libraries and other functions omitted for brievity ... | |
/** | |
* @dev verify the permissions of the _from address that want to interact with the `account` | |
* @param _from the address making the request | |
* @param _data the payload that will be run on `account` | |
*/ | |
function _verifyPermissions(address _from, bytes calldata _data) | |
internal | |
view | |
{ | |
bytes4 erc725Function = bytes4(_data[:4]); | |
// get the permissions of the caller | |
bytes32 permissions = ERC725Y(account).getPermissionsFor(_from); | |
// skip permissions check if caller has all permissions (except SIGN as not required) | |
// ... | |
if (erc725Function == setDataMultipleSelector) { | |
_verifyCanSetData(_from, permissions, _data); | |
} else if (erc725Function == IERC725X.execute.selector) { | |
_verifyCanExecute(_from, permissions, _data); | |
// more permissions checks to verify if the address making is allowed to: | |
// - interact with a specific address | |
// - run a specific function on the contract being called | |
// - can interact with a contract implementing a specific standard interface | |
// (omitted for brievity) | |
} else if (erc725Function == OwnableUnset.transferOwnership.selector) { | |
if (!permissions.includesPermissions(_PERMISSION_CHANGEOWNER)) | |
revert NotAuthorised(_from, "TRANSFEROWNERSHIP"); | |
} else { | |
revert("_verifyPermissions: unknown ERC725 selector"); | |
} | |
} | |
// other functions omitted for brievity ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment