-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.sol
More file actions
120 lines (97 loc) · 4.21 KB
/
Copy pathcontainer.sol
File metadata and controls
120 lines (97 loc) · 4.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
pragma solidity 0.5.4;
import {Editable} from "./editable.sol";
import {BaseContent} from "./base_content.sol";
import {INodeSpace} from "./node_space.sol";
/**
* Container
* The Container contract provides the interface required for an entity to be used as a library of content objects
*/
/* -- Revision history --
Container20190528144600ML: First versioned released
Container20190529091800ML: Remove warning on hasAccess
Container20200316135300ML: Leverages inherited hasAccess
*/
contract Container is Editable {
bytes32 public version = "Container20200316135300ML"; //class name (max 16), date YYYYMMDD, time HHMMSS and Developer initials XX
address public addressKMS;
address payable[] public contentTypes;
uint256 public contentTypesLength = 0;
mapping ( address => address payable ) public contentTypeContracts; // custom contracts map
event ContentTypeAdded(address contentType, address contentContract);
event ContentTypeRemoved(address contentType);
function setAddressKMS(address address_KMS) public onlyOwner {
addressKMS = address_KMS;
}
function addContentType(address payable content_type, address payable content_contract) public onlyOwner {
if ((contentTypeContracts[content_type] == address(0x0)) && (whitelistedType(content_type) == false)) {
if (contentTypesLength < contentTypes.length) {
contentTypes[contentTypesLength] = content_type;
} else {
contentTypes.push(content_type);
}
contentTypesLength = contentTypesLength + 1;
}
contentTypeContracts[content_type] = content_contract;
emit ContentTypeAdded(content_type, content_contract);
}
function removeContentType(address content_type) public onlyOwner returns (bool) {
uint256 latestIndex = contentTypesLength - 1;
for (uint256 i = 0; i < contentTypesLength; i++) {
if (contentTypes[i] == content_type) {
delete contentTypes[i];
if (i != latestIndex) {
contentTypes[i] = contentTypes[latestIndex];
delete contentTypes[latestIndex];
}
contentTypesLength = latestIndex; //decrease by 1
delete contentTypeContracts[content_type];
emit ContentTypeRemoved(content_type);
return true;
}
}
return false;
}
function validType(address content_type) public view returns (bool) {
if (contentTypesLength == 0){
return true;
}
return whitelistedType(content_type);
}
function whitelistedType(address content_type) public view returns (bool) {
bool isValidType = false;
for (uint i = 0; i < contentTypesLength; i++) {
if (contentTypes[i] == content_type) {
isValidType = true;
}
}
return isValidType;
}
function findTypeByHash(bytes32 typeHash) public view returns (address) {
for (uint i = 0; i < contentTypes.length; i++) {
Editable contentType = Editable(contentTypes[i]);
if (keccak256(abi.encodePacked(contentType.objectHash())) == keccak256(abi.encodePacked(typeHash))) {
return contentTypes[i];
}
}
return address(0x0);
}
function requiresReview() public view returns (bool) {
return false;
}
// Current implementation ignores rights provided directly to individual
function canContribute(address payable _candidate) public view returns (bool) {
return ((_candidate == owner) || (msg.sender == owner)); //not sure about the ||
}
function canPublish(address payable _candidate) public view returns (bool) {
return ((_candidate == owner) || (msg.sender == owner)); //not sure about the ||
}
function canReview(address /*_candidate*/) public view returns (bool) {
return false;
}
function publish(address payable contentObj) public returns (bool) {
require(msg.sender == contentObj);
BaseContent content = BaseContent(contentObj);
content.updateStatus(0); //update status to published
return (content.statusCode() == 0);
}
}