refactor: Move checkDestinationAndTag onto AccountRootEntry

Replace the entry-taking checkDestinationAndTag free function with the
const member AccountRootEntry::checkDestinationAndTag(hasDestinationTag).
The body is short, so it is inline in the header.
This commit is contained in:
Mayukha Vadari committed 2026-10-05 15:48:35 +01:00
1 parent f27581a6bb
commit 8940046ca8
4 files changed
+21 -27

No files matched your search

@@ -120,6 +120,26 @@ public:
[[nodiscard]] bool
isPseudoAccount() const;
/**
* Checks the destination and tag.
*
* - Checks that the entry exists.
* - If the entry requires a destination tag, checks that there is a tag.
*/
[[nodiscard]] TER
checkDestinationAndTag(bool hasDestinationTag) const
{
if (!this->exists())
return tecNO_DST;
// The tag is basically account-specific information we don't
// understand, but we can require someone to fill it in.
if ((*this)->isFlag(lsfRequireDestTag) && !hasDestinationTag)
return tecDST_TAG_NEEDED; // Cannot send without a tag
return tesSUCCESS;
}
/**
* Increase owner-count fields when the caller supplies the sponsor.
*
@@ -9,7 +9,6 @@
#include <xrpl/protocol/Rate.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <cstdint>
@@ -261,13 +260,4 @@ isPseudoAccount(ReadView const& view, AccountID const& accountId)
return AccountRootEntryR(accountId, view).isPseudoAccount();
}
/**
* Checks the destination and tag.
*
* - Checks that the SLE is not null.
* - If the SLE requires a destination tag, checks that there is a tag.
*/
[[nodiscard]] TER
checkDestinationAndTag(AccountRootEntryR const& toSle, bool hasDestinationTag);
} // namespace xrpl
+1 -2
View File
@@ -10,7 +10,6 @@
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/AccountRootEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
@@ -472,7 +471,7 @@ canWithdraw(
bool hasDestinationTag,
std::optional<std::vector<UInt256>> const& credentialIDs)
{
if (auto const ret = checkDestinationAndTag(toSle, hasDestinationTag))
if (auto const ret = toSle.checkDestinationAndTag(hasDestinationTag))
return ret;
if (from == to)
@@ -16,7 +16,6 @@
#include <xrpl/protocol/Rate.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/protocol/digest.h>
@@ -263,18 +262,4 @@ getPseudoAccountFields()
return kPseudoFields;
}
[[nodiscard]] TER
checkDestinationAndTag(AccountRootEntryR const& toSle, bool hasDestinationTag)
{
if (!toSle.exists())
return tecNO_DST;
// The tag is basically account-specific information we don't
// understand, but we can require someone to fill it in.
if (toSle->isFlag(lsfRequireDestTag) && !hasDestinationTag)
return tecDST_TAG_NEEDED; // Cannot send without a tag
return tesSUCCESS;
}
} // namespace xrpl