-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesignDepartment.sol
65 lines (54 loc) · 1.87 KB
/
DesignDepartment.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
pragma solidity ^0.4.18;
import './Directed.sol';
contract DesignDepartment is Directed {
event DesignerHired(address _designer, address by);
event DesignerFired(address _designer, address by);
struct Designer {
uint256 index;
bool isDesigner;
}
mapping (address => Designer) public designers;
address[] public designerIndex;
modifier isUniqueDesigner(address _designer) {
require(!designers[_designer].isDesigner);
_;
}
modifier isDesigner(address _designer) {
require(designers[_designer].isDesigner);
_;
}
modifier onlyAuthorized() {
require(
msg.sender == owner ||
msg.sender == director ||
designers[msg.sender].isDesigner
);
_;
}
function addDesigner(address _designer) onlyDirector isUniqueDesigner(_designer) public returns(bool) {
Designer memory newDesigner;
newDesigner.index = designerCount();
newDesigner.isDesigner = true;
designers[_designer] = newDesigner;
designerIndex.push(_designer);
emit DesignerHired(_designer, msg.sender);
return true;
}
function removeDesigner(address _designer) onlyDirector isDesigner(_designer) public returns(bool) {
if (designerCount() > 1) {
uint256 rowToDelete = designers[_designer].index;
address keyToMove = designerIndex[designerCount() - 1];
designerIndex[rowToDelete] = keyToMove;
designers[keyToMove].index = rowToDelete;
}
designerIndex.length--;
emit DesignerFired(_designer, msg.sender);
return true;
}
function designerCount() view public returns(uint256) {
return designerIndex.length;
}
function designerExists(address _designer) isDesigner(_designer) view public returns(bool) {
return true;
}
}