1#include <xrpl/tx/invariants/LoanInvariant.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/helpers/VaultHelpers.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STNumber.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/XRPAmount.h>
65 JLOG(j.
fatal()) <<
"Invariant failed: closed-ended loan final payment "
66 "must precede RedemptionDate";
75 if (
after->at(sfPaymentRemaining) == 0 &&
80 JLOG(j.
fatal()) <<
"Invariant failed: Loan with zero payments "
81 "remaining has not been paid off";
86 if (
after->at(sfPaymentRemaining) != 0 &&
91 JLOG(j.
fatal()) <<
"Invariant failed: Fully paid off Loan still has payments remaining";
94 if (before && (before->isFlag(lsfLoanOverpayment) !=
after->isFlag(lsfLoanOverpayment)))
96 JLOG(j.
fatal()) <<
"Invariant failed: Loan Overpayment flag changed";
100 for (
auto const field :
104 &sfPrincipalOutstanding,
105 &sfTotalValueOutstanding,
106 &sfManagementFeeOutstanding})
108 if (
after->at(*field) < 0)
110 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName() <<
" is negative ";
115 for (
auto const field : {
119 if (
after->at(*field) <= 0)
121 JLOG(j.
fatal()) <<
"Invariant failed: " << field->getName()
122 <<
" is zero or negative ";
A generic endpoint for log messages.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & const_ref
void visitEntry(bool, SLE::const_ref, SLE::const_ref)
std::vector< std::pair< SLE::const_pointer, SLE::const_pointer > > loans_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
VaultKind getVaultKind(SLE::const_ref vault)
Resolves the VaultKind of a vault SLE.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER