-
Notifications
You must be signed in to change notification settings - Fork 160
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
Module Registry removeModule() function #244
Changes from 2 commits
a9a7dcd
2ca6f97
7a341fe
f694238
e74ca24
3570f49
07385c7
e852543
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ contract ModuleRegistry is IModuleRegistry, Pausable, RegistryUpdater, ReclaimTo | |
mapping (address => address[]) public reputation; | ||
// Mapping contain the list of addresses of Module factory for a particular type | ||
mapping (uint8 => address[]) public moduleList; | ||
// Mapping to store the index of the moduleFacorty in the moduleList | ||
mapping(address => uint8) public moduleListIndex; | ||
// contains the list of verified modules | ||
mapping (address => bool) public verified; | ||
// Contains the list of the available tags corresponds to the module type | ||
|
@@ -31,10 +33,16 @@ contract ModuleRegistry is IModuleRegistry, Pausable, RegistryUpdater, ReclaimTo | |
event LogModuleRegistered(address indexed _moduleFactory, address indexed _owner); | ||
// Emit when the module get verified by the Polymath team | ||
event LogModuleVerified(address indexed _moduleFactory, bool _verified); | ||
// Emit when a moduleFactory is removed by Polymath or moduleFactory owner | ||
event LogModuleRemoved(address indexed _moduleFactory, address indexed _decisionMaker); | ||
|
||
constructor (address _polymathRegistry) public | ||
RegistryUpdater(_polymathRegistry) | ||
{ | ||
moduleList[1].push(address(0x0000000000000000000000000000000000000000)); | ||
moduleList[2].push(address(0x0000000000000000000000000000000000000000)); | ||
moduleList[3].push(address(0x0000000000000000000000000000000000000000)); | ||
moduleList[4].push(address(0x0000000000000000000000000000000000000000)); | ||
} | ||
|
||
/** | ||
|
@@ -67,14 +75,47 @@ contract ModuleRegistry is IModuleRegistry, Pausable, RegistryUpdater, ReclaimTo | |
function registerModule(address _moduleFactory) external whenNotPaused returns(bool) { | ||
require(registry[_moduleFactory] == 0, "Module factory should not be pre-registered"); | ||
IModuleFactory moduleFactory = IModuleFactory(_moduleFactory); | ||
require(moduleFactory.getType() != 0, "Factory type should not equal to 0"); | ||
registry[_moduleFactory] = moduleFactory.getType(); | ||
moduleList[moduleFactory.getType()].push(_moduleFactory); | ||
uint8 kind = moduleFactory.getType(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of "kind" use "type" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type is a reserved keyword documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, moduleFactoryType or _type, don't want to be introducing different names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay fixing |
||
require(kind != 0, "Factory kind should not equal to 0"); | ||
registry[_moduleFactory] = kind; | ||
moduleListIndex[_moduleFactory] = uint8(moduleList[kind].length); | ||
moduleList[kind].push(_moduleFactory); | ||
reputation[_moduleFactory] = new address[](0); | ||
emit LogModuleRegistered (_moduleFactory, Ownable(_moduleFactory).owner()); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Called by moduleFactory owner or registry curator to delete a moduleFactory | ||
* @param _moduleFactory is the address of the module factory to be deleted | ||
* @return bool | ||
*/ | ||
function removeModule(address _moduleFactory) external whenNotPaused returns(bool) { | ||
require(registry[_moduleFactory] != 0, "Module factory should be registered"); | ||
require(msg.sender == Ownable(_moduleFactory).owner() || msg.sender == owner, | ||
"msg.sender must be moduleFactory owner or registry curator"); | ||
|
||
uint8 index = moduleListIndex[_moduleFactory]; | ||
require(index != 0, "ModuleFactory index is not valid"); | ||
uint8 kind = registry[_moduleFactory]; | ||
uint8 last = uint8(moduleList[kind].length - 1); | ||
address temp = moduleList[kind][last]; | ||
|
||
// pop from array and re-order | ||
moduleList[kind][index] = temp; | ||
moduleListIndex[temp] = index; | ||
delete moduleList[kind][last]; | ||
moduleList[kind].length--; | ||
|
||
delete registry[_moduleFactory]; | ||
delete reputation[_moduleFactory]; | ||
delete verified[_moduleFactory]; | ||
delete moduleListIndex[_moduleFactory]; | ||
|
||
emit LogModuleRemoved (_moduleFactory, msg.sender); | ||
return true; | ||
} | ||
|
||
/** | ||
* @notice Called by Polymath to verify modules for SecurityToken to use. | ||
* @notice A module can not be used by an ST unless first approved/verified by Polymath | ||
|
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.
typo => moduleFactory