COOPENOMICS  v1
Кооперативная Экономика
program_invests.hpp
См. документацию.
1#pragma once
2
3using namespace eosio;
4using std::string;
5
13 namespace Status {
14 const eosio::name CREATED = "created"_n;
15 }
16}
17
18namespace Capital {
19
28 struct [[eosio::table, eosio::contract(CAPITAL)]] program_invest {
29 uint64_t id;
30 eosio::name coopname;
31 eosio::name username;
32 checksum256 invest_hash;
33 eosio::name status;
34 time_point_sec invested_at;
36 eosio::asset amount;
37
38 uint64_t primary_key() const { return id; }
39 uint64_t by_username() const { return username.value; }
40 checksum256 by_hash() const { return invest_hash; }
41 };
42
43typedef eosio::multi_index<
44 "progrinvests"_n, program_invest,
45 indexed_by<"byusername"_n, const_mem_fun<program_invest, uint64_t, &program_invest::by_username>>,
46 indexed_by<"byhash"_n, const_mem_fun<program_invest, checksum256, &program_invest::by_hash>>
48
49namespace ProgramInvests {
50
57 inline std::optional<program_invest> get_program_invest(eosio::name coopname, const checksum256& invest_hash) {
58 program_invest_index program_invests(_capital, coopname.value);
59 auto invest_hash_index = program_invests.get_index<"byhash"_n>();
60 auto itr = invest_hash_index.find(invest_hash);
61
62 if (itr != invest_hash_index.end()) {
63 return *itr;
64 }
65
66 return std::nullopt;
67 }
68
75 inline program_invest get_program_invest_or_fail(eosio::name coopname, const checksum256& invest_hash) {
76 auto invest = get_program_invest(coopname, invest_hash);
77 eosio::check(invest.has_value(), "Программная инвестиция с указанным хэшем не найдена");
78 return *invest;
79 }
80
90 eosio::name coopname,
91 eosio::name username,
92 checksum256 invest_hash,
93 eosio::asset amount,
94 document2 statement
95 ) {
96 // Создаем программную инвестицию
97 program_invest_index program_invests(_capital, coopname.value);
98 uint64_t invest_id = get_global_id_in_scope(_capital, coopname, "progrinvests"_n);
99
100 program_invests.emplace(coopname, [&](auto &i){
101 i.id = invest_id;
102 i.coopname = coopname;
103 i.username = username;
104 i.invest_hash = invest_hash;
106 i.invested_at = current_time_point();
107 i.statement = statement;
108 i.amount = amount;
109 });
110
111 // Отправляем на approve председателю
113 _capital,
114 coopname,
115 username,
116 statement,
118 invest_hash,
119 _capital,
122 std::string("")
123 );
124 }
125
131 inline void remove_program_invest(eosio::name coopname, const checksum256& invest_hash) {
132 program_invest_index program_invests(_capital, coopname.value);
133 auto invest_hash_index = program_invests.get_index<"byhash"_n>();
134 auto itr = invest_hash_index.find(invest_hash);
135
136 eosio::check(itr != invest_hash_index.end(), "Программная инвестиция для удаления не найдена");
137 invest_hash_index.erase(itr);
138 }
139
140} // namespace ProgramInvests
141
142} // namespace Capital
static constexpr eosio::name _capital
Definition: consts.hpp:150
contract
Definition: eosio.msig_tests.cpp:977
share_type amount
Definition: eosio.token_tests.cpp:174
uint64_t get_global_id_in_scope(eosio::name _me, eosio::name scope, eosio::name key)
Definition: counts.hpp:61
const eosio::name CREATED
Программная инвестиция создана
Definition: program_invests.hpp:14
Definition: program_invests.hpp:6
void remove_program_invest(eosio::name coopname, const checksum256 &invest_hash)
Удаляет программную инвестицию после обработки.
Definition: program_invests.hpp:131
program_invest get_program_invest_or_fail(eosio::name coopname, const checksum256 &invest_hash)
Получает программную инвестицию по хэшу или завершает выполнение с ошибкой.
Definition: program_invests.hpp:75
void create_program_invest_with_approve(eosio::name coopname, eosio::name username, checksum256 invest_hash, eosio::asset amount, document2 statement)
Создает программную инвестицию и отправляет её на утверждение.
Definition: program_invests.hpp:89
std::optional< program_invest > get_program_invest(eosio::name coopname, const checksum256 &invest_hash)
Получает программную инвестицию по хэшу.
Definition: program_invests.hpp:57
Definition: balances.cpp:6
eosio::multi_index< "progrinvests"_n, program_invest, indexed_by<"byusername"_n, const_mem_fun< program_invest, uint64_t, &program_invest::by_username > >, indexed_by<"byhash"_n, const_mem_fun< program_invest, checksum256, &program_invest::by_hash > > > program_invest_index
Definition: program_invests.hpp:47
constexpr eosio::name CREATE_PROGRAM_INVESTMENT
Definition: shared_names.hpp:109
constexpr eosio::name DECLINE_PROGRAM_INVESTMENT
Definition: shared_names.hpp:44
constexpr eosio::name APPROVE_PROGRAM_INVESTMENT
Definition: shared_names.hpp:43
void create_approval(name calling_contract, CREATEAPPRV_SIGNATURE)
Создаёт аппрув в совете
Definition: shared_soviet.hpp:73
Definition: eosio.msig.hpp:34
Таблица инвестиций хранит данные о вложениях в проекты.
Definition: invests.hpp:27
Таблица программных инвестиций хранит данные об инвестициях в программу капитализации.
Definition: program_invests.hpp:28
checksum256 by_hash() const
Индекс по хэшу инвестиции (3)
Definition: program_invests.hpp:40
document2 statement
Заявление на инвестицию
Definition: program_invests.hpp:35
checksum256 invest_hash
Хэш инвестиции
Definition: program_invests.hpp:32
eosio::name status
Статус инвестиции
Definition: program_invests.hpp:33
eosio::name username
Имя инвестора
Definition: program_invests.hpp:31
time_point_sec invested_at
Время создания инвестиции
Definition: program_invests.hpp:34
eosio::name coopname
Имя кооператива
Definition: program_invests.hpp:30
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: program_invests.hpp:39
uint64_t primary_key() const
Первичный ключ (1)
Definition: program_invests.hpp:38
uint64_t id
ID программной инвестиции (внутренний ключ)
Definition: program_invests.hpp:29
eosio::asset amount
Сумма инвестиции
Definition: program_invests.hpp:36
Definition: drafts.hpp:28