-
Notifications
You must be signed in to change notification settings - Fork 552
MultichainRegistry: new code pattern #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
function add( | ||
address _deployer, | ||
address _deployment, | ||
uint256 _chainId, | ||
string memory metadataUri | ||
) external { | ||
require( | ||
PermissionsEnumerable(address(this)).hasRole(OPERATOR_ROLE, _msgSender()) || _deployer == _msgSender(), | ||
"not operator or deployer." | ||
); | ||
|
||
TWMultichainRegistryStorage.Data storage data = TWMultichainRegistryStorage.multichainRegistryStorage(); | ||
|
||
bool added = data.deployments[_deployer][_chainId].add(_deployment); | ||
require(added, "failed to add"); | ||
|
||
data.chainIds.add(_chainId); | ||
|
||
if (bytes(metadataUri).length > 0) { | ||
data.addressToMetadataUri[_chainId][_deployment] = metadataUri; | ||
} | ||
|
||
emit Added(_deployer, _deployment, _chainId, metadataUri); | ||
} |
Check warning
Code scanning / Slither
Unused return
function multichainRegistryStorage() internal pure returns (Data storage multichainRegistryData) { | ||
bytes32 position = MULTICHAIN_REGISTRY_STORAGE_POSITION; | ||
assembly { | ||
multichainRegistryData.slot := position | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function permissionsStorage() internal pure returns (Data storage permissionsData) { | ||
bytes32 position = PERMISSIONS_STORAGE_POSITION; | ||
assembly { | ||
permissionsData.slot := position | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function erc2771ContextStorage() internal pure returns (Data storage erc2771ContextData) { | ||
bytes32 position = ERC2771_CONTEXT_STORAGE_POSITION; | ||
assembly { | ||
erc2771ContextData.slot := position | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function permissionsEnumerableStorage() internal pure returns (Data storage permissionsEnumerableData) { | ||
bytes32 position = PERMISSIONS_ENUMERABLE_STORAGE_POSITION; | ||
assembly { | ||
permissionsEnumerableData.slot := position | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function _msgSender() public view virtual returns (address sender) { | ||
if (IERC2771Context(address(this)).isTrustedForwarder(msg.sender)) { | ||
// The assembly code is more direct than the Solidity version using `abi.decode`. | ||
assembly { | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
} else { | ||
return msg.sender; | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function getRoleMember(bytes32 role, uint256 index) external view override returns (address member) { | ||
PermissionsEnumerableStorage.Data storage data = PermissionsEnumerableStorage.permissionsEnumerableStorage(); | ||
uint256 currentIndex = data.roleMembers[role].index; | ||
uint256 check; |
Check warning
Code scanning / Slither
Uninitialized local variables
function _msgSender() internal view virtual returns (address sender) { | ||
if (isTrustedForwarder(msg.sender)) { | ||
// The assembly code is more direct than the Solidity version using `abi.decode`. | ||
assembly { | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
} else { | ||
return msg.sender; | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
function _msgSender() internal view override(ERC2771ContextLogic, PermissionsLogic) returns (address sender) { | ||
if (isTrustedForwarder(msg.sender)) { | ||
// The assembly code is more direct than the Solidity version using `abi.decode`. | ||
assembly { | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
} else { | ||
return msg.sender; | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
No description provided.