diff --git a/src/xrpld/ledger/View.h b/src/xrpld/ledger/View.h index b2357bcbf5..af3dce1f5f 100644 --- a/src/xrpld/ledger/View.h +++ b/src/xrpld/ledger/View.h @@ -501,6 +501,21 @@ createPseudoAccount( uint256 const& pseudoOwnerKey, PseudoAccountOwnerType type); +// Returns true iff sleAcct is a pseudo-account. +// +// Returns false if sleAcct is +// * NOT a pseudo-account OR +// * NOT a ltACCOUNT_ROOT OR +// * null pointer +[[nodiscard]] bool +isPseudoAccount(std::shared_ptr sleAcct); + +[[nodiscard]] inline bool +isPseudoAccount(ReadView const& view, AccountID accountId) +{ + return isPseudoAccount(view.read(keylet::account(accountId))); +} + [[nodiscard]] TER addEmptyHolding( ApplyView& view, @@ -799,21 +814,6 @@ sharesToAssetsWithdraw( std::shared_ptr const& issuance, STAmount const& shares); -// Returns true iff sleAcct is a pseudo-account. -// -// Returns false if sleAcct is -// * NOT a pseudo-account OR -// * NOT a ltACCOUNT_ROOT OR -// * null pointer -[[nodiscard]] bool -isPseudoAccount(std::shared_ptr sleAcct); - -[[nodiscard]] inline bool -isPseudoAccount(ReadView const& view, AccountID accountId) -{ - return isPseudoAccount(view.read(keylet::account(accountId))); -} - } // namespace ripple #endif diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index 6ebc20e3cb..a6eb3bd972 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -1104,6 +1104,28 @@ createPseudoAccount( return account; } +[[nodiscard]] bool +isPseudoAccount(std::shared_ptr sleAcct) +{ + // Note, the list of the pseudo-account designator fields below MUST be + // maintained but it does NOT need to be amendment-gated, since a non-active + // amendment will not set any field, by definition. Specific properties of a + // pseudo-account are NOT checked here, that's what InvariantCheck is for. + static std::array const fields = // + { + &sfAMMID, // + &sfVaultID, // + }; + + // Intentionally use defensive coding here because it's cheap and makes the + // semantics of true return value clean. + return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT && + std::count_if( + fields.begin(), fields.end(), [&sleAcct](SField const* sf) -> bool { + return sleAcct->isFieldPresent(*sf); + }) > 0; +} + [[nodiscard]] TER addEmptyHolding( ApplyView& view, @@ -2576,26 +2598,4 @@ sharesToAssetsWithdraw( return assets; } -[[nodiscard]] bool -isPseudoAccount(std::shared_ptr sleAcct) -{ - // Note, the list of the pseudo-account designator fields below MUST be - // maintained but it does NOT need to be amendment-gated, since a non-active - // amendment will not set any field, by definition. Specific properties of a - // pseudo-account are NOT checked here, that's what InvariantCheck is for. - static std::array const fields = // - { - &sfAMMID, // - &sfVaultID, // - }; - - // Intentionally use defensive coding here because it's cheap and makes the - // semantics of true return value clean. - return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT && - std::count_if( - fields.begin(), fields.end(), [&sleAcct](SField const* sf) -> bool { - return sleAcct->isFieldPresent(*sf); - }) > 0; -} - } // namespace ripple