Skip to content

Commit 35d7039

Browse files
authored
Rename WhitelisterRole to WhitelistAdminRole. (#1589)
* Rename WhitelisterRole to WhitelistAdminRole. * Update WhitelistAdmin changelog entry.
1 parent a5b14f2 commit 35d7039

9 files changed

+88
-88
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### New features:
66
* Now targeting the 0.5.x line of Solidity compilers. For 0.4.24 support, use version 2.0 of OpenZeppelin.
7-
* `WhitelistCrowdsale`: a crowdsale where only whitelisted accounts (`WhitelistedRole`) can purchase tokens. Adding or removing accounts from the whitelist is done by whitelisters (`WhitelisterRole`). Similar to the pre-2.0 `WhitelistedCrowdsale`. ([#1525](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1525))
7+
* `WhitelistCrowdsale`: a crowdsale where only whitelisted accounts (`WhitelistedRole`) can purchase tokens. Adding or removing accounts from the whitelist is done by whitelist admins (`WhitelistAdminRole`). Similar to the pre-2.0 `WhitelistedCrowdsale`. ([#1525](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1525), [#1589](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1589))
88
* `RefundablePostDeliveryCrowdsale`: replacement for `RefundableCrowdsale` (deprecated, see below) where tokens are only granted once the crowdsale ends (if it meets its goal). ([#1543](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1543))
99
* `PausableCrowdsale`: allows for pausers (`PauserRole`) to pause token purchases. Other crowdsale operations (e.g. withdrawals and refunds, if applicable) are not affected. ([#832](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/832))
1010
* `ERC20`: `transferFrom` and `_burnFrom ` now emit `Approval` events, to represent the token's state comprehensively through events. ([#1524](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1524))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
pragma solidity ^0.5.0;
2+
3+
import "../Roles.sol";
4+
5+
/**
6+
* @title WhitelistAdminRole
7+
* @dev WhitelistAdmins are responsible for assigning and removing Whitelisted accounts.
8+
*/
9+
contract WhitelistAdminRole {
10+
using Roles for Roles.Role;
11+
12+
event WhitelistAdminAdded(address indexed account);
13+
event WhitelistAdminRemoved(address indexed account);
14+
15+
Roles.Role private _whitelistAdmins;
16+
17+
constructor () internal {
18+
_addWhitelistAdmin(msg.sender);
19+
}
20+
21+
modifier onlyWhitelistAdmin() {
22+
require(isWhitelistAdmin(msg.sender));
23+
_;
24+
}
25+
26+
function isWhitelistAdmin(address account) public view returns (bool) {
27+
return _whitelistAdmins.has(account);
28+
}
29+
30+
function addWhitelistAdmin(address account) public onlyWhitelistAdmin {
31+
_addWhitelistAdmin(account);
32+
}
33+
34+
function renounceWhitelistAdmin() public {
35+
_removeWhitelistAdmin(msg.sender);
36+
}
37+
38+
function _addWhitelistAdmin(address account) internal {
39+
_whitelistAdmins.add(account);
40+
emit WhitelistAdminAdded(account);
41+
}
42+
43+
function _removeWhitelistAdmin(address account) internal {
44+
_whitelistAdmins.remove(account);
45+
emit WhitelistAdminRemoved(account);
46+
}
47+
}

contracts/access/roles/WhitelistedRole.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
pragma solidity ^0.5.0;
22

33
import "../Roles.sol";
4-
import "./WhitelisterRole.sol";
4+
import "./WhitelistAdminRole.sol";
55

66
/**
77
* @title WhitelistedRole
8-
* @dev Whitelisted accounts have been approved by a Whitelister to perform certain actions (e.g. participate in a
9-
* crowdsale). This role is special in that the only accounts that can add it are Whitelisters (who can also remove it),
10-
* and not Whitelisteds themselves.
8+
* @dev Whitelisted accounts have been approved by a WhitelistAdmin to perform certain actions (e.g. participate in a
9+
* crowdsale). This role is special in that the only accounts that can add it are WhitelistAdmins (who can also remove
10+
* it), and not Whitelisteds themselves.
1111
*/
12-
contract WhitelistedRole is WhitelisterRole {
12+
contract WhitelistedRole is WhitelistAdminRole {
1313
using Roles for Roles.Role;
1414

1515
event WhitelistedAdded(address indexed account);
@@ -26,11 +26,11 @@ contract WhitelistedRole is WhitelisterRole {
2626
return _whitelisteds.has(account);
2727
}
2828

29-
function addWhitelisted(address account) public onlyWhitelister {
29+
function addWhitelisted(address account) public onlyWhitelistAdmin {
3030
_addWhitelisted(account);
3131
}
3232

33-
function removeWhitelisted(address account) public onlyWhitelister {
33+
function removeWhitelisted(address account) public onlyWhitelistAdmin {
3434
_removeWhitelisted(account);
3535
}
3636

contracts/access/roles/WhitelisterRole.sol

-47
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.0;
2+
3+
import "../access/roles/WhitelistAdminRole.sol";
4+
5+
contract WhitelistAdminRoleMock is WhitelistAdminRole {
6+
function removeWhitelistAdmin(address account) public {
7+
_removeWhitelistAdmin(account);
8+
}
9+
10+
function onlyWhitelistAdminMock() public view onlyWhitelistAdmin {
11+
}
12+
13+
// Causes a compilation error if super._removeWhitelistAdmin is not internal
14+
function _removeWhitelistAdmin(address account) internal {
15+
super._removeWhitelistAdmin(account);
16+
}
17+
}

contracts/mocks/WhitelisterRoleMock.sol

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
2+
const WhitelistAdminRoleMock = artifacts.require('WhitelistAdminRoleMock');
3+
4+
contract('WhitelistAdminRole', function ([_, whitelistAdmin, otherWhitelistAdmin, ...otherAccounts]) {
5+
beforeEach(async function () {
6+
this.contract = await WhitelistAdminRoleMock.new({ from: whitelistAdmin });
7+
await this.contract.addWhitelistAdmin(otherWhitelistAdmin, { from: whitelistAdmin });
8+
});
9+
10+
shouldBehaveLikePublicRole(whitelistAdmin, otherWhitelistAdmin, otherAccounts, 'whitelistAdmin');
11+
});
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
22
const WhitelistedRoleMock = artifacts.require('WhitelistedRoleMock');
33

4-
contract('WhitelistedRole', function ([_, whitelisted, otherWhitelisted, whitelister, ...otherAccounts]) {
4+
contract('WhitelistedRole', function ([_, whitelisted, otherWhitelisted, whitelistAdmin, ...otherAccounts]) {
55
beforeEach(async function () {
6-
this.contract = await WhitelistedRoleMock.new({ from: whitelister });
7-
await this.contract.addWhitelisted(whitelisted, { from: whitelister });
8-
await this.contract.addWhitelisted(otherWhitelisted, { from: whitelister });
6+
this.contract = await WhitelistedRoleMock.new({ from: whitelistAdmin });
7+
await this.contract.addWhitelisted(whitelisted, { from: whitelistAdmin });
8+
await this.contract.addWhitelisted(otherWhitelisted, { from: whitelistAdmin });
99
});
1010

11-
shouldBehaveLikePublicRole(whitelisted, otherWhitelisted, otherAccounts, 'whitelisted', whitelister);
11+
shouldBehaveLikePublicRole(whitelisted, otherWhitelisted, otherAccounts, 'whitelisted', whitelistAdmin);
1212
});

test/access/roles/WhitelisterRole.test.js

-11
This file was deleted.

0 commit comments

Comments
 (0)