Factor out isPseudoAccount

This commit is contained in:
Bronek Kozicki
2025-04-02 19:29:04 +01:00
parent dbbf6829b9
commit 85e7d293ca
4 changed files with 41 additions and 4 deletions

View File

@@ -165,8 +165,8 @@ LEDGER_ENTRY(ltACCOUNT_ROOT, 0x0061, AccountRoot, account, ({
{sfMintedNFTokens, soeDEFAULT},
{sfBurnedNFTokens, soeDEFAULT},
{sfFirstNFTokenSequence, soeOPTIONAL},
{sfAMMID, soeOPTIONAL},
{sfVaultID, soeOPTIONAL},
{sfAMMID, soeOPTIONAL}, // pseudo-account designator
{sfVaultID, soeOPTIONAL}, // pseudo-account designator
}))
/** A ledger object which contains a list of object identifiers.

View File

@@ -884,8 +884,7 @@ ValidNewAccountRoot::visitEntry(
{
accountsCreated_++;
accountSeq_ = (*after)[sfSequence];
pseudoAccount_ =
after->isFieldPresent(sfAMMID) || after->isFieldPresent(sfVaultID);
pseudoAccount_ = isPseudoAccount(after);
flags_ = after->getFlags();
}
}

View File

@@ -25,6 +25,7 @@
#include <xrpld/ledger/ReadView.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/Rate.h>
@@ -798,6 +799,21 @@ 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

@@ -2576,4 +2576,26 @@ 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