1#include <xrpl/tx/transactors/lending/LoanDelete.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/LendingHelpers.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/STTakesAsset.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/XRPAmount.h>
17#include <xrpl/tx/Transactor.h>
30 if (ctx.
tx[sfLoanID] == beast::kZero)
39 auto const& tx = ctx.
tx;
41 auto const account = tx[sfAccount];
42 auto const loanID = tx[sfLoanID];
47 JLOG(ctx.
j.
warn()) <<
"Loan does not exist.";
50 if (loanSle->at(sfPaymentRemaining) > 0)
52 JLOG(ctx.
j.
warn()) <<
"Active loan can not be deleted.";
56 auto const loanBrokerID = loanSle->at(sfLoanBrokerID);
63 if (loanBrokerSle->at(sfOwner) != account && loanSle->at(sfBorrower) != account)
65 JLOG(ctx.
j.
warn()) <<
"Account is not Loan Broker Owner or Loan Borrower.";
75 auto const& tx =
ctx_.tx;
78 auto const loanID = tx[sfLoanID];
82 auto const borrower = loanSle->at(sfBorrower);
87 auto const brokerID = loanSle->at(sfLoanBrokerID);
91 auto const brokerPseudoAccount = brokerSle->at(sfAccount);
96 auto const vaultAsset = vaultSle->at(sfAsset);
100 keylet::ownerDir(brokerPseudoAccount), loanSle->at(sfLoanBrokerNode), loanID,
false))
115 if (brokerSle->at(sfOwnerCount) == 0)
117 auto debtTotalProxy = brokerSle->at(sfDebtTotal);
118 if (*debtTotalProxy != beast::kZero)
122 vaultSle->at(sfAsset),
126 "xrpl::LoanDelete::doApply",
127 "last loan, remaining debt rounds to zero");
A generic endpoint for log messages.
static TER preclaim(PreclaimContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static NotTEC preflight(PreflightContext const &ctx)
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
Keylet loanBroker(AccountID const &owner, std::uint32_t seq) noexcept
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet loan(uint256 const &loanBrokerID, std::uint32_t loanSeq) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
int getAssetsTotalScale(SLE::const_ref vaultSle)
TERSubset< CanCvtToNotTEC > NotTEC
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
void roundToAsset(A const &asset, Number &value)
Round an arbitrary precision Number IN PLACE to the precision of a given Asset.
TERSubset< CanCvtToTER > TER
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
bool checkLendingProtocolDependencies(Rules const &rules, STTx const &tx)
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.