From eb88c0ef6b8c0485ac3a4285b28bd60e3243da6b Mon Sep 17 00:00:00 2001 From: Oleksandr <115580134+oleks-rip@users.noreply.github.com> Date: Wed, 29 Apr 2026 14:15:30 -0400 Subject: [PATCH] Fix clang-format, some refactoring --- .../xrpl/ledger/helpers/AccountRootHelpers.h | 8 ++-- include/xrpl/protocol/LedgerFormats.h | 4 +- .../xrpl/tx/transactors/oracle/OracleSet.h | 7 ++- .../ledger/helpers/AccountRootHelpers.cpp | 16 +++---- src/libxrpl/tx/Transactor.cpp | 46 +++++++++++-------- .../tx/transactors/oracle/OracleSet.cpp | 6 --- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/xrpl/ledger/helpers/AccountRootHelpers.h b/include/xrpl/ledger/helpers/AccountRootHelpers.h index 6cf04d7e8c..92259913a2 100644 --- a/include/xrpl/ledger/helpers/AccountRootHelpers.h +++ b/include/xrpl/ledger/helpers/AccountRootHelpers.h @@ -40,15 +40,15 @@ xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, (ownerCount + "sponsoring object count" - "sponsored object count" + additionalOwnerCount) * increment + (1 if not sponsored account + sponsoringAccountCount) * "reserve base" */ -XRPAmount +[[nodiscard]] XRPAmount accountReserve( ReadView const& view, - std::shared_ptr const& sle, + SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj = 0, std::int32_t reserveCountAdj = 0); -inline XRPAmount +[[nodiscard]] inline XRPAmount accountReserve( ReadView const& view, AccountID const& id, @@ -76,7 +76,7 @@ checkInsufficientReserve( std::uint32_t ownerCount( ReadView const& view, - std::shared_ptr const& sle, + SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj = 0); diff --git a/include/xrpl/protocol/LedgerFormats.h b/include/xrpl/protocol/LedgerFormats.h index 78b0e751e9..92ef289ac8 100644 --- a/include/xrpl/protocol/LedgerFormats.h +++ b/include/xrpl/protocol/LedgerFormats.h @@ -137,7 +137,7 @@ enum LedgerEntryType : std::uint16_t { LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \ LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \ LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \ - LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \ + LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \ \ LEDGER_OBJECT(Offer, \ LSF_FLAG(lsfPassive, 0x00010000) \ @@ -203,7 +203,7 @@ enum LedgerEntryType : std::uint16_t { LSF_FLAG(lsfLoanImpaired, 0x00020000) \ LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */ \ \ - LEDGER_OBJECT(Sponsorship, \ + LEDGER_OBJECT(Sponsorship, \ LSF_FLAG(lsfSponsorshipRequireSignForFee, 0x00010000) \ LSF_FLAG(lsfSponsorshipRequireSignForReserve, 0x00020000)) diff --git a/include/xrpl/tx/transactors/oracle/OracleSet.h b/include/xrpl/tx/transactors/oracle/OracleSet.h index 30e15c9d3c..8ce8a81923 100644 --- a/include/xrpl/tx/transactors/oracle/OracleSet.h +++ b/include/xrpl/tx/transactors/oracle/OracleSet.h @@ -22,8 +22,11 @@ public: { } - static uint32_t - calculateOracleReserve(std::size_t count); + inline static uint32_t + calculateOracleReserve(std::size_t count) + { + return count > 5 ? 2 : 1; + } static NotTEC preflight(PreflightContext const& ctx); diff --git a/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp b/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp index e19a49286a..2e64ac6de4 100644 --- a/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp +++ b/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp @@ -88,7 +88,7 @@ confineOwnerCount( static std::uint32_t ownerCountHlp( ReadView const& view, - std::shared_ptr const& sle, + SLE::const_ref sle, std::int32_t adjustment, bool reportConfine, beast::Journal j) @@ -129,7 +129,7 @@ ownerCountHlp( } static std::uint32_t -reserveCountHlp(std::shared_ptr const& sle, std::int32_t adjustment, beast::Journal j) +reserveCountHlp(SLE::const_ref sle, std::int32_t adjustment, beast::Journal j) { bool const isSponsored = sle->isFieldPresent(sfSponsor); std::uint32_t const sponsoringCount = sle->getFieldU32(sfSponsoringAccountCount); @@ -167,7 +167,7 @@ baseReserveHlp(ReadView const& view, std::uint32_t ownerCount, std::uint32_t res static XRPAmount reserveHlp( ReadView const& view, - std::shared_ptr const& sle, + SLE::const_ref sle, std::uint32_t ownerCount, std::uint32_t reserveCount) { @@ -180,11 +180,7 @@ reserveHlp( } std::uint32_t -ownerCount( - ReadView const& view, - std::shared_ptr const& sle, - beast::Journal j, - std::int32_t adjustment) +ownerCount(ReadView const& view, SLE::const_ref sle, beast::Journal j, std::int32_t adjustment) { return ownerCountHlp(view, sle, adjustment, true, j); } @@ -278,10 +274,10 @@ adjustOwnerCount( adjustSponsorOwnerCountHlp(view, accountSle, sfOwnerCount, accountID, adjustment, j); } -[[nodiscard]] XRPAmount +XRPAmount accountReserve( ReadView const& view, - std::shared_ptr const& sle, + SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj, std::int32_t reserveCountAdj) diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index 3ab2474008..ddb25e6f7f 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -167,19 +167,9 @@ preflightCheckSimulateKeys(ApplyFlags flags, STObject const& sigObject, beast::J } // namespace detail -/** Performs early sanity checks on the account and fee fields */ -NotTEC -Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) +static NotTEC +preflight1Sponsor(PreflightContext const& ctx, AccountID const& id) { - if (ctx.tx.isFieldPresent(sfDelegate)) - { - if (!ctx.rules.enabled(featurePermissionDelegationV1_1)) - return temDISABLED; - - if (ctx.tx[sfDelegate] == ctx.tx[sfAccount]) - return temBAD_SIGNER; - } - bool const hasSponsor = ctx.tx.isFieldPresent(sfSponsor); bool const hasSponsorFlags = ctx.tx.isFieldPresent(sfSponsorFlags); bool const hasSponsorSig = ctx.tx.isFieldPresent(sfSponsorSignature); @@ -223,6 +213,29 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) return temINVALID_FLAG; } + if (hasSponsor && ctx.tx.getAccountID(sfSponsor) == id) + { + JLOG(ctx.j.debug()) << "preflight1: Sponsor account cannot be the " + "same as the transaction originator"; + return temMALFORMED; + } + + return tesSUCCESS; +} + +/** Performs early sanity checks on the account and fee fields */ +NotTEC +Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) +{ + if (ctx.tx.isFieldPresent(sfDelegate)) + { + if (!ctx.rules.enabled(featurePermissionDelegationV1_1)) + return temDISABLED; + + if (ctx.tx[sfDelegate] == ctx.tx[sfAccount]) + return temBAD_SIGNER; + } + if (auto const ret = preflight0(ctx, flagMask)) return ret; @@ -261,13 +274,8 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) !ctx.rules.enabled(featureBatch), "Inner batch transaction must have a parent batch ID."); - // Sponsor checks - if (hasSponsor && ctx.tx.getAccountID(sfSponsor) == id) - { - JLOG(ctx.j.debug()) << "preflight1: Sponsor account cannot be the " - "same as the transaction originator"; - return temMALFORMED; - } + if (auto const ter = preflight1Sponsor(ctx, id); !isTesSuccess(ter)) + return ter; return tesSUCCESS; } diff --git a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp index e9dc1b619f..bb7eeb4468 100644 --- a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp +++ b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp @@ -59,12 +59,6 @@ OracleSet::preflight(PreflightContext const& ctx) return tesSUCCESS; } -uint32_t -OracleSet::calculateOracleReserve(std::size_t count) -{ - return count > 5 ? 2 : 1; -} - TER OracleSet::preclaim(PreclaimContext const& ctx) {