-
Notifications
You must be signed in to change notification settings - Fork 8
/
community.hpp
343 lines (276 loc) · 12.1 KB
/
community.hpp
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
#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>
#include <eosio/singleton.hpp>
#define TOSTR_(T) #T
#define TOSTR(T) TOSTR_(T)
enum permission
{
invite,
claim,
order,
verify,
sell,
award,
transfer
};
class [[eosio::contract("community")]] cambiatus : public eosio::contract
{
public:
using contract::contract;
TABLE community
{
eosio::symbol symbol;
eosio::name creator;
std::string logo;
std::string name;
std::string description;
eosio::asset inviter_reward;
eosio::asset invited_reward;
std::uint8_t has_objectives;
std::uint8_t has_shop;
std::uint8_t has_kyc;
uint64_t primary_key() const { return symbol.raw(); };
EOSLIB_SERIALIZE(community,
(symbol)(creator)(logo)(name)(description)(inviter_reward)(invited_reward)(has_objectives)(has_shop)(has_kyc));
};
TABLE network
{
std::uint64_t id;
eosio::symbol community;
eosio::name invited_user;
eosio::name invited_by;
std::string user_type;
// keys and indexes
std::uint64_t primary_key() const { return id; }
std::uint64_t users_by_cmm() const { return community.raw(); }
EOSLIB_SERIALIZE(network,
(id)(community)(invited_user)(invited_by)(user_type));
};
TABLE member
{
eosio::name name;
eosio::name inviter;
std::string user_type;
std::vector<eosio::name> roles;
std::uint64_t primary_key() const { return name.value; }
EOSLIB_SERIALIZE(member,
(name)(inviter)(user_type)(roles));
};
/**
* Roles is a way to identify people's relation with their community.
* It can be used to allow people to be recognized by their role in the whole of the community, to give them awards or to help them to identify themselves.
* They can be customized with a color and can have a name
*
* Roles can also be atttached with permissions that gives them abilities within the community such as the ability to invite new people in, to sell goods and services and more
*
* The initial abilities that we offer are:
* invite: invite new users `netlink`
* claim: allow claiming actions `claimaction`
* order: create new orders `transfersale`
* verify: verify autenticity on claims `verifyclaim`
* sell: sell items on the shop `createsale` `updatesale` .
* award: awards an action `verifyaction` (`award`)
*
* All of those roles are used from within the contract to mediate the usage of some actions.
*
*
* Roles are scoped by community.
*/
TABLE role
{
eosio::name name;
std::vector<std::string> permissions;
std::uint64_t primary_key() const { return name.value; }
EOSLIB_SERIALIZE(role, (name)(permissions));
};
TABLE objective
{
std::uint64_t id;
std::string description;
eosio::symbol community;
eosio::name creator;
// keys and indexes
std::uint64_t primary_key() const { return id; }
std::uint64_t by_cmm() const { return community.raw(); }
EOSLIB_SERIALIZE(objective,
(id)(description)(community)(creator));
};
TABLE action
{
std::uint64_t id;
std::uint64_t objective_id;
std::string description;
eosio::asset reward;
eosio::asset verifier_reward;
std::uint64_t deadline; // Max date where it can be claimed
std::uint64_t usages; // Max usages
std::uint64_t usages_left;
std::uint64_t verifications; // # verifications needed
std::string verification_type; // Can be 'automatic' and 'claimable'
std::uint8_t is_completed;
eosio::name creator;
std::uint8_t has_proof_photo;
std::uint8_t has_proof_code;
std::string photo_proof_instructions;
// std::vector<eosio::name> roles; // Validators of the action
std::uint64_t primary_key() const { return id; }
std::uint64_t by_objective() const { return objective_id; }
EOSLIB_SERIALIZE(action,
(id)(objective_id)(description)(reward)(verifier_reward)(deadline)(usages)(usages_left)(verifications)(verification_type)(is_completed)(creator)(has_proof_photo)(has_proof_code)(photo_proof_instructions));
};
TABLE action_validator
{
std::uint64_t id;
std::uint64_t action_id;
eosio::name validator;
std::uint64_t primary_key() const { return id; }
std::uint64_t by_action() const { return action_id; }
EOSLIB_SERIALIZE(action_validator,
(id)(action_id)(validator));
};
TABLE claim
{
std::uint64_t id;
std::uint64_t action_id;
eosio::name claimer;
std::string status; // Can be: `approved` `rejected` `pending`
std::string proof_photo;
std::string proof_code;
std::uint64_t primary_key() const { return id; }
std::uint64_t by_action() const { return action_id; }
EOSLIB_SERIALIZE(claim,
(id)(action_id)(claimer)(status)(proof_photo)(proof_code));
};
TABLE check
{
std::uint64_t id;
std::uint64_t claim_id;
eosio::name validator;
std::uint8_t is_verified; // Answer the verificator gave
std::uint64_t primary_key() const { return id; }
std::uint64_t by_claim() const { return claim_id; }
EOSLIB_SERIALIZE(check,
(id)(claim_id)(validator)(is_verified));
};
TABLE indexes
{
std::uint64_t last_used_sale_id;
std::uint64_t last_used_objective_id;
std::uint64_t last_used_action_id;
std::uint64_t last_used_claim_id;
};
/// @abi action
/// Creates a cambiatus community
ACTION create(eosio::asset cmm_asset, eosio::name creator, std::string logo, std::string name,
std::string description, eosio::asset inviter_reward, eosio::asset invited_reward,
std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
std::uint8_t auto_invite, std::string subdomain, std::string website);
/// @abi action
/// Updates community attributes
ACTION update(eosio::asset cmm_asset, std::string logo, std::string name,
std::string description, eosio::asset inviter_reward, eosio::asset invited_reward,
std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
std::uint8_t auto_invite, std::string subdomain, std::string website);
/// @abi action
/// Adds a user to a community
ACTION netlink(eosio::symbol community_id, eosio::name inviter, eosio::name new_user, std::string user_type);
/// @abi action
/// Create/Edit a given objective
ACTION upsertobjctv(eosio::symbol community_id, std::uint64_t objective_id, std::string description, eosio::name editor);
/// @abi action
/// Update action
ACTION upsertaction(eosio::symbol community_id, std::uint64_t action_id, std::uint64_t objective_id,
std::string description, eosio::asset reward,
eosio::asset verifier_reward, std::uint64_t deadline,
std::uint64_t usages, std::uint64_t usages_left,
std::uint64_t verifications, std::string verification_type,
std::string validators_str, std::uint8_t is_completed,
eosio::name creator,
std::uint8_t has_proof_photo, std::uint8_t has_proof_code,
std::string photo_proof_instructions, std::string image);
/// @abi action
/// Start a new claim on an action
ACTION claimaction(eosio::symbol community_id, std::uint64_t action_id, eosio::name maker,
std::string proof_photo, std::string proof_code, uint32_t proof_time);
/// @abi action
/// Send a vote verification for a given claim. It has to be `claimable` verification_type
ACTION verifyclaim(eosio::symbol community_id, std::uint64_t claim_id, eosio::name verifier, std::uint8_t vote);
/// @abi action
/// Verify that a given action was completed. It has to have the `automatic` verification_type
ACTION reward(eosio::symbol community_id, std::uint64_t action_id, eosio::name receiver, eosio::name awarder);
/// @abi action
/// Offchain event hook for when a transfer occours in our shop
ACTION transfersale(std::uint64_t sale_id, eosio::name from, eosio::name to, eosio::asset quantity, std::uint64_t units);
/// @abi action
/// Upserts roles in a community
ACTION upsertrole(eosio::symbol community_id, eosio::name name, std::string color, std::vector<std::string> & permissions);
/// @abi action
/// Sets a number of roles for an user
ACTION assignroles(eosio::symbol community_id, eosio::name member, std::vector<eosio::name> & roles);
/// @abi action
/// Set the indices for a chain
ACTION setindices(std::uint64_t sale_id, std::uint64_t objective_id, std::uint64_t action_id, std::uint64_t claim_id);
/// @abi action
/// Deletes an objective
ACTION deleteobj(std::uint64_t id);
/// @abi action
/// Deletes an action
ACTION deleteact(std::uint64_t id);
ACTION clean(std::string t, eosio::name name_scope, eosio::symbol symbol_scope);
// Get available key
uint64_t get_available_id(std::string table);
// Convinience methods
bool is_member(eosio::symbol community_id, eosio::name user);
bool has_permission(eosio::symbol community_id, eosio::name user, permission e_permission);
std::string permission_to_string(permission e_permission);
typedef eosio::multi_index<eosio::name{"community"}, cambiatus::community> communities;
typedef eosio::multi_index<eosio::name{"member"}, cambiatus::member> members;
typedef eosio::multi_index<eosio::name{"network"},
cambiatus::network,
eosio::indexed_by<eosio::name{"usersbycmm"},
eosio::const_mem_fun<cambiatus::network, uint64_t, &cambiatus::network::users_by_cmm> > >
networks;
typedef eosio::multi_index<eosio::name{"objective"},
cambiatus::objective,
eosio::indexed_by<eosio::name{"bycmm"},
eosio::const_mem_fun<cambiatus::objective, uint64_t, &cambiatus::objective::by_cmm> > >
objectives;
typedef eosio::multi_index<eosio::name{"action"},
cambiatus::action,
eosio::indexed_by<eosio::name{"byobj"},
eosio::const_mem_fun<cambiatus::action, uint64_t, &cambiatus::action::by_objective> > >
actions;
typedef eosio::multi_index<eosio::name{"validator"},
cambiatus::action_validator,
eosio::indexed_by<eosio::name{"byaction"},
eosio::const_mem_fun<cambiatus::action_validator, uint64_t, &cambiatus::action_validator::by_action> > >
validators;
typedef eosio::multi_index<eosio::name{"claim"},
cambiatus::claim,
eosio::indexed_by<eosio::name{"byaction"}, eosio::const_mem_fun<cambiatus::claim, uint64_t, &cambiatus::claim::by_action> > >
claims;
typedef eosio::multi_index<eosio::name{"check"},
cambiatus::check,
eosio::indexed_by<eosio::name{"byclaim"},
eosio::const_mem_fun<cambiatus::check, uint64_t, &cambiatus::check::by_claim> > >
checks;
typedef eosio::multi_index<eosio::name{"role"}, cambiatus::role> roles;
typedef eosio::singleton<eosio::name{"indexes"}, cambiatus::indexes> item_indexes;
item_indexes curr_indexes;
// Initialize our singleton table for indices
cambiatus(eosio::name receiver, eosio::name code, eosio::datastream<const char *> ds) : contract(receiver, code, ds), curr_indexes(_self, _self.value) {}
};
const auto currency_account = eosio::name{TOSTR(__TOKEN_ACCOUNT__)};
const auto backend_account = eosio::name{TOSTR(__BACKEND_ACCOUNT__)};
const uint32_t proof_expiration_secs = __PROOF_EXPIRATION_SECS__;
// Add global reference for a table from the token contract
struct currency_stats
{
eosio::asset supply;
eosio::asset max_supply;
eosio::asset min_balance;
eosio::name issuer;
std::string type;
uint64_t primary_key() const { return supply.symbol.code().raw(); }
};
typedef eosio::multi_index<eosio::name{"stat"}, currency_stats> cambiatus_tokens;