-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpublisher.sol
More file actions
253 lines (240 loc) · 12.7 KB
/
publisher.sol
File metadata and controls
253 lines (240 loc) · 12.7 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
publisher.sol
1.0.0
Rajci 'iFA' Andor @ ifa@corion.io / ifa@ethereumlottery.net
CORION Platform
*/
pragma solidity ^0.4.15;
import "./announcementTypes.sol";
import "./module.sol";
import "./moduleHandler.sol";
import "./safeMath.sol";
import "./multiOwner.sol";
contract publisher is announcementTypes, module, safeMath, moduleMultiOwner {
/* module callbacks */
function transferEvent(address from, address to, uint256 value) external onlyForModuleHandler returns (bool success) {
/*
Transaction completed. This function is available only for moduleHandler
If a transaction is carried out from or to an address which participated in the objection of an announcement, its objection purport is automatically set
*/
uint256 announcementID;
uint256 a;
// need reverse lookup
for ( a=0 ; a<opponents[from].length ; a++ ) {
announcementID = opponents[from][a];
if ( announcements[announcementID].end < block.number && announcements[announcementID].open ) {
announcements[announcementID].oppositionWeight = safeSub(announcements[announcementID].oppositionWeight, value);
}
}
for ( a=0 ; a<opponents[to].length ; a++ ) {
announcementID = opponents[to][a];
if ( announcements[announcementID].end < block.number && announcements[announcementID].open ) {
announcements[announcementID].oppositionWeight = safeAdd(announcements[announcementID].oppositionWeight, value);
}
}
super._transferEvent(from, to, value);
return true;
}
/* Structures */
struct announcements_s {
announcementType Type;
uint256 start;
uint256 end;
bool open;
string announcement;
string link;
bool oppositable;
uint256 oppositionWeight;
bool result;
string _str;
uint256 _uint;
address _addr;
}
/* Variables */
uint256 public minAnnouncementDelay = 40320;
uint8 public oppositeRate = 33;
uint256 public announcementsLength;
mapping(uint256 => announcements_s) public announcements;
mapping (address => uint256[]) public opponents;
/* Constructor */
function publisher(address moduleHandlerAddr) moduleMultiOwner(moduleHandlerAddress) module(moduleHandlerAddr) {
/*
Installation function. The installer will be registered in the admin list automatically.
@moduleHandlerAddr Address of moduleHandler
*/
}
/* Externals */
function newAnnouncement(announcementType Type, string Announcement, string Link, bool Oppositable,
string _str, uint256 _uint, address _addr) external {
/*
New announcement. Can be called only by those in the admin list
@Type Topic of announcement
@Start height of announcement block
@End planned completion of announcement
@Closed Completed or not
@Announcement Announcement text
@Link link to a Forum
@Opposition opposed or not
@_str text box
@_uint number box
@_addr address box
*/
require( block.number < moduleHandler(moduleHandlerAddress).debugModeUntil() );
if ( ! super.insertAndCheckDo(super.calcDoHash("newAnnouncement", sha3(Type, Announcement, Link, Oppositable, _str, _uint, _addr))) ) {
return;
}
announcementsLength++;
announcements[announcementsLength].Type = Type;
announcements[announcementsLength].start = block.number;
announcements[announcementsLength].end = block.number + minAnnouncementDelay;
announcements[announcementsLength].open = true;
announcements[announcementsLength].announcement = Announcement;
announcements[announcementsLength].link = Link;
announcements[announcementsLength].oppositable = Oppositable;
announcements[announcementsLength].oppositionWeight = 0;
announcements[announcementsLength].result = false;
announcements[announcementsLength]._str = _str;
announcements[announcementsLength]._uint = _uint;
announcements[announcementsLength]._addr = _addr;
ENewAnnouncement(announcementsLength, Type);
}
function closeAnnouncement(uint256 id) onlyOwner external {
/*
Close announcement. It can be closed only by those in the admin list. Windup is allowed only after the announcement is completed.
@id Announcement identification
*/
require( announcements[id].open && announcements[id].end < block.number );
if ( ! checkOpposited(announcements[id].oppositionWeight, announcements[id].oppositable) ) {
announcements[id].result = true;
if ( announcements[id].Type == announcementType.newModule ) {
require( moduleHandler(moduleHandlerAddress).newModule(announcements[id]._str, announcements[id]._addr, true, true) );
} else if ( announcements[id].Type == announcementType.dropModule ) {
require( moduleHandler(moduleHandlerAddress).dropModule(announcements[id]._str, true) );
} else if ( announcements[id].Type == announcementType.replaceModule ) {
require( moduleHandler(moduleHandlerAddress).replaceModule(announcements[id]._str, announcements[id]._addr, true) );
} else if ( announcements[id].Type == announcementType.replaceModuleHandler) {
require( moduleHandler(moduleHandlerAddress).replaceModuleHandler(announcements[id]._addr) );
} else if ( announcements[id].Type == announcementType.transactionFeeRate ||
announcements[id].Type == announcementType.transactionFeeMin ||
announcements[id].Type == announcementType.transactionFeeMax ||
announcements[id].Type == announcementType.transactionFeeBurn ) {
require( moduleHandler(moduleHandlerAddress).configureModule("token", announcements[id].Type, announcements[id]._uint, announcements[id]._addr) );
} else if ( announcements[id].Type == announcementType.providerPublicFunds ||
announcements[id].Type == announcementType.providerPrivateFunds ||
announcements[id].Type == announcementType.providerPrivateClientLimit ||
announcements[id].Type == announcementType.providerPublicMinRate ||
announcements[id].Type == announcementType.providerPublicMaxRate ||
announcements[id].Type == announcementType.providerPrivateMinRate ||
announcements[id].Type == announcementType.providerPrivateMaxRate ||
announcements[id].Type == announcementType.providerGasProtect ||
announcements[id].Type == announcementType.providerInterestMinFunds ||
announcements[id].Type == announcementType.providerRentRate ) {
require( moduleHandler(moduleHandlerAddress).configureModule("provider", announcements[id].Type, announcements[id]._uint, announcements[id]._addr) );
} else if ( announcements[id].Type == announcementType.schellingRoundBlockDelay ||
announcements[id].Type == announcementType.schellingCheckRounds ||
announcements[id].Type == announcementType.schellingCheckAboves ||
announcements[id].Type == announcementType.schellingRate ) {
require( moduleHandler(moduleHandlerAddress).configureModule("schelling", announcements[id].Type, announcements[id]._uint, announcements[id]._addr) );
} else if ( announcements[id].Type == announcementType.publisherMinAnnouncementDelay) {
minAnnouncementDelay = announcements[id]._uint;
} else if ( announcements[id].Type == announcementType.publisherOppositeRate) {
oppositeRate = uint8(announcements[id]._uint);
}
}
announcements[id].end = block.number;
announcements[id].open = false;
}
function oppositeAnnouncement(uint256 id) external {
/*
Opposition of announcement
If announcement is opposable, anyone owning a token can oppose it
Opposition is automatically with the total amount of tokens
If the quantity of his tokens changes, the purport of his opposition changes automatically
The prime time is the windup of the announcement, because this is the moment when the number of tokens in opposition are counted.
One address is entitled to be in oppositon only once. An opposition cannot be withdrawn.
Running announcements can be opposed only.
@id Announcement identification
*/
uint256 emptyArrayID = 0;
bool foundEmptyArrayID = false;
require( announcements[id].open );
require( announcements[id].oppositable );
for ( uint256 a=0 ; a<opponents[msg.sender].length ; a++ ) {
require( opponents[msg.sender][a] != id );
if ( ! announcements[opponents[msg.sender][a]].open) {
delete opponents[msg.sender][a];
if ( ! foundEmptyArrayID ) {
foundEmptyArrayID = true;
emptyArrayID = a;
}
}
}
if ( ! foundEmptyArrayID ) {
opponents[msg.sender].push(id);
} else {
opponents[msg.sender][emptyArrayID] = id;
}
var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(msg.sender);
require( _success );
require( _balance > 0);
announcements[id].oppositionWeight += _balance;
EOppositeAnnouncement(id, msg.sender, _balance);
}
function invalidateAnnouncement(uint256 id) onlyOwner external {
/*
Withdraw announcement. Only those in the admin list can withdraw it.
@id Announcement identification
*/
require( announcements[id].open );
announcements[id].end = block.number;
announcements[id].open = false;
EInvalidateAnnouncement(id);
}
/* Constants */
function Announcements(uint256 id) public constant returns (announcementType Type, uint256 Start, uint256 End,
bool Closed, string Announcement, string Link, bool Opposited, string _str, uint256 _uint, address _addr) {
/*
Announcement data query
@id Its identification
@Type Subject of announcement
@Start Height of announcement block
@End Planned completion of announcement
@Closed Closed or not
@Announcement Announcement text
@Link Link perhaps to a Forum
@Opposited Objected or not
@_str Text value
@_uint Number value
@_addr Address value
*/
Type = announcements[id].Type;
Start = announcements[id].start;
End = announcements[id].end;
Closed = ! announcements[id].open;
Announcement = announcements[id].announcement;
Link = announcements[id].link;
if ( checkOpposited(announcements[id].oppositionWeight, announcements[id].oppositable) ) {
Opposited = true;
}
_str = announcements[id]._str;
_uint = announcements[id]._uint;
_addr = announcements[id]._addr;
}
function checkOpposited(uint256 weight, bool oppositable) public constant returns (bool success) {
/*
Veto check
@weight Purport of objections so far
@oppositable Opposable at all
@success Opposed or not
*/
if ( ! oppositable ) { return false; }
var (_success, _amount) = moduleHandler(moduleHandlerAddress).totalSupply();
require( _success );
return _amount * oppositeRate / 100 > weight;
}
/* Events */
event ENewAnnouncement(uint256 id, announcementType typ);
event EOppositeAnnouncement(uint256 id, address addr, uint256 value);
event EInvalidateAnnouncement(uint256 id);
event ECloseAnnouncement(uint256 id);
}