-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_tenant_consumer_group.sol
68 lines (52 loc) · 1.95 KB
/
base_tenant_consumer_group.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pragma solidity 0.5.4;
import {Editable} from "./editable.sol";
import {MetaObject, CounterObject} from "./meta_object.sol";
import {BaseTenantSpace} from "./base_tenant_space.sol";
contract BaseTenantConsumerGroup is MetaObject, CounterObject, Editable {
bytes32 public version ="BsTenantConsGrp20210809150000PO";
mapping(address => bool) public membersMap;
uint256 public membersNum;
event MemberAdded(address candidate);
event MemberRevoked(address candidate);
bool public isConsumerGroup;
address payable public tenant;
constructor(address payable _tenantSpace) public {
tenant = _tenantSpace;
isConsumerGroup = true;
membersNum = 0;
}
function isAdmin(address payable _candidate) public view returns (bool) {
if (_candidate == owner || _candidate == tenant) {
return true;
}
return BaseTenantSpace(tenant).isAdmin(_candidate);
}
function hasAccess(address candidate) public view returns (bool) {
return membersMap[candidate];
}
function grantAccessInternal(address payable candidate) private {
if (!membersMap[candidate]) {
membersMap[candidate] = true;
membersNum++;
}
emit MemberAdded(candidate);
}
function grantAccessMany(address payable[] memory candidates) public {
require(isAdmin(msg.sender));
for (uint i = 0; i < candidates.length; i++) {
grantAccessInternal(candidates[i]);
}
}
function grantAccess(address payable candidate) public {
require(isAdmin(msg.sender) || (msg.sender == candidate));
grantAccessInternal(candidate);
}
function revokeAccess(address payable candidate) public {
require(isAdmin(msg.sender) || (msg.sender == candidate));
if (membersMap[candidate]) {
delete membersMap[candidate];
membersNum--;
}
emit MemberRevoked(candidate);
}
}