refactor: Move LendingHelpers into libxrpl/ledger/helpers (#6638)

Co-authored-by: xrplf-ai-reviewer[bot] <266832837+xrplf-ai-reviewer[bot]@users.noreply.github.com>
This commit is contained in:
Mayukha Vadari
2026-04-24 08:06:26 -04:00
committed by Bart
parent e34bf5bcee
commit f42915d61b
14 changed files with 38 additions and 29 deletions

View File

@@ -1,15 +1,14 @@
#pragma once
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/st.h>
namespace xrpl {
struct PreflightContext;
// Lending protocol has dependencies, so capture them here.
bool
checkLendingProtocolDependencies(PreflightContext const& ctx);
checkLendingProtocolDependencies(Rules const& rules, STTx const& tx);
static constexpr std::uint32_t secondsInYear = 365 * 24 * 60 * 60;

View File

@@ -1,7 +1,7 @@
#pragma once
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
namespace xrpl {

View File

@@ -1,4 +1,4 @@
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Log.h>
@@ -7,18 +7,19 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/LedgerFormats.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/STTx.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/Units.h>
#include <xrpl/tx/transactors/vault/VaultCreate.h>
#include <algorithm>
#include <cstddef>
@@ -28,9 +29,18 @@
namespace xrpl {
bool
checkLendingProtocolDependencies(PreflightContext const& ctx)
checkLendingProtocolDependencies(Rules const& rules, STTx const& tx)
{
return ctx.rules.enabled(featureSingleAssetVault) && VaultCreate::checkExtraFeatures(ctx);
if (!rules.enabled(featureSingleAssetVault))
return false;
if (!rules.enabled(featureMPTokensV1))
return false;
if (tx.isFieldPresent(sfDomainID) && !rules.enabled(featurePermissionedDomains))
return false;
return true;
}
LoanPaymentParts&

View File

@@ -7,6 +7,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
@@ -25,7 +26,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
#include <optional>
@@ -36,7 +36,7 @@ namespace xrpl {
bool
LoanBrokerCoverClawback::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -2,6 +2,7 @@
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/SField.h>
@@ -12,7 +13,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -21,7 +21,7 @@ namespace xrpl {
bool
LoanBrokerCoverDeposit::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -5,6 +5,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/Protocol.h>
@@ -17,7 +18,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -26,7 +26,7 @@ namespace xrpl {
bool
LoanBrokerCoverWithdraw::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -4,6 +4,7 @@
#include <xrpl/basics/Number.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Indexes.h>
@@ -15,7 +16,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -24,7 +24,7 @@ namespace xrpl {
bool
LoanBrokerDelete::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -6,6 +6,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Indexes.h>
@@ -18,7 +19,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
#include <vector>
@@ -28,7 +28,7 @@ namespace xrpl {
bool
LoanBrokerSet::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -5,6 +5,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STAmount.h> // IWYU pragma: keep
@@ -14,7 +15,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -23,7 +23,7 @@ namespace xrpl {
bool
LoanDelete::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -6,6 +6,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
@@ -22,7 +23,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <algorithm>
#include <cstdint>
@@ -33,7 +33,7 @@ namespace xrpl {
bool
LoanManage::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -8,6 +8,7 @@
#include <xrpl/json/to_string.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
@@ -23,7 +24,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/tx/transactors/lending/LoanManage.h>
#include <algorithm>
@@ -36,7 +36,7 @@ namespace xrpl {
bool
LoanPay::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -7,6 +7,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
@@ -25,7 +26,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <cstddef>
#include <cstdint>
@@ -40,7 +40,7 @@ namespace xrpl {
bool
LoanSet::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -6,8 +6,8 @@
#include <xrpl/basics/Number.h>
#include <xrpl/basics/chrono.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Units.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <cstdint>
#include <string>

View File

@@ -34,6 +34,7 @@
#include <xrpl/beast/xor_shift_engine.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/to_string.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/HashPrefix.h>
@@ -55,7 +56,6 @@
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/protocol/jss.h>
#include <xrpl/server/LoadFeeTrack.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/tx/transactors/lending/LoanSet.h>
#include <xrpl/tx/transactors/system/Batch.h>