3#include <eosio/eosio.hpp>
4#include <eosio/asset.hpp>
17#define CREATEDEBT_SIGNATURE name coopname, name username, checksum256 debt_hash, time_point_sec repaid_at, asset quantity
18#define SETTLEDEBT_SIGNATURE name coopname, name username, checksum256 debt_hash, asset quantity
26 using namespace eosio;
48 uint64_t
by_created()
const {
return created_at.sec_since_epoch(); }
49 uint64_t
by_repaid()
const {
return repaid_at.sec_since_epoch(); }
55 indexed_by<
"byusername"_n, const_mem_fun<debt, uint64_t, &debt::by_username>>,
56 indexed_by<
"bydebthash"_n, const_mem_fun<debt, checksum256, &debt::by_debt_hash>>,
57 indexed_by<
"bycreated"_n, const_mem_fun<debt, uint64_t, &debt::by_created>>,
58 indexed_by<
"byrepaid"_n, const_mem_fun<debt, uint64_t, &debt::by_repaid>>
84 inline std::optional<debt>
get_debt(name coopname,
const checksum256& debt_hash) {
86 auto by_hash = debts.get_index<
"bydebthash"_n>();
87 auto it = by_hash.find(debt_hash);
88 if (it == by_hash.end())
return std::nullopt;
98 inline std::optional<summary>
get_summary(name coopname, name username) {
100 auto it = summaries.find(username.value);
101 if (it == summaries.end())
return std::nullopt;
113 auto by_repaid = debts.get_index<
"byrepaid"_n>();
115 uint32_t now = time_point_sec(current_time_point()).sec_since_epoch();
117 for (
auto itr = by_repaid.begin(); itr != by_repaid.end() && itr->repaid_at.sec_since_epoch() <= now; ++itr) {
118 if (itr->username == username) {
119 eosio::check(
false,
"У пользователя есть просроченные долги");
134 name calling_contract,
138 Action::send<createdebt_interface>(
159 name calling_contract,
162 Action::send<settledebt_interface>(
static constexpr eosio::name _loan
Definition: consts.hpp:161
contract
Definition: eosio.msig_tests.cpp:977
#define CREATEDEBT_SIGNATURE
Сигнатуры действий контракта loan.
Definition: shared_loan.hpp:17
Definition: shared_loan.hpp:25
std::optional< debt > get_debt(name coopname, const checksum256 &debt_hash)
Получает долговое обязательство по хэшу.
Definition: shared_loan.hpp:84
multi_index<"summaries"_n, summary > summaries_index
Definition: shared_loan.hpp:76
void settle_debt(name calling_contract, SETTLEDEBT_SIGNATURE)
Погашает долговое обязательство пайщика.
Definition: shared_loan.hpp:158
multi_index< "debts"_n, debt, indexed_by<"byusername"_n, const_mem_fun< debt, uint64_t, &debt::by_username > >, indexed_by<"bydebthash"_n, const_mem_fun< debt, checksum256, &debt::by_debt_hash > >, indexed_by<"bycreated"_n, const_mem_fun< debt, uint64_t, &debt::by_created > >, indexed_by<"byrepaid"_n, const_mem_fun< debt, uint64_t, &debt::by_repaid > > > debts_index
Definition: shared_loan.hpp:59
void assert_no_expired_debts(name coopname, name username)
Проверяет отсутствие просроченных долгов у пользователя.
Definition: shared_loan.hpp:111
void create_debt(name calling_contract, CREATEDEBT_SIGNATURE)
Создает долговое обязательство пайщика.
Definition: shared_loan.hpp:133
std::optional< summary > get_summary(name coopname, name username)
Получает сводку по долгам пользователя.
Definition: shared_loan.hpp:98
constexpr eosio::name CREATE_DEBT
Definition: shared_names.hpp:73
constexpr eosio::name SETTLE_DEBT
Definition: shared_names.hpp:74
Definition: eosio.msig.hpp:34
#define SETTLEDEBT_SIGNATURE
Definition: shared_loan.hpp:18
void(SETTLEDEBT_SIGNATURE) settledebt_interface
Definition: shared_loan.hpp:22
void(CREATEDEBT_SIGNATURE) createdebt_interface
Definition: shared_loan.hpp:21
Структура долгового обязательства.
Definition: shared_loan.hpp:36
checksum256 debt_hash
Хэш долгового обязательства
Definition: shared_loan.hpp:40
asset amount
Сумма долга
Definition: shared_loan.hpp:41
name coopname
Имя кооператива
Definition: shared_loan.hpp:38
uint64_t by_username() const
Definition: shared_loan.hpp:46
uint64_t by_created() const
Definition: shared_loan.hpp:48
checksum256 by_debt_hash() const
Definition: shared_loan.hpp:47
time_point_sec repaid_at
Срок погашения долга
Definition: shared_loan.hpp:43
uint64_t primary_key() const
Definition: shared_loan.hpp:45
name username
Имя пользователя-должника
Definition: shared_loan.hpp:39
time_point_sec created_at
Время создания долга
Definition: shared_loan.hpp:42
uint64_t by_repaid() const
Definition: shared_loan.hpp:49
uint64_t id
Идентификатор долга
Definition: shared_loan.hpp:37
Структура сводки по долгам пользователя.
Definition: shared_loan.hpp:69
name username
Имя пользователя
Definition: shared_loan.hpp:70
asset total
Общая сумма долгов пользователя
Definition: shared_loan.hpp:71
uint64_t primary_key() const
Definition: shared_loan.hpp:73
Definition: shared_debts.hpp:1