-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdaclifyhub.cpp
More file actions
348 lines (278 loc) · 11.1 KB
/
daclifyhub.cpp
File metadata and controls
348 lines (278 loc) · 11.1 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include <daclifyhub.hpp>
#include <functions.cpp>
#include <deposits.cpp>
#include <components.cpp>
ACTION daclifyhub::setgrpstate(name groupname, uint8_t newstate){
require_auth(get_self() );
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != newstate, "Group already in this state.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.state = newstate;
});
}
ACTION daclifyhub::setsettings(settings new_settings, bool remove){
require_auth(get_self());
settings_table _settings(get_self(), get_self().value);
if(remove){
_settings.remove();
return;
}
_settings.set(new_settings, get_self());
}
ACTION daclifyhub::versioning(name modulename, checksum256 codehash, checksum256 abihash, string json_src, string info, uint64_t update_key){
require_auth(get_self() );
checksum256 test;
check(modulename.value, "Must specify a modulename");
versions_table _versions(get_self(), modulename.value);
if(update_key){
auto existing_version = _versions.find(update_key);
check(existing_version != _versions.end(), "Version with this key doesn't exist, can't update.");
if(codehash==test && abihash==test && json_src.empty() && info.empty() ){
_versions.erase(existing_version);
return;
}
_versions.modify( existing_version, same_payer, [&]( auto& v) {
v.codehash = codehash == test ? v.codehash : codehash;
v.abihash = abihash == test ? v.abihash : abihash;
v.json_src = json_src.empty() ? v.json_src : json_src;
v.info = info.empty() ? v.info : info;
});
return;
}
check(codehash != test && abihash != test && !json_src.empty(), "codehash, abihash and json_src required.");
uint64_t id = _versions.available_primary_key()==0 ? 1 : _versions.available_primary_key();
_versions.emplace(get_self(), [&](auto& v) {
v.version = id;
v.codehash = codehash;
v.abihash = codehash;
v.json_src = json_src;
v.info = info;
});
}
ACTION daclifyhub::versionstate(name modulename, uint64_t version, uint8_t status ){
require_auth(get_self() );
check(modulename.value, "Must specify a modulename.");
versions_table _versions(get_self(), modulename.value);
auto itr = _versions.find(version);
check(itr != _versions.end(), "Version doesn't exists.");
_versions.modify( itr, same_payer, [&]( auto& v) {
v.status = status;
});
}
ACTION daclifyhub::creategroup(name groupname, name creator, asset resource_estimation) {
require_auth(creator);
check(!is_account(groupname), "The chosen accountname is already taken.");
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr == _groups.end(), "group already registered as a group.");
// Create record if it does not exist
_groups.emplace(creator, [&](auto& group) {
group.groupname = groupname;
group.creator = creator;
});
create_group_account(groupname, creator, resource_estimation);
}
ACTION daclifyhub::linkgroup(name groupname, name creator, groupmeta meta, uiconf ui, uint8_t state, vector<name> tags, uint64_t claps, time_point_sec creation_date) {
require_auth(get_self() );
check(is_account(groupname), "The group account doesn't exist.");
check(is_account(creator), "The creator account doesn't exist.");
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr == _groups.end(), "Account already registered as a group.");
// Create record if it does not exist
_groups.emplace(get_self(), [&](auto& group) {
group.groupname = groupname;
group.creator = creator;
group.meta = meta;
group.ui = ui;
group.state = state;
group.tags = tags;
group.claps = claps;
group.creation_date = creation_date;
});
}
ACTION daclifyhub::activate(name groupname, name creator) {
require_auth(creator);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->creator == creator, "Only the group creator can activate.");
check(group_itr->state == 0, "Group already activated.");
_groups.modify( group_itr, same_payer, [&]( auto& a) {
a.state = 1;
});
action(
permission_level{ groupname, "owner"_n },
groupname,
"invitecust"_n,
std::make_tuple(creator)
).send();
}
ACTION daclifyhub::updateabout(name groupname, string about){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.meta.about = about;
});
}
ACTION daclifyhub::updatetitle(name groupname, string title){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.meta.title = title;
});
}
ACTION daclifyhub::updatelinks(name groupname, vector <link> newlinks){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.meta.links = newlinks;
});
}
ACTION daclifyhub::updatelogo(name groupname, string logo){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.ui.logo = logo;
});
}
ACTION daclifyhub::updatecolor(name groupname, string hexcolor){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.ui.hexcolor = hexcolor;
});
}
ACTION daclifyhub::setcustomui(name groupname, string url){
require_auth(groupname);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
if(!url.empty() ){
check(url.rfind("https://", 0) == 0, "Url must be https://");
}
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.ui.custom_ui_url = url;
});
}
ACTION daclifyhub::updatetags(name groupname, vector<name> tags){
require_auth(groupname);
check(tags.size() <= 6, "Too many tags, max 6.");
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "Group not found.");
check(group_itr->state != 0, "Group isn't active yet.");
//remove dups
tags.erase( unique( tags.begin(), tags.end() ), tags.end() );
for(name const& tag: tags) {
//validate individual tags here
check(tag.value != 0, "invalid tag name");
}
_groups.modify( group_itr, groupname, [&]( auto& a) {
a.tags = tags;
});
}
ACTION daclifyhub::messagebus(name sender_group, name event, string message, vector<name> receivers){
//pass data through the chain but doesn't store it.
//only active groups are allowed to use the message bus
require_auth(sender_group);
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(sender_group.value);
check(group_itr != _groups.end(), "Invalid sender.");
check(group_itr->state != 0, "Inactive group can't send messsages.");
}
ACTION daclifyhub::unlinkgroup(name groupname) {
//get_self is authorized to delete groups from the hub! The group will still exist though.
//however deleted groups can not be found via the ui. Direct links will still work.
check(eosio::has_auth(groupname) || eosio::has_auth(get_self()), "Not authorized to unlink the group from the hub.");
groups_table _groups(get_self(), get_self().value);
auto group_itr = _groups.find(groupname.value);
check(group_itr != _groups.end(), "group doesn't exist.");
_groups.erase(group_itr);
}
ACTION daclifyhub::clear() {
//maintenance actions
groups_table _groups(get_self(), get_self().value);
// Delete all records in table
auto itr = _groups.begin();
while (itr != _groups.end()) {
itr = _groups.erase(itr);
}
}
//notify transfer handler
void daclifyhub::on_transfer(name from, name to, asset quantity, string memo){
if(get_first_receiver() != name("eosio.token") || quantity.symbol.code() != symbol_code("EOS") ){
return;
}
if (from == get_self() || to != get_self()) {
return;
}
if ( from == name("eosio") || from == name("eosio.bpay") ||
from == name("eosio.msig") || from == name("eosio.names") ||
from == name("eosio.prods") || from == name("eosio.ram") ||
from == name("eosio.ramfee") || from == name("eosio.saving") ||
from == name("eosio.stake") || from == name("eosio.token") ||
from == name("eosio.unregd") || from == name("eosio.vpay") ||
from == name("eosio.wrap") || from == name("eosio.rex") ) {
return;
}
if(memo.substr(0, 16) == "clap for group: " ){
name potentialgroupname = memo.length() >= 17 ? name(memo.substr(16, 12 ) ) : name(0);
check(potentialgroupname != name(0), "No group name in memo");
groups_table _groups(get_self(), get_self().value);
auto itr = _groups.find(potentialgroupname.value);
check(itr != _groups.end(), "Group does not exists.");
check(itr->state != 0, "Group is not activated.");
_groups.modify( itr, same_payer, [&]( auto& n) {
n.claps += quantity.amount;
});
//add to contract balance
add_deposit(get_self(), extended_asset(quantity, get_first_receiver()) );
return;
}
add_deposit(from, extended_asset(quantity, get_first_receiver()) );
}
ACTION daclifyhub::migrategrps (uint8_t batch, uint8_t skip){
/*
require_auth(get_self() );
groups2_table _source(get_self(), get_self().value);
groups_table _destination(get_self(), get_self().value);
//groups_table _source(get_self(), get_self().value);
// groups2_table _destination(get_self(), get_self().value);
auto src_itr = _source.begin();
while (src_itr != _source.end()) {
_destination.emplace(get_self(), [&](auto& g) {
g.groupname= src_itr->groupname;
g.creator= src_itr->creator;
g.meta= src_itr->meta;
g.ui= src_itr->ui;
g.state= src_itr->state;
g.r1= src_itr->r1;
g.r2= src_itr->r2;
g.creation_date= src_itr->creation_date;
g.tags = src_itr->tags;
g.flag =src_itr->flag;
g.claps=src_itr->claps;
});
src_itr = _source.erase(src_itr);
}
*/
}