COOPENOMICS  v1
Кооперативная Экономика
table_branch_decisions.hpp
См. документацию.
1#pragma once
2
3#include <algorithm>
4#include <eosio/eosio.hpp>
5#include <string>
6#include <vector>
7
8#include "../consts.hpp"
9#include "document_core.hpp"
10
23static constexpr uint64_t MIN_DECISION_QUORUM = 3;
24
28static constexpr uint32_t DECISION_VOTING_WINDOW_SECONDS = 15 * 60;
29
32 std::string title;
33 std::string decision;
34 std::string context;
35};
36
39 uint64_t question_id;
40 eosio::name vote;
41};
42
48struct [[eosio::table, eosio::contract(BRANCH)]] coodecision {
49 uint64_t id;
50 eosio::checksum256 hash;
51 eosio::name coopname;
52 eosio::name type;
53 eosio::name initiator;
54 eosio::name chairman;
55 eosio::name status;
56
63
64 eosio::time_point_sec open_at;
65 eosio::time_point_sec close_at;
66 uint64_t signed_ballots;
67
68 eosio::name braname;
69 std::string address;
70
71 std::vector<eosio::name> participants;
72 eosio::time_point_sec created_at;
73 // Место и время проведения собрания НЕ публикуются в блокчейн —
74 // это приватные данные пайщиков, живут в БД платформы (composite db-слой).
75
76 uint64_t primary_key() const { return id; }
77 eosio::checksum256 by_hash() const { return hash; }
78
79 bool is_participant(const eosio::name &username) const {
80 return std::find(participants.begin(), participants.end(), username) != participants.end();
81 }
82};
83
84typedef eosio::multi_index<
85 "decisions"_n, coodecision,
86 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<coodecision, eosio::checksum256, &coodecision::by_hash>>>
88
94struct [[eosio::table, eosio::contract(BRANCH)]] coodecquest {
95 uint64_t id;
96 uint64_t decision_id;
97 uint64_t number;
98 eosio::name coopname;
99
100 std::string title;
101 std::string decision;
102 std::string context;
103
107
108 std::vector<eosio::name> voters_for;
109 std::vector<eosio::name> voters_against;
110 std::vector<eosio::name> voters_abstained;
111
112 uint64_t primary_key() const { return id; }
113 uint64_t by_decision() const { return decision_id; }
114};
115
116typedef eosio::multi_index<
117 "decisionq"_n, coodecquest,
118 eosio::indexed_by<"bydecision"_n, eosio::const_mem_fun<coodecquest, uint64_t, &coodecquest::by_decision>>>
120
122inline coodecision get_decision_or_fail(eosio::name coopname, eosio::checksum256 hash) {
123 decision_index decisions(_branch, coopname.value);
124 auto idx = decisions.get_index<"byhash"_n>();
125 auto itr = idx.find(hash);
126 eosio::check(itr != idx.end(), "Решение собрания не найдено");
127 return *itr;
128}
129
131inline void erase_coodecquests(eosio::name coopname, uint64_t decision_id) {
132 coodecquest_index questions(_branch, coopname.value);
133 auto by_dec = questions.get_index<"bydecision"_n>();
134 auto itr = by_dec.lower_bound(decision_id);
135 while (itr != by_dec.end() && itr->decision_id == decision_id) {
136 itr = by_dec.erase(itr);
137 }
138}
static constexpr eosio::name _branch
Definition: consts.hpp:176
contract
Definition: eosio.msig_tests.cpp:977
Definition: eosio.msig.hpp:34
Definition: table_branch_decisions.hpp:48
eosio::name coopname
Имя кооператива
Definition: table_branch_decisions.hpp:51
eosio::checksum256 by_hash() const
Definition: table_branch_decisions.hpp:77
bool is_participant(const eosio::name &username) const
Definition: table_branch_decisions.hpp:79
eosio::time_point_sec open_at
Начало голосования
Definition: table_branch_decisions.hpp:64
eosio::name initiator
Организатор собрания
Definition: table_branch_decisions.hpp:53
eosio::name status
opened | voting | approved | onapproval
Definition: table_branch_decisions.hpp:55
document2 protocol
Протокол решения (утверждает председатель)
Definition: table_branch_decisions.hpp:58
document2 liability
Договор о полной индивидуальной материальной ответственности председателя КУ (подписан председателем ...
Definition: table_branch_decisions.hpp:60
eosio::time_point_sec created_at
Дата создания
Definition: table_branch_decisions.hpp:72
document2 authority
Доверенность председателю КУ (подписана председателем участка, ждёт встречной подписи председателя со...
Definition: table_branch_decisions.hpp:61
eosio::name braname
Заранее сгенерированный аккаунт будущего КУ (createbranch)
Definition: table_branch_decisions.hpp:68
eosio::time_point_sec close_at
Плановое закрытие голосования
Definition: table_branch_decisions.hpp:65
uint64_t id
Идентификатор решения
Definition: table_branch_decisions.hpp:49
eosio::name type
Тип решения: "free" | "createbranch".
Definition: table_branch_decisions.hpp:52
std::vector< eosio::name > participants
Присоединившиеся участники собрания
Definition: table_branch_decisions.hpp:71
std::string address
Адрес привязки КУ (createbranch)
Definition: table_branch_decisions.hpp:69
document2 proposal
Подписанное предложение/повестка инициатора
Definition: table_branch_decisions.hpp:57
document2 petition
Заявление председателя в совет (для createbranch)
Definition: table_branch_decisions.hpp:59
uint64_t signed_ballots
Число поданных бюллетеней
Definition: table_branch_decisions.hpp:66
eosio::checksum256 hash
Якорь процесса (внешний идентификатор)
Definition: table_branch_decisions.hpp:50
eosio::name chairman
Председатель собрания — выбирается организатором из участников при открытии голосования (для createbr...
Definition: table_branch_decisions.hpp:54
document2 authorization
Решение совета (callback)
Definition: table_branch_decisions.hpp:62
uint64_t primary_key() const
Definition: table_branch_decisions.hpp:76
Definition: table_branch_decisions.hpp:94
std::vector< eosio::name > voters_for
Проголосовавшие за
Definition: table_branch_decisions.hpp:108
uint64_t by_decision() const
Definition: table_branch_decisions.hpp:113
std::string context
Контекст вопроса
Definition: table_branch_decisions.hpp:102
uint64_t counter_votes_against
Счётчик голосов против
Definition: table_branch_decisions.hpp:105
eosio::name coopname
Имя кооператива
Definition: table_branch_decisions.hpp:98
uint64_t counter_votes_for
Счётчик голосов за
Definition: table_branch_decisions.hpp:104
std::string decision
Проект решения по вопросу
Definition: table_branch_decisions.hpp:101
std::vector< eosio::name > voters_against
Проголосовавшие против
Definition: table_branch_decisions.hpp:109
uint64_t primary_key() const
Definition: table_branch_decisions.hpp:112
std::string title
Текст вопроса
Definition: table_branch_decisions.hpp:100
uint64_t id
Идентификатор вопроса
Definition: table_branch_decisions.hpp:95
uint64_t counter_votes_abstained
Счётчик воздержавшихся
Definition: table_branch_decisions.hpp:106
uint64_t number
Номер вопроса в повестке
Definition: table_branch_decisions.hpp:97
std::vector< eosio::name > voters_abstained
Воздержавшиеся
Definition: table_branch_decisions.hpp:110
uint64_t decision_id
Идентификатор решения
Definition: table_branch_decisions.hpp:96
Точка повестки дня собрания (вход действия createdec).
Definition: table_branch_decisions.hpp:31
std::string title
Текст вопроса
Definition: table_branch_decisions.hpp:32
std::string decision
Проект решения по вопросу
Definition: table_branch_decisions.hpp:33
std::string context
Контекст вопроса (может быть пустым)
Definition: table_branch_decisions.hpp:34
Голос участника по одному вопросу повестки (вход действия votedec).
Definition: table_branch_decisions.hpp:38
eosio::name vote
Голос: "for"_n | "against"_n | "abstained"_n.
Definition: table_branch_decisions.hpp:40
uint64_t question_id
Идентификатор вопроса
Definition: table_branch_decisions.hpp:39
Definition: document_core.hpp:27
eosio::multi_index< "decisions"_n, coodecision, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< coodecision, eosio::checksum256, &coodecision::by_hash > > > decision_index
Definition: table_branch_decisions.hpp:87
void erase_coodecquests(eosio::name coopname, uint64_t decision_id)
Удалить все вопросы повестки данного решения (при erase решения).
Definition: table_branch_decisions.hpp:131
static constexpr uint64_t MIN_DECISION_QUORUM
Минимальный кворум учредительного собрания (число подписанных бюллетеней).
Definition: table_branch_decisions.hpp:23
coodecision get_decision_or_fail(eosio::name coopname, eosio::checksum256 hash)
Получить решение по якорю или упасть.
Definition: table_branch_decisions.hpp:122
static constexpr uint32_t DECISION_VOTING_WINDOW_SECONDS
Definition: table_branch_decisions.hpp:28
eosio::multi_index< "decisionq"_n, coodecquest, eosio::indexed_by<"bydecision"_n, eosio::const_mem_fun< coodecquest, uint64_t, &coodecquest::by_decision > > > coodecquest_index
Definition: table_branch_decisions.hpp:119