3#include <eosio/asset.hpp>
4#include <eosio/eosio.hpp>
8#include "../../consts.hpp"
9#include "../actions.hpp"
10#include "../names.hpp"
15#define CREATEDEBT_SIGNATURE name coopname, name username, checksum256 debt_hash, time_point_sec repaid_at, asset quantity
16#define SETTLEDEBT_SIGNATURE name coopname, name username, checksum256 debt_hash, asset quantity
23inline std::optional<debt>
get_debt(name coopname,
const checksum256 &debt_hash) {
25 auto by_hash = debts.get_index<
"bydebthash"_n>();
26 auto it = by_hash.find(debt_hash);
27 if (it == by_hash.end())
32inline std::optional<summary>
get_summary(name coopname, name username) {
34 auto it = summaries.find(username.value);
35 if (it == summaries.end())
42 auto by_repaid = debts.get_index<
"byrepaid"_n>();
44 uint32_t now = time_point_sec(current_time_point()).sec_since_epoch();
46 for (
auto itr = by_repaid.begin(); itr != by_repaid.end() && itr->repaid_at.sec_since_epoch() <= now;
48 if (itr->username == username) {
49 eosio::check(
false,
"У пользователя есть просроченные долги");
56 debt_hash, repaid_at, quantity);
static constexpr eosio::name _loan
Definition: consts.hpp:161
#define SETTLEDEBT_SIGNATURE
Definition: loan.hpp:16
void(SETTLEDEBT_SIGNATURE) settledebt_interface
Definition: loan.hpp:19
#define CREATEDEBT_SIGNATURE
Definition: loan.hpp:15
void(CREATEDEBT_SIGNATURE) createdebt_interface
Definition: loan.hpp:18
std::optional< debt > get_debt(name coopname, const checksum256 &debt_hash)
Definition: loan.hpp:23
multi_index<"summaries"_n, summary > summaries_index
Definition: table_loan_summaries.hpp:19
void settle_debt(name calling_contract, SETTLEDEBT_SIGNATURE)
Definition: loan.hpp:59
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: table_loan_debts.hpp:35
void assert_no_expired_debts(name coopname, name username)
Definition: loan.hpp:40
void create_debt(name calling_contract, CREATEDEBT_SIGNATURE)
Definition: loan.hpp:54
std::optional< summary > get_summary(name coopname, name username)
Definition: loan.hpp:32
constexpr eosio::name CREATE_DEBT
Definition: names.hpp:75
constexpr eosio::name SETTLE_DEBT
Definition: names.hpp:76
Definition: eosio.msig.hpp:34