COOPENOMICS  v1
Кооперативная Экономика
table_branch_branches.hpp
См. документацию.
1#pragma once
2
3#include <algorithm>
4#include <eosio/eosio.hpp>
5#include <vector>
6
7#include "../consts.hpp"
8
14struct [[eosio::table, eosio::contract(BRANCH)]] coobranch {
15 eosio::name braname;
16 eosio::name trustee;
17 std::vector<eosio::name> trusted;
18
19 uint64_t primary_key() const { return braname.value; }
20 uint64_t by_trustee() const { return trustee.value; }
21
22 void add_account_to_trusted(const eosio::name &account) { trusted.push_back(account); }
23
24 void remove_account_from_trusted(const eosio::name &account) {
25 auto itr = std::remove(trusted.begin(), trusted.end(), account);
26 eosio::check(itr != trusted.end(), "Account not found in trusted list");
27 trusted.erase(itr, trusted.end());
28 }
29
30 bool is_account_in_trusted(const eosio::name &account) const {
31 return std::find(trusted.begin(), trusted.end(), account) != trusted.end();
32 }
33
34 bool is_user_authorized(const eosio::name &username) const {
35 if (trustee == username) {
36 return true;
37 }
38 return is_account_in_trusted(username);
39 }
40};
41
42typedef eosio::multi_index<
43 "branches"_n, coobranch,
44 eosio::indexed_by<"bytrustee"_n, eosio::const_mem_fun<coobranch, uint64_t, &coobranch::by_trustee>>>
46
47coobranch get_branch_or_fail(eosio::name coopname, eosio::name braname) {
48 branch_index branches(_branch, coopname.value);
49 auto branch = branches.find(braname.value);
50
51 eosio::check(branch != branches.end(), "Кооперативный Участок не найден");
52
53 return *branch;
54}
Константы контракта кооперативных участков
Definition: branch.hpp:51
static constexpr eosio::name _branch
Definition: consts.hpp:160
contract
Definition: eosio.msig_tests.cpp:977
Definition: eosio.msig.hpp:34
Definition: table_registrator_accounts.hpp:14
Definition: table_branch_branches.hpp:14
uint64_t by_trustee() const
Definition: table_branch_branches.hpp:20
void add_account_to_trusted(const eosio::name &account)
Definition: table_branch_branches.hpp:22
uint64_t primary_key() const
Definition: table_branch_branches.hpp:19
void remove_account_from_trusted(const eosio::name &account)
Definition: table_branch_branches.hpp:24
bool is_user_authorized(const eosio::name &username) const
Definition: table_branch_branches.hpp:34
bool is_account_in_trusted(const eosio::name &account) const
Definition: table_branch_branches.hpp:30
eosio::name trustee
Definition: table_branch_branches.hpp:16
std::vector< eosio::name > trusted
Definition: table_branch_branches.hpp:17
eosio::name braname
Definition: table_branch_branches.hpp:15
coobranch get_branch_or_fail(eosio::name coopname, eosio::name braname)
Definition: table_branch_branches.hpp:47
eosio::multi_index< "branches"_n, coobranch, eosio::indexed_by<"bytrustee"_n, eosio::const_mem_fun< coobranch, uint64_t, &coobranch::by_trustee > > > branch_index
Definition: table_branch_branches.hpp:45