minor code improvements

This commit is contained in:
Vito
2026-02-17 13:33:47 +01:00
parent 087a9c1cf3
commit 82b0d57aac
5 changed files with 17 additions and 5 deletions

View File

@@ -985,6 +985,11 @@ sharesToAssetsWithdraw(
std::shared_ptr<SLE const> const& issuance,
STAmount const& shares);
// Determine if a vault is insolvent. A vault is considered insolvent when
// the total assets in the vault are zero, and outstanding shares are non-zero.
[[nodiscard]] bool
isVaultInsolvent(std::shared_ptr<SLE const> const& vault, std::shared_ptr<SLE const> const& shareIssuance);
/** Has the specified time passed?
@param now the current time

View File

@@ -270,13 +270,11 @@ constexpr std::uint32_t const tfBatchMask =
// LoanPay: True, indicates any excess in this payment can be used
// as an overpayment. False, no overpayments will be taken.
constexpr std::uint32_t const tfLoanOverpayment = 0x00010000;
// LoanPay exclusive flags:
// tfLoanFullPayment: True, indicates that the payment is an early
// full payment. It must pay the entire loan including close
// interest and fees, or it will fail. False: Not a full payment.
constexpr std::uint32_t const tfLoanFullPayment = 0x00020000;
// tfLoanLatePayment: True, indicates that the payment is late,
// and includes late interest and fees. If the loan is not late,
// it will fail. False: not a late payment. If the current payment

View File

@@ -3438,4 +3438,13 @@ after(NetClock::time_point now, std::uint32_t mark)
return now.time_since_epoch().count() > mark;
}
[[nodiscard]] bool
isVaultInsolvent(std::shared_ptr<SLE const> const& vault, std::shared_ptr<SLE const> const& shareIssuance)
{
auto const assetsTotal = vault->at(sfAssetsTotal);
auto const sharesOutstanding = shareIssuance->at(sfOutstandingAmount);
return assetsTotal == 0 && sharesOutstanding > 0;
}
} // namespace xrpl

View File

@@ -82,7 +82,7 @@ VaultDeposit::preclaim(PreclaimContext const& ctx)
// Perform these checks early to avoid unnecessary processing
// The Vault is insolvent, deposits are not allowed
if (vault->at(sfAssetsTotal) == 0 && sleShareIssuance->at(sfOutstandingAmount) > 0)
if (isVaultInsolvent(vault, sleShareIssuance))
{
JLOG(ctx.j.debug()) << "VaultDeposit: Vault is insolvent, deposits are not allowed";
return tecNO_PERMISSION;

View File

@@ -35,13 +35,13 @@ VaultSet::getFlagsMask(PreflightContext const& ctx)
static bool
isValidVaultUpdate(PreflightContext const& ctx)
{
auto const checkFlags = ctx.rules.enabled(fixLendingProtocolV1_1);
auto const shouldCheckFlags = ctx.rules.enabled(fixLendingProtocolV1_1);
auto const atLeastOneFieldPresent =
ctx.tx.isFieldPresent(sfDomainID) || ctx.tx.isFieldPresent(sfAssetsMaximum) || ctx.tx.isFieldPresent(sfData);
return atLeastOneFieldPresent ||
(checkFlags && (ctx.tx.isFlag(tfVaultDepositBlock) || ctx.tx.isFlag(tfVaultDepositUnblock)));
(shouldCheckFlags && (ctx.tx.isFlag(tfVaultDepositBlock) || ctx.tx.isFlag(tfVaultDepositUnblock)));
}
NotTEC