COOPENOMICS  v1
Кооперативная Экономика
branch.hpp
См. документацию.
1#pragma once
2
11struct [[eosio::table, eosio::contract(BRANCH)]] branchstat {
12 eosio::name coopname;
13 uint64_t count;
14
15 uint64_t primary_key() const { return coopname.value; }
16};
17
18typedef eosio::multi_index<"branchstat"_n, branchstat> branchstat_index;
19
20uint64_t add_branch_count(eosio::name coopname){
21 branchstat_index stat(_branch, _branch.value);
22 auto st = stat.find(coopname.value);
23
24 uint64_t new_count = 0;
25
26 if (st == stat.end()){
27 new_count = 1;
28 stat.emplace(coopname, [&](auto &s){
29 s.coopname = coopname;
30 s.count = new_count;
31 });
32 } else {
33 new_count = st -> count + 1;
34 stat.modify(st, coopname, [&](auto &s){
35 s.count += 1;
36 });
37 };
38
39 return new_count;
40};
41
42uint64_t sub_branch_count(eosio::name coopname){
43 branchstat_index stat(_branch, _branch.value);
44 auto st = stat.find(coopname.value);
45 uint64_t new_count = 0;
46
47 eosio::check(st != stat.end(), "Нет кооперативных участков");
48 eosio::check( st -> count > 0, "Системная ошибка");
49
50 new_count = st -> count - 1;
51
52 stat.modify(st, coopname, [&](auto &s){
53 s.count -= 1;
54 });
55
56 return new_count;
57};
58
59
68struct [[eosio::table, eosio::contract(BRANCH)]] coobranch {
69 eosio::name braname;
70 eosio::name trustee;
71 std::vector<eosio::name> trusted;
72
73
74 uint64_t primary_key() const { return braname.value; }
75 uint64_t by_trustee() const { return trustee.value; }
76
77 void add_account_to_trusted(const eosio::name& account) {
78 trusted.push_back(account);
79 }
80
81 void remove_account_from_trusted(const eosio::name& account) {
82 auto itr = std::remove(trusted.begin(), trusted.end(), account);
83 check(itr != trusted.end(), "Account not found in trusted list");
84 trusted.erase(itr, trusted.end());
85 }
86
87 bool is_account_in_trusted(const eosio::name& account) const {
88 return std::find(trusted.begin(), trusted.end(), account) != trusted.end();
89 }
90
96 bool is_user_authorized(const eosio::name& username) const {
97 // Проверяем является ли пользователь доверенным лицом (trustee)
98 if (trustee == username) {
99 return true;
100 }
101
102 // Проверяем находится ли пользователь в списке доверенных (trusted)
103 return is_account_in_trusted(username);
104 }
105};
106
107typedef eosio::multi_index<"branches"_n, coobranch,
108 eosio::indexed_by<"bytrustee"_n, eosio::const_mem_fun<coobranch, uint64_t, &coobranch::by_trustee>>
110
111
112coobranch get_branch_or_fail(eosio::name coopname, eosio::name braname) {
113 branch_index branches(_branch, coopname.value);
114 auto branch = branches.find(braname.value);
115
116 eosio::check(branch != branches.end(), "Кооперативный Участок не найден");
117
118 return *branch;
119};
120
Константы контракта кооперативных участков
Definition: branch.hpp:51
static constexpr eosio::name _branch
Definition: consts.hpp:160
contract
Definition: eosio.msig_tests.cpp:977
eosio::multi_index<"branchstat"_n, branchstat > branchstat_index
Definition: branch.hpp:18
uint64_t add_branch_count(eosio::name coopname)
Definition: branch.hpp:20
eosio::multi_index<"branches"_n, coobranch, eosio::indexed_by<"bytrustee"_n, eosio::const_mem_fun< coobranch, uint64_t, &coobranch::by_trustee > > > branch_index
Definition: branch.hpp:109
coobranch get_branch_or_fail(eosio::name coopname, eosio::name braname)
Definition: branch.hpp:112
uint64_t sub_branch_count(eosio::name coopname)
Definition: branch.hpp:42
Definition: eosio.msig.hpp:34
Структура, представляющая учетные записи аккаунтов.
Definition: accounts.hpp:60
Таблица статистики кооперативных участков хранит количество участков для каждого кооператива.
Definition: branch.hpp:11
uint64_t count
Количество кооперативных участков
Definition: branch.hpp:13
uint64_t primary_key() const
Definition: branch.hpp:15
eosio::name coopname
Имя кооператива
Definition: branch.hpp:12
Таблица кооперативных участков хранит информацию о кооперативных участках и их доверенных лицах.
Definition: branch.hpp:68
uint64_t by_trustee() const
Индекс по доверенному лицу (2)
Definition: branch.hpp:75
void add_account_to_trusted(const eosio::name &account)
Definition: branch.hpp:77
uint64_t primary_key() const
Первичный ключ (1)
Definition: branch.hpp:74
void remove_account_from_trusted(const eosio::name &account)
Definition: branch.hpp:81
bool is_user_authorized(const eosio::name &username) const
Проверяет права доступа пользователя к данному кооперативному участку
Definition: branch.hpp:96
bool is_account_in_trusted(const eosio::name &account) const
Definition: branch.hpp:87
eosio::name trustee
Председатель кооперативного участка
Definition: branch.hpp:70
std::vector< eosio::name > trusted
Список доверенных лиц кооперативного участка
Definition: branch.hpp:71
eosio::name braname
Имя кооперативного участка
Definition: branch.hpp:69