1#include <xrpld/app/tx/detail/LoanDelete.h>
3#include <xrpld/app/misc/LendingHelpers.h>
16 if (ctx.
tx[sfLoanID] == beast::zero)
25 auto const& tx = ctx.
tx;
27 auto const account = tx[sfAccount];
28 auto const loanID = tx[sfLoanID];
33 JLOG(ctx.
j.
warn()) <<
"Loan does not exist.";
36 if (loanSle->at(sfPaymentRemaining) > 0)
38 JLOG(ctx.
j.
warn()) <<
"Active loan can not be deleted.";
42 auto const loanBrokerID = loanSle->at(sfLoanBrokerID);
49 if (loanBrokerSle->at(sfOwner) != account &&
50 loanSle->at(sfBorrower) != account)
53 <<
"Account is not Loan Broker Owner or Loan Borrower.";
66 auto const loanID = tx[sfLoanID];
70 auto const borrower = loanSle->at(sfBorrower);
75 auto const brokerID = loanSle->at(sfLoanBrokerID);
79 auto const brokerPseudoAccount = brokerSle->at(sfAccount);
81 auto const vaultSle =
view.
peek(keylet ::vault(brokerSle->at(sfVaultID)));
88 loanSle->at(sfLoanBrokerNode),
95 loanSle->at(sfOwnerNode),
109 if (brokerSle->at(sfOwnerCount) == 0)
111 auto debtTotalProxy = brokerSle->at(sfDebtTotal);
112 if (*debtTotalProxy != beast::zero)
116 vaultSle->at(sfAsset),
120 "xrpl::LoanDelete::doApply",
121 "last loan, remaining debt rounds to zero");
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER preclaim(PreclaimContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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 account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Number roundToAsset(A const &asset, Number const &value, std::int32_t scale, Number::rounding_mode rounding=Number::getround())
Round an arbitrary precision Number to the precision of a given Asset.
bool checkLendingProtocolDependencies(PreflightContext const &ctx)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
int getVaultScale(SLE::const_ref vaultSle)
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.