-
Notifications
You must be signed in to change notification settings - Fork 552
Plugin refactor #302
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
Plugin refactor #302
Conversation
function _removePlugin(bytes4 _selector) internal { | ||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
address currentPlugin = _getPluginForFunction(_selector); | ||
require(currentPlugin != address(0), "Router: No plugin available for selector"); | ||
|
||
delete data.pluginForSelector[_selector]; | ||
data.allSelectors.remove(_selector); | ||
data.selectorsForPlugin[currentPlugin].remove(bytes32(_selector)); | ||
|
||
emit PluginRemoved(_selector, currentPlugin); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _addPlugin(Plugin memory _plugin) internal { | ||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
require(data.allSelectors.add(bytes32(_plugin.selector)), "Router: Selector exists"); | ||
require( | ||
_plugin.selector == bytes4(keccak256(abi.encodePacked(_plugin.functionString))), | ||
"Router: Incorrect selector" | ||
); | ||
|
||
data.pluginForSelector[_plugin.selector] = _plugin; | ||
data.selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.selector)); | ||
|
||
emit PluginAdded(_plugin.selector, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _removePlugin(bytes4 _selector) internal { | ||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
address currentPlugin = _getPluginForFunction(_selector); | ||
require(currentPlugin != address(0), "Router: No plugin available for selector"); | ||
|
||
delete data.pluginForSelector[_selector]; | ||
data.allSelectors.remove(_selector); | ||
data.selectorsForPlugin[currentPlugin].remove(bytes32(_selector)); | ||
|
||
emit PluginRemoved(_selector, currentPlugin); | ||
} |
Check warning
Code scanning / Slither
Unused return
function routerStorage() internal pure returns (Data storage routerData) { | ||
bytes32 position = ROUTER_STORAGE_POSITION; | ||
assembly { | ||
routerData.slot := position | ||
} | ||
} |
Check warning
Code scanning / Slither
Assembly usage
contracts/extension/plugin/Map.sol
Outdated
@@ -5,7 +5,7 @@ import "../interface/plugin/IMap.sol"; | |||
|
|||
import "../../openzeppelin-presets/utils/EnumerableSet.sol"; | |||
|
|||
abstract contract Map is IMap { | |||
contract Map is IMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this PluginMap
instead to be specific?
@@ -15,23 +15,8 @@ interface IMap { | |||
string functionString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this functionSignature
} | ||
|
||
registered = new Plugin[](totalCount); | ||
uint256 index; |
Check warning
Code scanning / Slither
Uninitialized local variables
} | ||
|
||
registered = new bytes4[](count); | ||
uint256 index; |
Check warning
Code scanning / Slither
Uninitialized local variables
function _updatePlugin(Plugin memory _plugin) internal { | ||
address currentPlugin = getPluginForFunction(_plugin.functionSelector); | ||
require( | ||
_plugin.functionSelector == bytes4(keccak256(abi.encodePacked(_plugin.functionSignature))), | ||
"Router: fn selector and signature mismatch." | ||
); | ||
|
||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
data.allSelectors.add(bytes32(_plugin.functionSelector)); | ||
data.pluginForSelector[_plugin.functionSelector] = _plugin; | ||
data.selectorsForPlugin[currentPlugin].remove(bytes32(_plugin.functionSelector)); | ||
data.selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.functionSelector)); | ||
|
||
emit PluginUpdated(_plugin.functionSelector, currentPlugin, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _updatePlugin(Plugin memory _plugin) internal { | ||
address currentPlugin = getPluginForFunction(_plugin.functionSelector); | ||
require( | ||
_plugin.functionSelector == bytes4(keccak256(abi.encodePacked(_plugin.functionSignature))), | ||
"Router: fn selector and signature mismatch." | ||
); | ||
|
||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
data.allSelectors.add(bytes32(_plugin.functionSelector)); | ||
data.pluginForSelector[_plugin.functionSelector] = _plugin; | ||
data.selectorsForPlugin[currentPlugin].remove(bytes32(_plugin.functionSelector)); | ||
data.selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.functionSelector)); | ||
|
||
emit PluginUpdated(_plugin.functionSelector, currentPlugin, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _updatePlugin(Plugin memory _plugin) internal { | ||
address currentPlugin = getPluginForFunction(_plugin.functionSelector); | ||
require( | ||
_plugin.functionSelector == bytes4(keccak256(abi.encodePacked(_plugin.functionSignature))), | ||
"Router: fn selector and signature mismatch." | ||
); | ||
|
||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
data.allSelectors.add(bytes32(_plugin.functionSelector)); | ||
data.pluginForSelector[_plugin.functionSelector] = _plugin; | ||
data.selectorsForPlugin[currentPlugin].remove(bytes32(_plugin.functionSelector)); | ||
data.selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.functionSelector)); | ||
|
||
emit PluginUpdated(_plugin.functionSelector, currentPlugin, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _addPlugin(Plugin memory _plugin) internal { | ||
RouterStorage.Data storage data = RouterStorage.routerStorage(); | ||
|
||
// Revert: default plugin exists for function; use updatePlugin instead. | ||
try IPluginMap(functionMap).getPluginForFunction(_plugin.functionSelector) returns (address) { | ||
revert("Router: default plugin exists for function."); | ||
} catch { | ||
require(data.allSelectors.add(bytes32(_plugin.functionSelector)), "Router: plugin exists for function."); | ||
} | ||
|
||
require( | ||
_plugin.functionSelector == bytes4(keccak256(abi.encodePacked(_plugin.functionSignature))), | ||
"Router: fn selector and signature mismatch." | ||
); | ||
|
||
data.pluginForSelector[_plugin.functionSelector] = _plugin; | ||
data.selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.functionSelector)); | ||
|
||
emit PluginAdded(_plugin.functionSelector, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
function _setPlugin(Plugin memory _plugin) internal { | ||
require(allSelectors.add(bytes32(_plugin.functionSelector)), "Map: Selector exists"); | ||
require( | ||
_plugin.functionSelector == bytes4(keccak256(abi.encodePacked(_plugin.functionSignature))), | ||
"Map: Incorrect selector" | ||
); | ||
|
||
pluginForSelector[_plugin.functionSelector] = _plugin; | ||
selectorsForPlugin[_plugin.pluginAddress].add(bytes32(_plugin.functionSelector)); | ||
|
||
emit PluginSet(_plugin.functionSelector, _plugin.functionSignature, _plugin.pluginAddress); | ||
} |
Check warning
Code scanning / Slither
Unused return
No description provided.