COOPENOMICS  v1
Кооперативная Экономика
table_marketplace_invest.hpp
См. документацию.
1#pragma once
2
3#include "../core/ram_payer.hpp"
4#include <eosio/asset.hpp>
5#include <eosio/binary_extension.hpp>
6#include <eosio/crypto.hpp>
7#include <eosio/eosio.hpp>
8#include <eosio/time.hpp>
9
10#include "../consts.hpp"
11#include "../core/utils.hpp"
12#include "document_core.hpp"
13
40namespace MarketInvest {
41
43static constexpr uint64_t SCALE = 1'000'000'000'000ULL;
45static constexpr uint64_t OUT_OF_RANGE = UINT64_MAX;
46
47namespace Status {
48 static constexpr eosio::name ACTIVE = "active"_n;
49 static constexpr eosio::name DONE = "done"_n;
50}
51
52namespace PropertyStatus {
53 static constexpr eosio::name CREATED = "created"_n;
54 static constexpr eosio::name APPROVED = "approved"_n;
55 static constexpr eosio::name AUTHORIZED = "authorized"_n;
56 static constexpr eosio::name ACT1 = "act1"_n;
57}
58
59} // namespace MarketInvest
60
72struct [[eosio::table, eosio::contract(MARKETPLACE)]] mkt_invagreement {
73 uint64_t id;
74 eosio::name username;
75 eosio::name braname;
76 eosio::time_point_sec signed_at;
78
79 uint64_t primary_key() const { return id; }
81 uint128_t by_user_branch() const { return combine_ids(username.value, braname.value); }
82 uint64_t by_branch() const { return braname.value; }
83};
84
85typedef eosio::multi_index<
86 "invagrbranch"_n, mkt_invagreement,
87 eosio::indexed_by<"byuserbr"_n, eosio::const_mem_fun<mkt_invagreement, uint128_t, &mkt_invagreement::by_user_branch>>,
88 eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun<mkt_invagreement, uint64_t, &mkt_invagreement::by_branch>>
91
108struct [[eosio::table, eosio::contract(MARKETPLACE)]] mkt_invbranch {
109 eosio::name braname;
110 eosio::asset money_total;
111 eosio::asset property_total;
112 eosio::asset unused_total;
113 eosio::asset reserved;
114 eosio::asset spent_total;
115 eosio::asset repaid_total;
116 eosio::asset surplus_total;
117 int64_t base = 0;
118 uint64_t acc = 0;
119 uint128_t s_join = 0;
120 int64_t s_fixed = 0;
121 uint64_t join_seq = 0;
126 eosio::binary_extension<int64_t> base_money;
127
128 uint64_t primary_key() const { return braname.value; }
129 int64_t base_money_or_zero() const { return base_money.has_value() ? base_money.value() : 0; }
130};
131
132typedef eosio::multi_index<"invbranches"_n, mkt_invbranch> mkt_invbranches_index;
134
143struct [[eosio::table, eosio::contract(MARKETPLACE)]] mkt_investor {
144 uint64_t id;
145 eosio::name braname;
146 eosio::name username;
147 eosio::name status;
148 eosio::asset money;
149 eosio::asset property;
150 eosio::asset used_money;
151 eosio::asset claimed;
152 int64_t returned_fixed = 0;
153 uint64_t acc_join = 0;
154 uint64_t acc_done = 0;
155 uint64_t join_seq = 0;
156 eosio::time_point_sec joined_at;
160 eosio::binary_extension<eosio::asset> money_in;
161
162 uint64_t primary_key() const { return id; }
163 uint64_t by_branch() const { return braname.value; }
164 uint64_t by_user() const { return username.value; }
165 uint128_t by_branch_user() const { return combine_ids(braname.value, username.value); }
166
167 int64_t units() const { return used_money.amount + property.amount; }
169 eosio::asset money_in_or_current() const { return money_in.has_value() ? money_in.value() : money; }
170 int64_t unused() const { return money.amount - used_money.amount; }
171
174 uint128_t by_unused() const {
175 const bool in_queue = unused() > 0;
176 return combine_ids(braname.value, in_queue ? join_seq : MarketInvest::OUT_OF_RANGE);
177 }
179 uint128_t by_done() const {
180 const bool in_base = status == MarketInvest::Status::ACTIVE && units() > 0;
181 return combine_ids(braname.value, in_base ? acc_done : MarketInvest::OUT_OF_RANGE);
182 }
183};
184
185typedef eosio::multi_index<
186 "investors"_n, mkt_investor,
187 eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun<mkt_investor, uint64_t, &mkt_investor::by_branch>>,
188 eosio::indexed_by<"byuser"_n, eosio::const_mem_fun<mkt_investor, uint64_t, &mkt_investor::by_user>>,
189 eosio::indexed_by<"bybruser"_n, eosio::const_mem_fun<mkt_investor, uint128_t, &mkt_investor::by_branch_user>>,
190 eosio::indexed_by<"byunused"_n, eosio::const_mem_fun<mkt_investor, uint128_t, &mkt_investor::by_unused>>,
191 eosio::indexed_by<"bydone"_n, eosio::const_mem_fun<mkt_investor, uint128_t, &mkt_investor::by_done>>
194
206struct [[eosio::table, eosio::contract(MARKETPLACE)]] mkt_invprop {
207 uint64_t id;
208 checksum256 hash;
209 eosio::name braname;
210 eosio::name username;
211 eosio::name status;
212 eosio::asset amount;
213 std::string description;
218 eosio::time_point_sec created_at;
219
220 uint64_t primary_key() const { return id; }
221 checksum256 by_hash() const { return hash; }
222 uint64_t by_branch() const { return braname.value; }
223 uint64_t by_user() const { return username.value; }
224};
225
226typedef eosio::multi_index<
227 "invprops"_n, mkt_invprop,
228 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<mkt_invprop, checksum256, &mkt_invprop::by_hash>>,
229 eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun<mkt_invprop, uint64_t, &mkt_invprop::by_branch>>,
230 eosio::indexed_by<"byuser"_n, eosio::const_mem_fun<mkt_invprop, uint64_t, &mkt_invprop::by_user>>
contract
Definition: eosio.msig_tests.cpp:977
static constexpr eosio::name ACT1
акт подписан вносящим
Definition: table_marketplace_invest.hpp:56
static constexpr eosio::name AUTHORIZED
совет принял решение о приёме
Definition: table_marketplace_invest.hpp:55
static constexpr eosio::name CREATED
заявление подано
Definition: table_marketplace_invest.hpp:53
static constexpr eosio::name APPROVED
председатель участка одобрил, вопрос на повестке совета
Definition: table_marketplace_invest.hpp:54
static constexpr eosio::name DONE
использованное возвращено, неиспользованное доступно к заявлению
Definition: table_marketplace_invest.hpp:49
static constexpr eosio::name ACTIVE
паевой взнос возвращается из экономии участка
Definition: table_marketplace_invest.hpp:48
Definition: invest.hpp:23
static constexpr uint64_t SCALE
Точность счётчика возврата: возвращено на единицу базы × SCALE.
Definition: table_marketplace_invest.hpp:43
static constexpr uint64_t OUT_OF_RANGE
Ключ индекса для строк вне выборки (нет неиспользованных денег / вне базы).
Definition: table_marketplace_invest.hpp:45
Definition: eosio.msig.hpp:34
Definition: document_core.hpp:27
Договор об участии в хозяйственной деятельности кооперативного участка (registry 1118)....
Definition: table_marketplace_invest.hpp:72
uint128_t by_user_branch() const
Пайщик и участок — один договор на пару.
Definition: table_marketplace_invest.hpp:81
uint64_t by_branch() const
Definition: table_marketplace_invest.hpp:82
eosio::name braname
кооперативный участок договора
Definition: table_marketplace_invest.hpp:75
document2 agreement
подписанный договор
Definition: table_marketplace_invest.hpp:77
eosio::name username
пайщик
Definition: table_marketplace_invest.hpp:74
eosio::time_point_sec signed_at
время подписи
Definition: table_marketplace_invest.hpp:76
uint64_t primary_key() const
Definition: table_marketplace_invest.hpp:79
uint64_t id
первичный ключ
Definition: table_marketplace_invest.hpp:73
Паевые взносы инициаторов одного кооперативного участка и счётчик возврата (CRPS)....
Definition: table_marketplace_invest.hpp:108
eosio::binary_extension< int64_t > base_money
Definition: table_marketplace_invest.hpp:126
eosio::asset reserved
выделено в пул под расходы и помощь и ещё не израсходовано
Definition: table_marketplace_invest.hpp:113
eosio::asset unused_total
деньги инициаторов, ещё не израсходованные из пула и не забранные заявлением
Definition: table_marketplace_invest.hpp:112
eosio::asset surplus_total
переплата на границе завершения возврата, переданная на w.brn.common
Definition: table_marketplace_invest.hpp:116
eosio::name braname
кооперативный участок (первичный ключ)
Definition: table_marketplace_invest.hpp:109
eosio::asset money_total
внесено деньгами по строкам инициаторов участка (за вычетом забранного неиспользованного)
Definition: table_marketplace_invest.hpp:110
int64_t base_money_or_zero() const
Definition: table_marketplace_invest.hpp:129
eosio::asset property_total
внесено имуществом по цене приёма
Definition: table_marketplace_invest.hpp:111
eosio::asset repaid_total
возмещено из экономии участка на w.mkt.repay всего
Definition: table_marketplace_invest.hpp:115
uint64_t primary_key() const
Definition: table_marketplace_invest.hpp:128
eosio::asset spent_total
оплачено из пула всего
Definition: table_marketplace_invest.hpp:114
Инициатор кооперативного участка: одна строка на пару «участок — пайщик».
Definition: table_marketplace_invest.hpp:143
uint64_t by_branch() const
Definition: table_marketplace_invest.hpp:163
eosio::asset used_money
из денег израсходовано пулом участка
Definition: table_marketplace_invest.hpp:150
eosio::asset money
внесено деньгами (за вычетом забранного неиспользованного)
Definition: table_marketplace_invest.hpp:148
eosio::time_point_sec joined_at
Definition: table_marketplace_invest.hpp:156
eosio::asset claimed
забрано из возвращённого заявлениями (без неиспользованного)
Definition: table_marketplace_invest.hpp:151
eosio::name braname
кооперативный участок
Definition: table_marketplace_invest.hpp:145
uint128_t by_branch_user() const
Definition: table_marketplace_invest.hpp:165
uint128_t by_unused() const
Definition: table_marketplace_invest.hpp:174
eosio::name status
active | done (done с нулевым остатком — возмещено полностью)
Definition: table_marketplace_invest.hpp:147
eosio::asset property
внесено имуществом по цене приёма
Definition: table_marketplace_invest.hpp:149
uint64_t primary_key() const
Definition: table_marketplace_invest.hpp:162
uint64_t by_user() const
Definition: table_marketplace_invest.hpp:164
eosio::binary_extension< eosio::asset > money_in
Definition: table_marketplace_invest.hpp:160
int64_t units() const
Definition: table_marketplace_invest.hpp:167
eosio::name username
пайщик-инициатор
Definition: table_marketplace_invest.hpp:146
int64_t unused() const
Definition: table_marketplace_invest.hpp:170
uint128_t by_done() const
Очередь завершения: активные в базе по счётчику полного возврата.
Definition: table_marketplace_invest.hpp:179
uint64_t id
суррогатный ключ
Definition: table_marketplace_invest.hpp:144
eosio::asset money_in_or_current() const
Внесено деньгами всего; у строки прежней сборки — текущий остаток денег.
Definition: table_marketplace_invest.hpp:169
Заявление инициатора о паевом взносе имуществом в кооперативный участок (registry 1120) до второй под...
Definition: table_marketplace_invest.hpp:206
eosio::name username
вносящий пайщик
Definition: table_marketplace_invest.hpp:210
document2 approved_statement
то же заявление с подписью председателя участка
Definition: table_marketplace_invest.hpp:215
document2 act
акт приёма-передачи 1122
Definition: table_marketplace_invest.hpp:217
uint64_t by_user() const
Definition: table_marketplace_invest.hpp:223
std::string description
наименование, описание, количество
Definition: table_marketplace_invest.hpp:213
eosio::asset amount
цена приёма, названная вносящим
Definition: table_marketplace_invest.hpp:212
eosio::name status
created | approved | authorized | act1
Definition: table_marketplace_invest.hpp:211
uint64_t primary_key() const
Definition: table_marketplace_invest.hpp:220
uint64_t by_branch() const
Definition: table_marketplace_invest.hpp:222
eosio::time_point_sec created_at
время подачи
Definition: table_marketplace_invest.hpp:218
checksum256 by_hash() const
Definition: table_marketplace_invest.hpp:221
checksum256 hash
хэш паевого взноса имуществом (процесс p.mkt.invest)
Definition: table_marketplace_invest.hpp:208
document2 decision
протокол решения совета 1121
Definition: table_marketplace_invest.hpp:216
eosio::name braname
кооперативный участок
Definition: table_marketplace_invest.hpp:209
uint64_t id
суррогатный ключ
Definition: table_marketplace_invest.hpp:207
document2 statement
заявление 1120, подпись вносящего
Definition: table_marketplace_invest.hpp:214
eosio::multi_index<"invbranches"_n, mkt_invbranch > mkt_invbranches_index
Definition: table_marketplace_invest.hpp:132
RAM_PAYER_CLASS(mkt_invagreement, contract)
eosio::multi_index< "invprops"_n, mkt_invprop, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< mkt_invprop, checksum256, &mkt_invprop::by_hash > >, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< mkt_invprop, uint64_t, &mkt_invprop::by_branch > >, eosio::indexed_by<"byuser"_n, eosio::const_mem_fun< mkt_invprop, uint64_t, &mkt_invprop::by_user > > > mkt_invprops_index
Definition: table_marketplace_invest.hpp:231
eosio::multi_index< "invagrbranch"_n, mkt_invagreement, eosio::indexed_by<"byuserbr"_n, eosio::const_mem_fun< mkt_invagreement, uint128_t, &mkt_invagreement::by_user_branch > >, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< mkt_invagreement, uint64_t, &mkt_invagreement::by_branch > > > mkt_invagreements_index
Definition: table_marketplace_invest.hpp:89
eosio::multi_index< "investors"_n, mkt_investor, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< mkt_investor, uint64_t, &mkt_investor::by_branch > >, eosio::indexed_by<"byuser"_n, eosio::const_mem_fun< mkt_investor, uint64_t, &mkt_investor::by_user > >, eosio::indexed_by<"bybruser"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_branch_user > >, eosio::indexed_by<"byunused"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_unused > >, eosio::indexed_by<"bydone"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_done > > > mkt_investors_index
Definition: table_marketplace_invest.hpp:192
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y)
Definition: utils.hpp:7