Skip to content
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

Solidity style fixes to multi-issuer contracts #243

Merged
merged 7 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions contracts/minting/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pragma solidity ^0.4.24;

import './../Ownable.sol';
import "../Ownable.sol";

/**
* @title Controller
Expand All @@ -33,11 +34,14 @@ contract Controller is Ownable {
// The controller manages a single worker address.
mapping(address => address) public controllers;

event ControllerConfigured(address indexed _controller, address indexed _worker);
event ControllerConfigured(
address indexed _controller,
address indexed _worker
);
event ControllerRemoved(address indexed _controller);

/**
* @dev ensure that the caller is the controller of a non-zero worker address
* @dev ensure that caller is the controller of a non-zero worker address
*/
modifier onlyController() {
require(controllers[msg.sender] != address(0), "The value of controller[msg.sender] must be non-zero.");
Expand All @@ -50,10 +54,18 @@ contract Controller is Ownable {
// onlyOwner functions

/**
* @dev set the controller of a particular _worker
* Argument _worker must not be 0x00, call removeController(_controller) instead.
* @dev set the controller of a particular _worker.
* Argument _worker must not be 0x00. Call removeController(_controller)
* instead to disable the controller.
*/
function configureController(address _controller, address _worker) onlyOwner public returns (bool) {
function configureController(
address _controller,
address _worker
)
public
onlyOwner
returns (bool)
{
require(_worker != address(0), "Worker must be a non-zero address.");
controllers[_controller] = _worker;
emit ControllerConfigured(_controller, _worker);
Expand All @@ -63,9 +75,15 @@ contract Controller is Ownable {
/**
* @dev disables a controller by setting its worker to address(0);
*/
function removeController(address _controller) onlyOwner public returns (bool) {
function removeController(
address _controller
)
public
onlyOwner
returns (bool)
{
controllers[_controller] = address(0);
emit ControllerRemoved(_controller);
return true;
}
}
}
16 changes: 8 additions & 8 deletions contracts/minting/MasterMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pragma solidity ^0.4.24;

import './MintController.sol';
import "./MintController.sol";

contract MasterMinter is MintController {

constructor(address _minterManager) MintController(_minterManager) public {

}
}
}
98 changes: 74 additions & 24 deletions contracts/minting/MintController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pragma solidity ^0.4.24;

import './Controller.sol';
import 'openzeppelin-solidity/contracts/math/SafeMath.sol';
import "./Controller.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

// Using an interface for managing minters so that MintController
// can be used for managing minters with different contracts.
interface MinterManagementInterface {
function isMinter(address account) external view returns (bool);
function minterAllowance(address minter) external view returns (uint256);
function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool);
function configureMinter(
address minter,
uint256 minterAllowedAmount
)
external returns (bool);
function removeMinter(address minter) external returns (bool);
}

Expand All @@ -43,21 +48,42 @@ contract MintController is Controller {

MinterManagementInterface public minterManager;

event MinterManagerSet(address indexed oldMinterManager, address indexed newMinterManager);
event MinterConfigured(address indexed msgSender, address indexed minter, uint256 allowance);
event MinterRemoved(address indexed msgSender, address indexed minter);
event MinterAllowanceIncrement(address indexed msgSender, address indexed minter, uint256 increment, uint256 newAllowance);
event MinterManagerSet(
address indexed oldMinterManager,
address indexed newMinterManager
);
event MinterConfigured(
address indexed msgSender,
address indexed minter,
uint256 allowance
);
event MinterRemoved(
address indexed msgSender,
address indexed minter
);
event MinterAllowanceIncrement(
address indexed msgSender,
address indexed minter,
uint256 increment,
uint256 newAllowance
);

constructor(address _minterManager) public {
minterManager = MinterManagementInterface(_minterManager);
minterManager = MinterManagementInterface(_minterManager);
}

// onlyOwner functions

/**
* @dev sets the minterManager
*/
function setMinterManager(address _newMinterManager) onlyOwner public returns (bool) {
function setMinterManager(
address _newMinterManager
)
public
onlyOwner
returns (bool)
{
emit MinterManagerSet(minterManager, _newMinterManager);
minterManager = MinterManagementInterface(_newMinterManager);
return true;
Expand All @@ -77,35 +103,59 @@ contract MintController is Controller {
/**
* @dev Enables the minter and sets its allowance
*/
function configureMinter(uint256 newAllowance) onlyController public returns (bool) {
function configureMinter(
uint256 newAllowance
)
public
onlyController
returns (bool)
{
address minter = controllers[msg.sender];
emit MinterConfigured(msg.sender, minter, newAllowance);
return internal_setMinterAllowance(minter, newAllowance);
}

/**
/**
* @dev Increases the minter allowance if and only if the minter is
* currently active. The controller can safely send a signed incrementMinterAllowance()
* transaction to a minter and not worry about it being used to undo a removeMinter()
* transaction.
* currently active. The controller can safely send a signed
* incrementMinterAllowance() transaction to a minter and not worry
* about it being used to undo a removeMinter() transaction.
*/
function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) {
function incrementMinterAllowance(
uint256 allowanceIncrement
)
public
onlyController
returns (bool)
{
address minter = controllers[msg.sender];
require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager.");

uint256 currentAllowance = minterManager.minterAllowance(minter);
uint256 newAllowance = currentAllowance.add(allowanceIncrement);

emit MinterAllowanceIncrement(msg.sender, minter, allowanceIncrement, newAllowance);
emit MinterAllowanceIncrement(
msg.sender,
minter,
allowanceIncrement,
newAllowance
);
return internal_setMinterAllowance(minter, newAllowance);
}

// Internal functions

/**
* @dev Uses the MinterManagementInterface to enable the minter and set its allowance.
* @dev Uses the MinterManagementInterface to enable the minter and
* set its allowance.
*/
function internal_setMinterAllowance(address minter, uint256 newAllowance) internal returns (bool) {
function internal_setMinterAllowance(
address minter,
uint256 newAllowance
)
internal
returns (bool)
{
return minterManager.configureMinter(minter, newAllowance);
}
}
}