1#include <xrpl/tx/transactors/lending/LoanBrokerDelete.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/LendingHelpers.h>
8#include <xrpl/ledger/helpers/TokenHelpers.h>
9#include <xrpl/protocol/Asset.h>
10#include <xrpl/protocol/Feature.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/STAmount.h>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/STTx.h>
16#include <xrpl/protocol/TER.h>
17#include <xrpl/protocol/XRPAmount.h>
18#include <xrpl/tx/Transactor.h>
40 auto const& tx = ctx.
tx;
42 auto const account = tx[sfAccount];
43 auto const brokerID = tx[sfLoanBrokerID];
48 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
52 auto const brokerOwner = sleBroker->at(sfOwner);
54 if (account != brokerOwner)
56 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
61 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Owner count is " <<
ownerCount;
69 JLOG(ctx.
j.
fatal()) <<
"Vault is missing for Broker " << brokerID;
74 Asset const asset = vault->at(sfAsset);
76 if (
auto const debtTotal = sleBroker->at(sfDebtTotal); debtTotal !=
beast::kZero)
88 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Debt total is " << debtTotal
89 <<
", which rounds to " << rounded;
95 auto const coverAvailable =
STAmount{asset, sleBroker->at(sfCoverAvailable)};
102 JLOG(ctx.
j.
warn()) <<
"Broker owner account is frozen.";
111 auto const brokerPseudo = sleBroker->at(sfAccount);
114 JLOG(ctx.
j.
warn()) <<
"Broker pseudo-account is frozen/locked.";
126 auto const& tx =
ctx_.tx;
128 auto const brokerID = tx[sfLoanBrokerID];
134 auto const vaultID = broker->at(sfVaultID);
138 auto const vaultPseudoID = sleVault->at(sfAccount);
139 auto const vaultAsset = sleVault->at(sfAsset);
141 auto const brokerPseudoID = broker->at(sfAccount);
143 if (!
view().dirRemove(
148 if (!
view().dirRemove(
149 keylet::ownerDir(vaultPseudoID), broker->at(sfVaultNode), broker->key(),
false))
155 auto const coverAvailable =
STAmount{vaultAsset, broker->at(sfCoverAvailable)};
165 if (!brokerPseudoSLE)
170 if (*brokerPseudoSLE->at(sfBalance))
172 JLOG(
j_.warn()) <<
"LoanBrokerDelete: Pseudo-account has a balance";
175 if (brokerPseudoSLE->at(sfOwnerCount) != 0)
177 JLOG(
j_.warn()) <<
"LoanBrokerDelete: Pseudo-account still owns objects";
182 JLOG(
j_.warn()) <<
"LoanBrokerDelete: Pseudo-account has a directory";
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(SLE::ref sle)=0
Remove a peeked SLE.
static TER preclaim(PreclaimContext const &ctx)
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.
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const accountID_
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.
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
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.
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, SLE::ref sponsorSle={}, WaiveTransferFee waiveFee=WaiveTransferFee::No, AllowMPTOverflow allowOverflow=AllowMPTOverflow::No)
Calls static accountSendIOU if saAmount represents Issue.
TER removeEmptyHolding(ApplyViewContext ctx, AccountID const &accountID, MPTIssue const &mptIssue, beast::Journal journal)
int getAssetsTotalScale(SLE::const_ref vaultSle)
TER checkFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
int scale(Number const &number, Asset const &asset)
Get the scale of a Number for a given asset.
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
std::uint32_t ownerCount(SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj=0)
Return number of the objects which reserve is covered by the account(sle) (so called "ownercount").
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.