COOPENOMICS  v1
Кооперативная Экономика
program_properties.hpp
См. документацию.
1#pragma once
2
3#include <eosio/eosio.hpp>
4#include <eosio/asset.hpp>
5
6using namespace eosio;
7using std::string;
8
16 namespace Status {
17 constexpr eosio::name CREATED = "created"_n;
18 constexpr eosio::name APPROVED = "approved"_n;
19 constexpr eosio::name AUTHORIZED = "authorized"_n;
20 constexpr eosio::name ACT1 = "act1"_n;
21 constexpr eosio::name ACT2 = "act2"_n;
22 }
23}
24
26
35 struct [[eosio::table, eosio::contract(CAPITAL)]] program_property {
36 uint64_t id;
37 name coopname;
38 name username;
39 name status;
40 checksum256 property_hash;
41 eosio::asset property_amount;
46 time_point_sec created_at;
47
48 uint64_t primary_key() const { return id; }
49 uint64_t by_username() const { return username.value; }
50 checksum256 by_property_hash() const { return property_hash; }
51 };
52
53typedef eosio::multi_index<
54 "pgproperties"_n, program_property,
55 indexed_by<"byusername"_n, const_mem_fun<program_property, uint64_t, &program_property::by_username>>,
56 indexed_by<"byhash"_n, const_mem_fun<program_property, checksum256, &program_property::by_property_hash>>
58
65 inline std::optional<program_property> get_program_property(eosio::name coopname, const checksum256 &hash) {
66 program_property_index properties(_capital, coopname.value);
67 auto property_hash_index = properties.get_index<"byhash"_n>();
68
69 auto itr = property_hash_index.find(hash);
70 if (itr == property_hash_index.end()) {
71 return std::nullopt;
72 }
73
74 return *itr;
75}
76
83 inline program_property get_program_property_or_fail(eosio::name coopname, const checksum256 &hash) {
84 auto property = get_program_property(coopname, hash);
85 eosio::check(property.has_value(), "Предложение по программному имущественному взносу не найдено");
86
87 return property.value();
88}
89
95inline void delete_program_property(eosio::name coopname, const checksum256 &hash) {
96 program_property_index properties(_capital, coopname.value);
97 auto property_hash_index = properties.get_index<"byhash"_n>();
98
99 auto itr = property_hash_index.find(hash);
100 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
101
102 properties.erase(*itr);
103}
104
115 eosio::name coopname,
116 eosio::name username,
117 checksum256 property_hash,
118 const eosio::asset &property_amount,
119 const std::string &property_description,
120 const document2 &statement
121) {
122 // Создаем предложение
123 program_property_index properties(_capital, coopname.value);
124 auto property_id = get_global_id_in_scope(_capital, coopname, "pgproperties"_n);
125
126 // Создаем предложение в таблице pgproperties
127 properties.emplace(coopname, [&](auto &p) {
128 p.id = property_id;
130 p.coopname = coopname;
131 p.username = username;
132 p.property_hash = property_hash;
133 p.property_amount = property_amount;
134 p.property_description = property_description;
135 p.statement = statement;
136 p.created_at = current_time_point();
137 });
138
139 // Отправляем на approve председателю
141 _capital,
142 coopname,
143 username,
144 statement,
146 property_hash,
147 _capital,
150 std::string("")
151 );
152}
153
160inline void update_program_property_status(eosio::name coopname, const checksum256 &property_hash, eosio::name new_status) {
161 program_property_index properties(_capital, coopname.value);
162 auto property_hash_index = properties.get_index<"byhash"_n>();
163
164 auto itr = property_hash_index.find(property_hash);
165 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
166
167 property_hash_index.modify(itr, _capital, [&](auto &p) {
168 p.status = new_status;
169 });
170}
171
175inline void set_program_property_approved_statement(eosio::name coopname, const checksum256 &property_hash, const document2 &approved_statement) {
176 program_property_index properties(_capital, coopname.value);
177 auto property_hash_index = properties.get_index<"byhash"_n>();
178
179 auto itr = property_hash_index.find(property_hash);
180 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
181
182 property_hash_index.modify(itr, _capital, [&](auto &p) {
183 p.statement = approved_statement;
184 });
185}
186
190inline void set_program_property_authorization(eosio::name coopname, const checksum256 &property_hash, const document2 &authorization) {
191 program_property_index properties(_capital, coopname.value);
192 auto property_hash_index = properties.get_index<"byhash"_n>();
193
194 auto itr = property_hash_index.find(property_hash);
195 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
196
197 property_hash_index.modify(itr, _capital, [&](auto &p) {
198 p.authorization = authorization;
199 });
200}
201
205inline void set_program_property_act1(eosio::name coopname, const checksum256 &property_hash, const document2 &act1) {
206 program_property_index properties(_capital, coopname.value);
207 auto property_hash_index = properties.get_index<"byhash"_n>();
208
209 auto itr = property_hash_index.find(property_hash);
210 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
211
212 property_hash_index.modify(itr, _capital, [&](auto &p) {
213 p.act = act1;
214 });
215}
216
220inline void set_program_property_act2(eosio::name coopname, const checksum256 &property_hash, const document2 &act2) {
221 program_property_index properties(_capital, coopname.value);
222 auto property_hash_index = properties.get_index<"byhash"_n>();
223
224 auto itr = property_hash_index.find(property_hash);
225 eosio::check(itr != property_hash_index.end(), "Предложение по программному имущественному взносу не найдено");
226
227 property_hash_index.modify(itr, _capital, [&](auto &p) {
228 p.act = act2;
229 });
230}
231
232} // namespace Capital::ProgramProperties
static constexpr eosio::name _capital
Definition: consts.hpp:150
contract
Definition: eosio.msig_tests.cpp:977
uint64_t get_global_id_in_scope(eosio::name _me, eosio::name scope, eosio::name key)
Definition: counts.hpp:61
constexpr eosio::name AUTHORIZED
Программный имущественный взнос авторизован
Definition: program_properties.hpp:19
constexpr eosio::name ACT2
Второй акт подписан
Definition: program_properties.hpp:21
constexpr eosio::name CREATED
Программный имущественный взнос создан
Definition: program_properties.hpp:17
constexpr eosio::name APPROVED
Программный имущественный взнос одобрен
Definition: program_properties.hpp:18
constexpr eosio::name ACT1
Первый акт подписан
Definition: program_properties.hpp:20
Definition: program_properties.hpp:9
void set_program_property_act1(eosio::name coopname, const checksum256 &property_hash, const document2 &act1)
Устанавливает первый акт
Definition: program_properties.hpp:205
void set_program_property_act2(eosio::name coopname, const checksum256 &property_hash, const document2 &act2)
Устанавливает второй акт
Definition: program_properties.hpp:220
std::optional< program_property > get_program_property(eosio::name coopname, const checksum256 &hash)
Получает программное предложение по хэшу.
Definition: program_properties.hpp:65
void update_program_property_status(eosio::name coopname, const checksum256 &property_hash, eosio::name new_status)
Обновляет статус программного предложения
Definition: program_properties.hpp:160
void create_program_property_with_approve(eosio::name coopname, eosio::name username, checksum256 property_hash, const eosio::asset &property_amount, const std::string &property_description, const document2 &statement)
Создает предложение по программному имущественному взносу и отправляет его на утверждение.
Definition: program_properties.hpp:114
program_property get_program_property_or_fail(eosio::name coopname, const checksum256 &hash)
Получает программное предложение по хэшу или падает с ошибкой.
Definition: program_properties.hpp:83
void set_program_property_authorization(eosio::name coopname, const checksum256 &property_hash, const document2 &authorization)
Устанавливает решение совета
Definition: program_properties.hpp:190
eosio::multi_index< "pgproperties"_n, program_property, indexed_by<"byusername"_n, const_mem_fun< program_property, uint64_t, &program_property::by_username > >, indexed_by<"byhash"_n, const_mem_fun< program_property, checksum256, &program_property::by_property_hash > > > program_property_index
Definition: program_properties.hpp:57
void set_program_property_approved_statement(eosio::name coopname, const checksum256 &property_hash, const document2 &approved_statement)
Устанавливает одобренное заявление
Definition: program_properties.hpp:175
void delete_program_property(eosio::name coopname, const checksum256 &hash)
Удаляет программное предложение по хэшу.
Definition: program_properties.hpp:95
constexpr eosio::name CREATE_PROGRAM_PROPERTY
Definition: shared_names.hpp:106
constexpr eosio::name DECLINE_PROGRAM_PROPERTY
Definition: shared_names.hpp:25
constexpr eosio::name APPROVE_PROGRAM_PROPERTY
Definition: shared_names.hpp:24
void create_approval(name calling_contract, CREATEAPPRV_SIGNATURE)
Создаёт аппрув в совете
Definition: shared_soviet.hpp:73
Definition: eosio.msig.hpp:34
Таблица программных имущественных взносов хранит данные о предложениях по имущественным взносам в про...
Definition: program_properties.hpp:35
document2 statement
Заявление о внесении имущества
Definition: program_properties.hpp:43
uint64_t primary_key() const
Первичный ключ (1)
Definition: program_properties.hpp:48
document2 act
Акт
Definition: program_properties.hpp:45
time_point_sec created_at
Время создания предложения
Definition: program_properties.hpp:46
checksum256 by_property_hash() const
Индекс по хэшу предложения (3)
Definition: program_properties.hpp:50
checksum256 property_hash
Хэш предложения
Definition: program_properties.hpp:40
uint64_t id
ID программного имущественного взноса (внутренний ключ)
Definition: program_properties.hpp:36
document2 authorization
Решение совета
Definition: program_properties.hpp:44
eosio::asset property_amount
Оценочная стоимость имущества
Definition: program_properties.hpp:41
name status
Статус предложения (created | approved | authorized | act1 | act2)
Definition: program_properties.hpp:39
name username
Имя пользователя, подающего предложение
Definition: program_properties.hpp:38
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: program_properties.hpp:49
std::string property_description
Описание имущества
Definition: program_properties.hpp:42
name coopname
Имя кооператива
Definition: program_properties.hpp:37
Definition: drafts.hpp:28