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>
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))
114 if (brokerSle->at(sfOwnerCount) == 0)
116 auto debtTotalProxy = brokerSle->at(sfDebtTotal);
121 vaultSle->at(sfAsset),
125 "xrpl::LoanDelete::doApply",
126 "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 loan(uint256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void decreaseOwnerCountForObject(ApplyView &view, SLE::ref accountSle, SLE::ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
int getAssetsTotalScale(SLE::const_ref vaultSle)
void adjustLoanBrokerOwnerCount(ApplyView &view, SLE::ref brokerSle, std::int32_t delta, beast::Journal j)
Adjust a LoanBroker's owner count.
TERSubset< CanCvtToNotTEC > NotTEC
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.