-
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
Forced Transfer #253
Forced Transfer #253
Changes from 2 commits
940b048
d897529
86c17a8
0f5a5c7
7547477
a22ec70
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 |
---|---|---|
|
@@ -56,6 +56,11 @@ contract SecurityToken is StandardToken, DetailedERC20, ReentrancyGuard, Registr | |
// Use to permanently halt all minting | ||
bool public mintingFrozen; | ||
|
||
// addresses whitelisted by issuer as controller | ||
mapping (address => bool) public isController; | ||
mapping (address => uint256) private controllerID; | ||
address[] public controllers; | ||
|
||
struct ModuleData { | ||
bytes32 name; | ||
address moduleAddress; | ||
|
@@ -110,6 +115,10 @@ contract SecurityToken is StandardToken, DetailedERC20, ReentrancyGuard, Registr | |
event Minted(address indexed to, uint256 amount); | ||
event Burnt(address indexed _burner, uint256 _value); | ||
|
||
// Events to log controller actions | ||
event LogChangeControllerStatus(address indexed _controller, bool _status); | ||
event LogControllerTransfer(address indexed _controller, address indexed _from, address indexed _to, uint256 _amount, bytes _data); | ||
|
||
// Require msg.sender to be the specified module type | ||
modifier onlyModule(uint8 _moduleType) { | ||
bool isModuleType = false; | ||
|
@@ -145,6 +154,14 @@ contract SecurityToken is StandardToken, DetailedERC20, ReentrancyGuard, Registr | |
_; | ||
} | ||
|
||
/** | ||
* @notice Revert if called by account which is not a controller | ||
*/ | ||
modifier onlyController() { | ||
require(isController[msg.sender]); | ||
_; | ||
} | ||
|
||
/** | ||
* @notice Constructor | ||
* @param _name Name of the SecurityToken | ||
|
@@ -721,4 +738,62 @@ contract SecurityToken is StandardToken, DetailedERC20, ReentrancyGuard, Registr | |
return _getValueAt(checkpointBalances[_investor], _checkpointId, balanceOf(_investor)); | ||
} | ||
|
||
/** | ||
* @notice Use to get the list of controller addresses | ||
* @return address array containing the list of controller addresses | ||
*/ | ||
function getControllers() public view returns (address[]) { | ||
return controllers; | ||
} | ||
|
||
/** | ||
* @notice Use by the issuer ot set the status of a controller addresses | ||
* @param _controller address of the controller | ||
* @param _status bool representing new status to set | ||
*/ | ||
function setControllerStatus(address _controller, bool _status) public onlyOwner { | ||
require(isController[_controller] != _status); | ||
if (_status == true) { | ||
isController[_controller] = true; | ||
controllerID[_controller] = controllers.length; | ||
controllers.push(_controller); | ||
} else { | ||
isController[_controller] = false; | ||
uint256 i = controllerID[_controller]; | ||
address last = controllers[controllers.length - 1]; | ||
controllers[i] = last; | ||
controllerID[last] = i; | ||
|
||
delete controllers[controllers.length - 1]; | ||
delete controllerID[_controller]; | ||
controllers.length--; | ||
} | ||
emit LogChangeControllerStatus(_controller, _status); | ||
} | ||
|
||
/** | ||
* @notice Use by a controller to execute a foced transfer | ||
* @param _from address from which to take tokens | ||
* @param _to address where to send tokens | ||
* @param _value amount of tokens to transfer | ||
* @param _data data attached to the transfer by controller for event | ||
*/ | ||
function controllerTransfer(address _from, address _to, uint256 _value, bytes _data) public onlyController { | ||
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. Wouldn't this function also need to be added to the constructor? 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. Only if it calls 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. This pattern can be revisited using internal / private functions 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. Yes - if it is going to call One option here is to call 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 like the idea of adding the result to the event |
||
require(_value <= balances[_from]); | ||
require(_to != address(0)); | ||
|
||
_adjustInvestorCount(_from, _to, _value); | ||
_adjustBalanceCheckpoints(_from); | ||
_adjustBalanceCheckpoints(_to); | ||
|
||
// Consider passing setting to record change in state but not transfer check (could be a part of standard messaging module) | ||
// require(verifyTransfer(_from, _to, _value), "Transfer is not valid"); | ||
|
||
balances[_from] = balances[_from].sub(_value); | ||
balances[_to] = balances[_to].add(_value); | ||
|
||
emit LogControllerTransfer(msg.sender, _from, _to, _value, _data); | ||
emit Transfer(_from, _to, _value); | ||
pabloruiz55 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} |
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.
what's
_data
for?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.
a reason string explaining why the transfer occured which gets logged as an event