COOPENOMICS  v1
Кооперативная Экономика
project_properties.hpp
См. документацию.
1#pragma once
2
3
4#include "../../../lib/core/ram_payer.hpp"
5#include <eosio/eosio.hpp>
6#include <eosio/asset.hpp>
7
8using namespace eosio;
9using std::string;
10
18 namespace Status {
19 constexpr eosio::name CREATED = "created"_n;
20 }
21}
22
24
33 struct [[eosio::table, eosio::contract(CAPITAL)]] property {
34 uint64_t id;
35 name coopname;
36 name username;
37 name status;
38 checksum256 project_hash;
39 checksum256 property_hash;
40 eosio::asset property_amount;
42 time_point_sec created_at;
43
44 uint64_t primary_key() const { return id; }
45 uint64_t by_username() const { return username.value; }
46 checksum256 by_property_hash() const { return property_hash; }
47 checksum256 by_project_hash() const { return project_hash; }
48 };
49
50typedef eosio::multi_index<
51 "pjproperties"_n, property,
52 indexed_by<"byusername"_n, const_mem_fun<property, uint64_t, &property::by_username>>,
53 indexed_by<"byhash"_n, const_mem_fun<property, checksum256, &property::by_property_hash>>,
54 indexed_by<"byprojhash"_n, const_mem_fun<property, checksum256, &property::by_project_hash>>
56
63 inline std::optional<property> get_property(eosio::name coopname, const checksum256 &hash) {
64 property_index properties(_capital, coopname.value);
65 auto property_hash_index = properties.get_index<"byhash"_n>();
66
67 auto itr = property_hash_index.find(hash);
68 if (itr == property_hash_index.end()) {
69 return std::nullopt;
70 }
71
72 return property(*itr);
73}
74
81 inline property get_property_or_fail(eosio::name coopname, const checksum256 &hash) {
82 auto property = get_property(coopname, hash);
83 eosio::check(property.has_value(), "Предложение по имущественному взносу не найдено");
84
85 return property.value();
86}
87
93inline void delete_property(eosio::name coopname, uint64_t property_id) {
94 property_index properties(_capital, coopname.value);
95 auto property = properties.find(property_id);
96 eosio::check(property != properties.end(), "Предложение по имущественному взносу не найдено");
97
98 properties.erase(property);
99}
100
111 eosio::name coopname,
112 eosio::name username,
113 checksum256 project_hash,
114 checksum256 property_hash,
115 const eosio::asset &property_amount,
116 const std::string &property_description
117) {
118 // Создаем предложение
119 property_index properties(_capital, coopname.value);
120 auto property_id = get_global_id_in_scope(_capital, coopname, "properties"_n);
121
122 // Создаем предложение в таблице properties
123 properties.emplace(RamPayer::of(properties, coopname), [&](auto &p) {
124 p.id = property_id;
126 p.coopname = coopname;
127 p.username = username;
128 p.project_hash = project_hash;
129 p.property_hash = property_hash;
130 p.property_amount = property_amount;
131 p.property_description = property_description;
132 p.created_at = current_time_point();
133 });
134
135 // Создаем пустой документ
136 auto empty_doc = document2{};
137
138 // Отправляем на approve председателю
140 _capital,
141 coopname,
142 username,
143 empty_doc,
145 property_hash,
146 _capital,
149 std::string("")
150 );
151}
152
153} // namespace Capital::ProjectProperties
154
155// Плательщик за оперативную память строк таблицы — правило в lib/core/ram_payer.hpp.
static constexpr eosio::name _capital
Definition: consts.hpp:171
contract
Definition: eosio.msig_tests.cpp:977
constexpr eosio::name CREATED
Имущественный взнос создан
Definition: project_properties.hpp:19
Definition: project_properties.hpp:11
eosio::multi_index< "pjproperties"_n, property, indexed_by<"byusername"_n, const_mem_fun< property, uint64_t, &property::by_username > >, indexed_by<"byhash"_n, const_mem_fun< property, checksum256, &property::by_property_hash > >, indexed_by<"byprojhash"_n, const_mem_fun< property, checksum256, &property::by_project_hash > > > property_index
Definition: project_properties.hpp:55
std::optional< property > get_property(eosio::name coopname, const checksum256 &hash)
Получает предложение по хэшу.
Definition: project_properties.hpp:63
property get_property_or_fail(eosio::name coopname, const checksum256 &hash)
Получает предложение по хэшу или падает с ошибкой.
Definition: project_properties.hpp:81
void create_property_with_approve(eosio::name coopname, eosio::name username, checksum256 project_hash, checksum256 property_hash, const eosio::asset &property_amount, const std::string &property_description)
Создает предложение по имущественному взносу и отправляет его на утверждение.
Definition: project_properties.hpp:110
void delete_property(eosio::name coopname, uint64_t property_id)
Удаляет предложение по ID.
Definition: project_properties.hpp:93
constexpr eosio::name DECLINE_PROPERTY
Definition: names.hpp:21
constexpr eosio::name APPROVE_PROPERTY
Definition: names.hpp:20
constexpr eosio::name CREATE_PROPERTY
Definition: names.hpp:132
eosio::name of(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:78
void create_approval(name calling_contract, CREATEAPPRV_SIGNATURE)
Definition: soviet.hpp:66
Definition: eosio.msig.hpp:34
RAM_PAYER_CLASS(Capital::ProjectProperties::property, cooperative)
Таблица имущественных взносов хранит данные о предложениях по имущественным взносам в проекты.
Definition: project_properties.hpp:33
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: project_properties.hpp:45
name status
Статус предложения (created)
Definition: project_properties.hpp:37
name coopname
Имя кооператива
Definition: project_properties.hpp:35
checksum256 project_hash
Хэш проекта, связанного с предложением
Definition: project_properties.hpp:38
checksum256 by_project_hash() const
Индекс по хэшу проекта (4)
Definition: project_properties.hpp:47
uint64_t primary_key() const
Первичный ключ (1)
Definition: project_properties.hpp:44
checksum256 property_hash
Хэш предложения
Definition: project_properties.hpp:39
uint64_t id
ID имущественного взноса (внутренний ключ)
Definition: project_properties.hpp:34
eosio::asset property_amount
Оценочная стоимость имущества
Definition: project_properties.hpp:40
std::string property_description
Описание имущества
Definition: project_properties.hpp:41
checksum256 by_property_hash() const
Индекс по хэшу предложения (3)
Definition: project_properties.hpp:46
time_point_sec created_at
Время создания предложения
Definition: project_properties.hpp:42
name username
Имя пользователя, подающего предложение
Definition: project_properties.hpp:36
Definition: table_registrator_orgs.hpp:17
Definition: document_core.hpp:27
uint64_t get_global_id_in_scope(eosio::name _me, eosio::name scope, eosio::name key)
Definition: table_counts.hpp:62