Move isPseudoAccount near createPseudoAccount

This commit is contained in:
Bronek Kozicki
2025-04-03 11:35:46 +01:00
parent 392e3846ed
commit 6f4e7e8e44
2 changed files with 37 additions and 37 deletions

View File

@@ -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<SLE const> 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<SLE const> 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<SLE const> sleAcct);
[[nodiscard]] inline bool
isPseudoAccount(ReadView const& view, AccountID accountId)
{
return isPseudoAccount(view.read(keylet::account(accountId)));
}
} // namespace ripple
#endif

View File

@@ -1104,6 +1104,28 @@ createPseudoAccount(
return account;
}
[[nodiscard]] bool
isPseudoAccount(std::shared_ptr<SLE const> 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<SField const*, 2> 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<SLE const> 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<SField const*, 2> 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