COOPENOMICS  v1
Кооперативная Экономика
coops.hpp
См. документацию.
1#pragma once
9 eosio::name username;
10 bool is_voting;
11 std::string position_title;
12 eosio::name position;
13 // (CHAIRMAN, _('chairman')),
14 // (CHAIRMAN_VP, _('vpchairman')),
15 // (SECRETARY, _('secretary')),
16 // (ACCOUNTING, _('accounting')),
17 // (MEMBER, _('member')),
18 // (INVITED, _(‘invited')),
19};
20
32struct [[eosio::table, eosio::contract(SOVIET)]] boards {
33 uint64_t id;
34 eosio::name type;
35 // (soviet, _('Board of Members')), # Совет кооператива
36 // (executive, _('Executive Board')), # Правление
37 // (audit, _('Audit and Revision Board')), # Ревизионный
38 // (other, _('Other committee')), # Другая комиссия
39 std::string name;
40 std::string description;
41
42 std::vector<board_member> members;
43
44 eosio::time_point_sec created_at;
45 eosio::time_point_sec last_update;
46
47
52 uint64_t primary_key() const { return id; }
53
58 uint64_t by_type() const { return type.value; }
59
60 bool is_valid_member(eosio::name member) const {
61 for (const auto& m : members) {
62 if (m.username == member)
63 return true;
64 }
65 return false;
66 }
67
68 bool is_voting_member(eosio::name member) const {
69 for (const auto& m : members) {
70 if (m.username == member && m.is_voting == true)
71 return true;
72 }
73 return false;
74 }
75
76
77 bool is_valid_chairman(eosio::name chairman) const {
78 for (const auto& m : members) {
79 if (m.username == chairman && (m.position == "chairman"_n || m.position == "vpchairman"_n))
80 return true;
81 }
82 return false;
83 }
84
85 eosio::name get_chairman() const {
86 for (const auto& m : members) {
87 if (m.position == "chairman"_n)
88 return m.username;
89 }
90 return ""_n;
91 };
92
93 bool is_valid_secretary(eosio::name secretary) const {
94 for (const auto& m : members) {
95 if (m.username == secretary && (m.position == "secretary"_n))
96 return true;
97 }
98 return false;
99 }
100
101 bool has_voting_right(eosio::name member) const {
102 for (const auto& m : members) {
103 if (m.username == member && m.is_voting)
104 return true;
105 }
106 return false;
107 }
108
109
110 uint64_t get_members_count() const {
111 return members.size();
112 };
113
114};
115
116typedef eosio::multi_index< "boards"_n, boards,
117eosio::indexed_by<"bytype"_n, eosio::const_mem_fun<boards, uint64_t,
119
120
126struct right {
127 eosio::name contract;
128 eosio::name action_name;
129};
130
147struct [[eosio::table, eosio::contract(SOVIET)]] staff {
148 eosio::name username;
149 std::string position_title;
150 std::vector<eosio::name> roles;
151 std::vector<right> rights;
152 eosio::time_point_sec created_at;
153 eosio::time_point_sec updated_at;
154
155 uint64_t primary_key() const { return username.value; }
156
157 bool has_right(eosio::name contract, eosio::name action_name) const {
158 for (const auto& r : rights) {
159 if (r.contract == contract && r.action_name == action_name) {
160 return true;
161 }
162 }
163 return false;
164 }
165};
166
167typedef eosio::multi_index<"staff"_n, staff> staff_index;
168
169
181struct [[eosio::table, eosio::contract(SOVIET)]] participant {
182 eosio::name username;
183 eosio::time_point_sec created_at;
184 eosio::time_point_sec last_update;
185 eosio::time_point_sec last_min_pay;
186
187 eosio::name status; //accepted | blocked
188
189 bool is_initial = true;
190 bool is_minimum = true;
191 bool has_vote = true;
192
193 eosio::binary_extension<eosio::name> type;
194 eosio::binary_extension<eosio::name> braname;
195
196 eosio::binary_extension<eosio::asset> initial_amount;
197 eosio::binary_extension<eosio::asset> minimum_amount;
198
203 uint64_t primary_key() const {
204 return username.value;
205 }
211 uint64_t bylastpay() const {
212 return last_min_pay.sec_since_epoch();
213 }
214
219 uint64_t by_created_at() const {
220 return created_at.sec_since_epoch();
221 }
222
223 bool is_active() const {
224 return status == "accepted"_n;
225 }
226
227 uint64_t by_braname() const {
228 return braname.has_value() ? braname -> value : 0; // Проверка на наличие значения
229 }
230
231};
232
233typedef eosio::multi_index< "participants"_n, participant,
234 eosio::indexed_by<"bylastpay"_n, eosio::const_mem_fun<participant, uint64_t, &participant::bylastpay>>,
235 eosio::indexed_by<"createdat"_n, eosio::const_mem_fun<participant, uint64_t, &participant::by_created_at>>,
236 eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun<participant, uint64_t, &participant::by_braname>>
238
239
251struct [[eosio::table, eosio::contract(SOVIET)]] decision {
252 uint64_t id;
253 eosio::name coopname;
254 eosio::name username;
255
256 eosio::name type;
257 uint64_t batch_id;
259
260 std::vector<eosio::name> votes_for;
261 std::vector<eosio::name> votes_against;
262
263 bool validated = false;
264 bool approved = false;
265 bool authorized = false;
266 eosio::name authorized_by;
268
269 eosio::time_point_sec created_at;
270
271 eosio::binary_extension<eosio::time_point_sec> expired_at;
272 eosio::binary_extension<std::string> meta;
273
274 eosio::binary_extension<name> callback_contract;
275 eosio::binary_extension<name> confirm_callback;
276 eosio::binary_extension<name> decline_callback;
277 eosio::binary_extension<checksum256> hash;
278
283 uint64_t primary_key() const { return id; }
284
289 uint64_t by_secondary() const { return batch_id; }
290
295 uint64_t bytype() const { return type.value; }
296
301 uint64_t byapproved() const { return approved; }
302
307 uint64_t byvalidated() const { return validated; }
308
313 uint64_t byauthorized() const { return authorized; }
314
315
316 checksum256 byhash() const { return hash.value(); }
317
318
319 void check_for_any_vote_exist(eosio::name member) const {
320 // Проверяем, есть ли имя участника в голосах за
321 eosio::check(std::find(votes_for.begin(), votes_for.end(), member) == votes_for.end(), "Участник уже голосовал за данное решение.");
322
323 // Проверяем, есть ли имя участника в голосах против
324 eosio::check(std::find(votes_against.begin(), votes_against.end(), member) == votes_against.end(), "Участник уже голосовал против данного решения.");
325 };
326
327 std::pair<uint64_t, uint64_t> get_votes_count() const {
328 return std::make_pair(votes_for.size(), votes_against.size());
329 };
330};
331
332
333typedef eosio::multi_index< "decisions"_n, decision,
334 eosio::indexed_by<"bysecondary"_n, eosio::const_mem_fun<decision, uint64_t, &decision::by_secondary>>,
335 eosio::indexed_by<"bytype"_n, eosio::const_mem_fun<decision, uint64_t, &decision::bytype>>,
336 eosio::indexed_by<"byapproved"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byapproved>>,
337 eosio::indexed_by<"byvalidated"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byvalidated>>,
338 eosio::indexed_by<"byauthorized"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byauthorized>>,
339 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<decision, checksum256, &decision::byhash>>
341
342
343boards get_board_by_id(eosio::name coopname, uint64_t board_id){
344 boards_index boards(_soviet, coopname.value);
345 auto board = boards.find(board_id);
346
347 eosio::check(board != boards.end(), "Совет не найден");
348
349 return *board;
350
351};
352
353
354boards get_board_by_type_or_fail(eosio::name coopname, eosio::name type){
355 boards_index boards(_soviet, coopname.value);
356 auto boards_by_type_index = boards.template get_index<"bytype"_n>();
357 auto exist = boards_by_type_index.find(type.value);
358
359 eosio::check(exist != boards_by_type_index.end(), "Совет не найден");
360
361 return *exist;
362
363};
364
365
366bool check_for_exist_board_by_type(eosio::name coopname, eosio::name type){
367 boards_index boards(_soviet, coopname.value);
368
369 auto boards_by_type_index = boards.template get_index<"bytype"_n>();
370
371 auto exist = boards_by_type_index.find(type.value);
372
373 if (exist != boards_by_type_index.end())
374 return true;
375 else return false;
376}
377
379 std::string full_address;
380 std::string latitude;
381 std::string longitude;
382 std::string country;
383 std::string state;
384 std::string city;
385 std::string district;
386 std::string street;
387 std::string house_number;
388 std::string building_section;
389 std::string unit_number;
390 std::string directions; //как добраться
391 std::string phone_number;
392 std::string email;
393 std::string business_hours;
394 std::string meta;
395};
396
397
409struct [[eosio::table, eosio::contract(SOVIET)]] address {
410 uint64_t id;
411 eosio::name coopname;
412 eosio::name braname;
414
415 uint64_t primary_key() const { return id; }
416};
417
418
419typedef eosio::multi_index< "addresses"_n, address> addresses_index;
420
421
422
423bool is_valid_participant(eosio::name coopname, eosio::name username) {
424 participants_index participants(_soviet, coopname.value);
425 auto participant = participants.find(username.value);
427 auto account = accounts.find(username.value);
428
429 if (
430 participant != participants.end() &&
431 participant->status == "accepted"_n
432 )
433 {
434 return true;
435 }
436
437 return false;
438}
439
440
441participant get_participant_or_fail(eosio::name coopname, eosio::name username){
442 participants_index participants(_soviet, coopname.value);
443 auto participant = participants.find(username.value);
444 eosio::check(participant != participants.end(), "Пайщик не найден в кооперативе");
445 eosio::check(participant -> status != "blocked"_n, "Пайщик заблокирован");
446
447 return *participant;
448}
449
450
451
eosio::multi_index< "accounts"_n, account, eosio::indexed_by< "byreferer"_n, eosio::const_mem_fun< account, uint64_t, &account::by_referer > >, eosio::indexed_by<"bytype"_n, eosio::const_mem_fun< account, uint64_t, &account::by_type > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< account, uint64_t, &account::by_status > >, eosio::indexed_by<"byregistr"_n, eosio::const_mem_fun< account, uint64_t, &account::by_registr > >, eosio::indexed_by<"byregistred"_n, eosio::const_mem_fun< account, uint64_t, &account::by_registered_at > >, eosio::indexed_by<"byverif"_n, eosio::const_mem_fun< account, uint64_t,&account::is_verified_index > > > accounts_index
Definition: accounts.hpp:150
static constexpr eosio::name _registrator
Definition: consts.hpp:157
static constexpr eosio::name _soviet
Definition: consts.hpp:156
eosio::multi_index<"staff"_n, staff > staff_index
Тип мультииндекса для таблицы администраторов
Definition: coops.hpp:167
participant get_participant_or_fail(eosio::name coopname, eosio::name username)
Definition: coops.hpp:441
boards get_board_by_id(eosio::name coopname, uint64_t board_id)
Definition: coops.hpp:343
boards get_board_by_type_or_fail(eosio::name coopname, eosio::name type)
Definition: coops.hpp:354
eosio::multi_index< "addresses"_n, address > addresses_index
Definition: coops.hpp:419
eosio::multi_index< "participants"_n, participant, eosio::indexed_by<"bylastpay"_n, eosio::const_mem_fun< participant, uint64_t, &participant::bylastpay > >, eosio::indexed_by<"createdat"_n, eosio::const_mem_fun< participant, uint64_t, &participant::by_created_at > >, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< participant, uint64_t, &participant::by_braname > > > participants_index
Definition: coops.hpp:237
bool check_for_exist_board_by_type(eosio::name coopname, eosio::name type)
Definition: coops.hpp:366
eosio::multi_index< "boards"_n, boards, eosio::indexed_by<"bytype"_n, eosio::const_mem_fun< boards, uint64_t, &boards::by_type > > > boards_index
Definition: coops.hpp:118
bool is_valid_participant(eosio::name coopname, eosio::name username)
Definition: coops.hpp:423
eosio::multi_index< "decisions"_n, decision, eosio::indexed_by<"bysecondary"_n, eosio::const_mem_fun< decision, uint64_t, &decision::by_secondary > >, eosio::indexed_by<"bytype"_n, eosio::const_mem_fun< decision, uint64_t, &decision::bytype > >, eosio::indexed_by<"byapproved"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byapproved > >, eosio::indexed_by<"byvalidated"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byvalidated > >, eosio::indexed_by<"byauthorized"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byauthorized > >, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< decision, checksum256, &decision::byhash > > > decisions_index
Definition: coops.hpp:340
contract
Definition: eosio.msig_tests.cpp:977
Definition: eosio.msig.hpp:34
Структура, представляющая учетные записи аккаунтов.
Definition: accounts.hpp:60
Definition: coops.hpp:378
std::string country
Definition: coops.hpp:382
std::string street
Definition: coops.hpp:386
std::string district
Definition: coops.hpp:385
std::string city
Definition: coops.hpp:384
std::string full_address
Definition: coops.hpp:379
std::string state
Definition: coops.hpp:383
std::string unit_number
Definition: coops.hpp:389
std::string building_section
Definition: coops.hpp:388
std::string house_number
Definition: coops.hpp:387
std::string latitude
Definition: coops.hpp:380
std::string phone_number
Definition: coops.hpp:391
std::string directions
Definition: coops.hpp:390
std::string meta
Definition: coops.hpp:394
std::string business_hours
Definition: coops.hpp:393
std::string longitude
Definition: coops.hpp:381
std::string email
Definition: coops.hpp:392
Таблица адресов кооператива
Definition: coops.hpp:409
address_data data
Definition: coops.hpp:413
uint64_t id
Definition: coops.hpp:410
uint64_t primary_key() const
Definition: coops.hpp:415
eosio::name coopname
Definition: coops.hpp:411
eosio::name braname
Definition: coops.hpp:412
Структура, представляющая членов совета (борда).
Definition: coops.hpp:8
eosio::name position
Позиция члена в доске:
Definition: coops.hpp:12
bool is_voting
Флаг, указывающий, имеет ли член доски право голоса.
Definition: coops.hpp:10
std::string position_title
Название должности члена доски.
Definition: coops.hpp:11
eosio::name username
Уникальное имя члена доски.
Definition: coops.hpp:9
Таблица советов кооператива
Definition: coops.hpp:32
bool has_voting_right(eosio::name member) const
Definition: coops.hpp:101
bool is_valid_secretary(eosio::name secretary) const
Definition: coops.hpp:93
eosio::name type
Тип доски:
Definition: coops.hpp:34
bool is_valid_member(eosio::name member) const
Definition: coops.hpp:60
uint64_t get_members_count() const
Definition: coops.hpp:110
uint64_t id
Уникальный идентификатор доски.
Definition: coops.hpp:33
uint64_t by_type() const
Возвращает ключ для индексации по типу доски.
Definition: coops.hpp:58
std::vector< board_member > members
Список членов доски.
Definition: coops.hpp:42
uint64_t primary_key() const
Возвращает первичный ключ доски.
Definition: coops.hpp:52
eosio::time_point_sec last_update
Время последнего обновления информации о доске.
Definition: coops.hpp:45
bool is_voting_member(eosio::name member) const
Definition: coops.hpp:68
eosio::name get_chairman() const
Definition: coops.hpp:85
bool is_valid_chairman(eosio::name chairman) const
Definition: coops.hpp:77
std::string name
Название доски.
Definition: coops.hpp:39
eosio::time_point_sec created_at
Время создания доски.
Definition: coops.hpp:44
std::string description
Описание доски.
Definition: coops.hpp:40
Таблица решений кооператива
Definition: coops.hpp:251
document2 authorization
Документ подписанного решения председателем
Definition: coops.hpp:267
eosio::binary_extension< name > confirm_callback
действие для вызова после принятия решения
Definition: coops.hpp:275
uint64_t by_secondary() const
Возвращает ключ для индексации по идентификатору карточки.
Definition: coops.hpp:289
eosio::name coopname
Имя кооператива, связанного с решением.
Definition: coops.hpp:253
eosio::binary_extension< checksum256 > hash
входящий идентификатор решения
Definition: coops.hpp:277
eosio::name type
Тип решения: // joincoop | change | ...
Definition: coops.hpp:256
uint64_t byauthorized() const
Возвращает ключ для индексации по статусу "авторизовано".
Definition: coops.hpp:313
eosio::binary_extension< eosio::time_point_sec > expired_at
Время до истечения
Definition: coops.hpp:271
uint64_t batch_id
Идентификатор карточки, связанной с типом решения.
Definition: coops.hpp:257
std::vector< eosio::name > votes_against
Список имен, голосовавших "против" решения.
Definition: coops.hpp:261
uint64_t bytype() const
Возвращает ключ для индексации по типу решения.
Definition: coops.hpp:295
uint64_t id
Уникальный идентификатор решения.
Definition: coops.hpp:252
eosio::binary_extension< std::string > meta
мета-данные
Definition: coops.hpp:272
std::pair< uint64_t, uint64_t > get_votes_count() const
Definition: coops.hpp:327
document2 statement
Документ заявления
Definition: coops.hpp:258
checksum256 byhash() const
Definition: coops.hpp:316
eosio::name username
Имя пользователя, связанного с решением.
Definition: coops.hpp:254
std::vector< eosio::name > votes_for
Список имен, голосовавших "за" решение.
Definition: coops.hpp:260
uint64_t byvalidated() const
Возвращает ключ для индексации по статусу "подтверждено".
Definition: coops.hpp:307
uint64_t byapproved() const
Возвращает ключ для индексации по статусу "принято".
Definition: coops.hpp:301
eosio::binary_extension< name > callback_contract
контракт для вызова после принятия решения
Definition: coops.hpp:274
uint64_t primary_key() const
Возвращает первичный ключ решения.
Definition: coops.hpp:283
eosio::binary_extension< name > decline_callback
действие для вызова после отклонения решения
Definition: coops.hpp:276
eosio::name authorized_by
Имя аккаунта председателя
Definition: coops.hpp:266
eosio::time_point_sec created_at
Время создания карточки решения.
Definition: coops.hpp:269
void check_for_any_vote_exist(eosio::name member) const
Definition: coops.hpp:319
Definition: drafts.hpp:28
Таблица участников кооператива
Definition: coops.hpp:181
eosio::binary_extension< eosio::name > braname
имя кооперативного участка
Definition: coops.hpp:194
uint64_t bylastpay() const
Возвращает ключ для индексации по времени последнего минимального платежа.
Definition: coops.hpp:211
uint64_t by_braname() const
Definition: coops.hpp:227
eosio::name username
Уникальное имя члена кооператива.
Definition: coops.hpp:182
eosio::binary_extension< eosio::name > type
individual | entrepreneur | organization
Definition: coops.hpp:193
eosio::binary_extension< eosio::asset > minimum_amount
внесенный минимальный паевой взнос
Definition: coops.hpp:197
eosio::time_point_sec created_at
Время создания записи о члене.
Definition: coops.hpp:183
eosio::name status
Definition: coops.hpp:187
uint64_t primary_key() const
Возвращает первичный ключ учетной записи члена кооператива.
Definition: coops.hpp:203
eosio::time_point_sec last_update
Время последнего обновления информации о члене.
Definition: coops.hpp:184
eosio::binary_extension< eosio::asset > initial_amount
внесенный вступительный взнос
Definition: coops.hpp:196
eosio::time_point_sec last_min_pay
Время последнего минимального платежа.
Definition: coops.hpp:185
uint64_t by_created_at() const
Возвращает ключ для индексации по времени создания
Definition: coops.hpp:219
bool is_active() const
Definition: coops.hpp:223
Структура, представляющая права доступа.
Definition: coops.hpp:126
eosio::name contract
Имя контракта, к которому применяется право доступа.
Definition: coops.hpp:127
eosio::name action_name
Имя действия, к которому применяется право доступа.
Definition: coops.hpp:128
Структура, представляющая администраторов кооператива.
Definition: coops.hpp:147
eosio::time_point_sec updated_at
Время последнего обновления информации об администраторе
Definition: coops.hpp:153
bool has_right(eosio::name contract, eosio::name action_name) const
Definition: coops.hpp:157
std::string position_title
Название должности администратора
Definition: coops.hpp:149
uint64_t primary_key() const
Первичный ключ для индексации по имени администратора
Definition: coops.hpp:155
std::vector< right > rights
Список прав администратора
Definition: coops.hpp:151
eosio::name username
Уникальное имя администратора
Definition: coops.hpp:148
eosio::time_point_sec created_at
Время создания записи об администраторе
Definition: coops.hpp:152
std::vector< eosio::name > roles
Список ролей
Definition: coops.hpp:150