Improve encapsulation on SignatureBouncer, Whitelist and RBAC example (#1265)

* Improve encapsulation on Whitelist

* remove only

* update whitelisted crowdsale test

* Improve encapsulation on SignatureBouncer

* fix missing test

* Improve encapsulation on RBAC example

* Improve encapsulation on RBAC example

* Remove extra visibility

* Improve encapsulation on ERC20 Mintable

* Improve encapsulation on Superuser

* fix lint

* add missing constant
This commit is contained in:
Leo Arias
2018-09-03 16:06:43 -06:00
committed by Francisco Giordano
parent b0f20d43df
commit f4eb51a7e9
11 changed files with 58 additions and 53 deletions

View File

@ -32,10 +32,13 @@ import "../cryptography/ECDSA.sol";
contract SignatureBouncer is Ownable, RBAC {
using ECDSA for bytes32;
string public constant ROLE_BOUNCER = "bouncer";
uint internal constant METHOD_ID_SIZE = 4;
// signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint internal constant SIGNATURE_SIZE = 96;
// Name of the bouncer role.
string private constant ROLE_BOUNCER = "bouncer";
// Function selectors are 4 bytes long, as documented in
// https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector
uint256 private constant METHOD_ID_SIZE = 4;
// Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint256 private constant SIGNATURE_SIZE = 96;
/**
* @dev requires that a valid signature of a bouncer was provided
@ -64,6 +67,14 @@ contract SignatureBouncer is Ownable, RBAC {
_;
}
/**
* @dev Determine if an account has the bouncer role.
* @return true if the account is a bouncer, false otherwise.
*/
function isBouncer(address _account) public view returns(bool) {
return hasRole(_account, ROLE_BOUNCER);
}
/**
* @dev allows the owner to add additional bouncer addresses
*/
@ -153,6 +164,6 @@ contract SignatureBouncer is Ownable, RBAC {
address signer = _hash
.toEthSignedMessageHash()
.recover(_signature);
return hasRole(signer, ROLE_BOUNCER);
return isBouncer(signer);
}
}

View File

@ -11,7 +11,9 @@ import "../access/rbac/RBAC.sol";
* This simplifies the implementation of "user permissions".
*/
contract Whitelist is Ownable, RBAC {
string public constant ROLE_WHITELISTED = "whitelist";
// Name of the whitelisted role.
string private constant ROLE_WHITELISTED = "whitelist";
/**
* @dev Throws if operator is not whitelisted.
@ -35,9 +37,10 @@ contract Whitelist is Ownable, RBAC {
}
/**
* @dev getter to determine if address is in whitelist
* @dev Determine if an account is whitelisted.
* @return true if the account is whitelisted, false otherwise.
*/
function whitelist(address _operator)
function isWhitelisted(address _operator)
public
view
returns (bool)