1#include <xrpld/app/tx/detail/LoanBrokerDelete.h>
3#include <xrpld/app/misc/LendingHelpers.h>
16 if (ctx.
tx[sfLoanBrokerID] == beast::zero)
25 auto const& tx = ctx.
tx;
27 auto const account = tx[sfAccount];
28 auto const brokerID = tx[sfLoanBrokerID];
33 JLOG(ctx.
j.
warn()) <<
"LoanBroker does not exist.";
37 auto const brokerOwner = sleBroker->at(sfOwner);
39 if (account != brokerOwner)
41 JLOG(ctx.
j.
warn()) <<
"Account is not the owner of the LoanBroker.";
44 if (
auto const ownerCount = sleBroker->at(sfOwnerCount); ownerCount != 0)
46 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Owner count is " << ownerCount;
49 if (
auto const debtTotal = sleBroker->at(sfDebtTotal);
50 debtTotal != beast::zero)
58 auto const asset = vault->at(sfAsset);
64 if (rounded != beast::zero)
67 JLOG(ctx.
j.
warn()) <<
"LoanBrokerDelete: Debt total is "
68 << debtTotal <<
", which rounds to " << rounded;
78 JLOG(ctx.
j.
fatal()) <<
"Vault is missing for Broker " << brokerID;
83 Asset const asset = vault->at(sfAsset);
85 auto const coverAvailable =
86 STAmount{asset, sleBroker->at(sfCoverAvailable)};
89 if (coverAvailable > beast::zero)
93 JLOG(ctx.
j.
warn()) <<
"Broker owner account is frozen.";
106 auto const brokerID = tx[sfLoanBrokerID];
112 auto const vaultID = broker->at(sfVaultID);
116 auto const vaultPseudoID = sleVault->at(sfAccount);
117 auto const vaultAsset = sleVault->at(sfAsset);
119 auto const brokerPseudoID = broker->at(sfAccount);
121 if (!
view().dirRemove(
123 broker->at(sfOwnerNode),
129 if (!
view().dirRemove(
131 broker->at(sfVaultNode),
139 auto const coverAvailable =
140 STAmount{vaultAsset, broker->at(sfCoverAvailable)};
155 if (!brokerPseudoSLE)
160 if (*brokerPseudoSLE->at(sfBalance))
162 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account has a balance";
165 if (brokerPseudoSLE->at(sfOwnerCount) != 0)
168 <<
"LoanBrokerDelete: Pseudo-account still owns objects";
174 JLOG(
j_.
warn()) <<
"LoanBrokerDelete: Pseudo-account has 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 NotTEC preflight(PreflightContext const &ctx)
static bool checkExtraFeatures(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 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.
TER checkDeepFrozen(ReadView const &view, AccountID const &account, Issue const &issue)
TER removeEmptyHolding(ApplyView &view, AccountID const &accountID, Issue const &issue, beast::Journal journal)
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)
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
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.