COOPENOMICS  v1
Кооперативная Экономика
project_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 }
19}
20
22
31 struct [[eosio::table, eosio::contract(CAPITAL)]] property {
32 uint64_t id;
33 name coopname;
34 name username;
35 name status;
36 checksum256 project_hash;
37 checksum256 property_hash;
38 eosio::asset property_amount;
40 time_point_sec created_at;
41
42 uint64_t primary_key() const { return id; }
43 uint64_t by_username() const { return username.value; }
44 checksum256 by_property_hash() const { return property_hash; }
45 checksum256 by_project_hash() const { return project_hash; }
46 };
47
48typedef eosio::multi_index<
49 "pjproperties"_n, property,
50 indexed_by<"byusername"_n, const_mem_fun<property, uint64_t, &property::by_username>>,
51 indexed_by<"byhash"_n, const_mem_fun<property, checksum256, &property::by_property_hash>>,
52 indexed_by<"byprojhash"_n, const_mem_fun<property, checksum256, &property::by_project_hash>>
54
61 inline std::optional<property> get_property(eosio::name coopname, const checksum256 &hash) {
62 property_index properties(_capital, coopname.value);
63 auto property_hash_index = properties.get_index<"byhash"_n>();
64
65 auto itr = property_hash_index.find(hash);
66 if (itr == property_hash_index.end()) {
67 return std::nullopt;
68 }
69
70 return property(*itr);
71}
72
79 inline property get_property_or_fail(eosio::name coopname, const checksum256 &hash) {
80 auto property = get_property(coopname, hash);
81 eosio::check(property.has_value(), "Предложение по имущественному взносу не найдено");
82
83 return property.value();
84}
85
91inline void delete_property(eosio::name coopname, uint64_t property_id) {
92 property_index properties(_capital, coopname.value);
93 auto property = properties.find(property_id);
94 eosio::check(property != properties.end(), "Предложение по имущественному взносу не найдено");
95
96 properties.erase(property);
97}
98
109 eosio::name coopname,
110 eosio::name username,
111 checksum256 project_hash,
112 checksum256 property_hash,
113 const eosio::asset &property_amount,
114 const std::string &property_description
115) {
116 // Создаем предложение
117 property_index properties(_capital, coopname.value);
118 auto property_id = get_global_id_in_scope(_capital, coopname, "properties"_n);
119
120 // Создаем предложение в таблице properties
121 properties.emplace(coopname, [&](auto &p) {
122 p.id = property_id;
124 p.coopname = coopname;
125 p.username = username;
126 p.project_hash = project_hash;
127 p.property_hash = property_hash;
128 p.property_amount = property_amount;
129 p.property_description = property_description;
130 p.created_at = current_time_point();
131 });
132
133 // Создаем пустой документ
134 auto empty_doc = document2{};
135
136 // Отправляем на approve председателю
138 _capital,
139 coopname,
140 username,
141 empty_doc,
143 property_hash,
144 _capital,
147 std::string("")
148 );
149}
150
151} // namespace Capital::ProjectProperties
static constexpr eosio::name _capital
Definition: consts.hpp:150
contract
Definition: eosio.msig_tests.cpp:977
constexpr eosio::name CREATED
Имущественный взнос создан
Definition: project_properties.hpp:17
Definition: project_properties.hpp:9
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:53
std::optional< property > get_property(eosio::name coopname, const checksum256 &hash)
Получает предложение по хэшу.
Definition: project_properties.hpp:61
property get_property_or_fail(eosio::name coopname, const checksum256 &hash)
Получает предложение по хэшу или падает с ошибкой.
Definition: project_properties.hpp:79
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:108
void delete_property(eosio::name coopname, uint64_t property_id)
Удаляет предложение по ID.
Definition: project_properties.hpp:91
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:113
void create_approval(name calling_contract, CREATEAPPRV_SIGNATURE)
Definition: soviet.hpp:60
Definition: eosio.msig.hpp:34
Таблица имущественных взносов хранит данные о предложениях по имущественным взносам в проекты.
Definition: project_properties.hpp:31
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: project_properties.hpp:43
name status
Статус предложения (created)
Definition: project_properties.hpp:35
name coopname
Имя кооператива
Definition: project_properties.hpp:33
checksum256 project_hash
Хэш проекта, связанного с предложением
Definition: project_properties.hpp:36
checksum256 by_project_hash() const
Индекс по хэшу проекта (4)
Definition: project_properties.hpp:45
uint64_t primary_key() const
Первичный ключ (1)
Definition: project_properties.hpp:42
checksum256 property_hash
Хэш предложения
Definition: project_properties.hpp:37
uint64_t id
ID имущественного взноса (внутренний ключ)
Definition: project_properties.hpp:32
eosio::asset property_amount
Оценочная стоимость имущества
Definition: project_properties.hpp:38
std::string property_description
Описание имущества
Definition: project_properties.hpp:39
checksum256 by_property_hash() const
Индекс по хэшу предложения (3)
Definition: project_properties.hpp:44
time_point_sec created_at
Время создания предложения
Definition: project_properties.hpp:40
name username
Имя пользователя, подающего предложение
Definition: project_properties.hpp:34
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:58