diff --git a/include/xrpl/ledger/helpers/SponsorHelpers.h b/include/xrpl/ledger/helpers/SponsorHelpers.h index 17b287c5b2..3c4615b325 100644 --- a/include/xrpl/ledger/helpers/SponsorHelpers.h +++ b/include/xrpl/ledger/helpers/SponsorHelpers.h @@ -31,104 +31,38 @@ isReserveSponsored(STTx const& tx) return (tx.getFieldU32(sfSponsorFlags) & spfSponsorReserve) != 0u; } -inline std::optional -getTxReserveSponsorAccountID(STTx const& tx) -{ - if (tx.isFieldPresent(sfSponsor) && isReserveSponsored(tx)) - { - return tx.getAccountID(sfSponsor); - } - return {}; -} +std::optional +getTxReserveSponsorAccountID(STTx const& tx); -inline std::expected -getTxReserveSponsor(ApplyViewContext ctx) -{ - auto const sponsorID = getTxReserveSponsorAccountID(ctx.tx); - if (sponsorID) - { - auto sle = ctx.view.peek(keylet::account(*sponsorID)); +std::expected +getTxReserveSponsor(ApplyViewContext ctx); - // already checked in Transactor::checkSponsor - if (!sle) - return std::unexpected(tecINTERNAL); - return sle; - } - return SLE::pointer(); -} +std::expected +getTxReserveSponsor(ReadView const& view, STTx const& tx); -inline std::expected -getTxReserveSponsor(ReadView const& view, STTx const& tx) -{ - auto const sponsorID = getTxReserveSponsorAccountID(tx); - if (sponsorID) - { - auto sle = view.read(keylet::account(*sponsorID)); +std::optional +getLedgerEntryReserveSponsorAccountID(SLE::const_ref sle, SF_ACCOUNT const& field = sfSponsor); - // already checked in Transactor::checkSponsor - if (!sle) - return std::unexpected(tecINTERNAL); - return sle; - } - return SLE::pointer(); -} - -inline std::optional -getLedgerEntryReserveSponsorAccountID(SLE::const_ref sle, SF_ACCOUNT const& field = sfSponsor) -{ - if (sle->isFieldPresent(field)) - return sle->getAccountID(field); - return {}; -} - -inline SLE::pointer +SLE::pointer getLedgerEntryReserveSponsor( ApplyView& view, SLE::const_ref sle, - SF_ACCOUNT const& field = sfSponsor) -{ - auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field); - if (sponsorID) - return view.peek(keylet::account(*sponsorID)); - return {}; -} + SF_ACCOUNT const& field = sfSponsor); -inline SLE::const_pointer +SLE::const_pointer getLedgerEntryReserveSponsor( ReadView const& view, SLE::const_ref sle, - SF_ACCOUNT const& field = sfSponsor) -{ - auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field); - if (sponsorID) - return view.read(keylet::account(*sponsorID)); - return {}; -} + SF_ACCOUNT const& field = sfSponsor); -inline void +void addSponsorToLedgerEntry( SLE::ref sle, SLE::const_ref sponsorSle, - SF_ACCOUNT const& field = sfSponsor) -{ - XRPL_ASSERT( - (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) || - (sle->getType() != ltRIPPLE_STATE && field == sfSponsor), - "addSponsorToLedgerEntry : Invalid field to the LedgerEntry"); - if (sponsorSle) - sle->setAccountID(field, sponsorSle->getAccountID(sfAccount)); -} + SF_ACCOUNT const& field = sfSponsor); -inline void -removeSponsorFromLedgerEntry(SLE::ref sle, SF_ACCOUNT const& field = sfSponsor) -{ - XRPL_ASSERT( - (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) || - (sle->getType() != ltRIPPLE_STATE && field == sfSponsor), - "removeSponsorFromLedgerEntry : Invalid field to the LedgerEntry"); - if (sle->isFieldPresent(field)) - sle->makeFieldAbsent(field); -} +void +removeSponsorFromLedgerEntry(SLE::ref sle, SF_ACCOUNT const& field = sfSponsor); template inline std::optional diff --git a/src/libxrpl/ledger/helpers/SponsorHelpers.cpp b/src/libxrpl/ledger/helpers/SponsorHelpers.cpp new file mode 100644 index 0000000000..cb7f0fedc2 --- /dev/null +++ b/src/libxrpl/ledger/helpers/SponsorHelpers.cpp @@ -0,0 +1,109 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +std::optional +getTxReserveSponsorAccountID(STTx const& tx) +{ + if (tx.isFieldPresent(sfSponsor) && isReserveSponsored(tx)) + { + return tx.getAccountID(sfSponsor); + } + return {}; +} + +std::expected +getTxReserveSponsor(ApplyViewContext ctx) +{ + auto const sponsorID = getTxReserveSponsorAccountID(ctx.tx); + if (sponsorID) + { + auto sle = ctx.view.peek(keylet::account(*sponsorID)); + + // already checked in Transactor::checkSponsor + if (!sle) + return std::unexpected(tecINTERNAL); + return sle; + } + return SLE::pointer(); +} + +std::expected +getTxReserveSponsor(ReadView const& view, STTx const& tx) +{ + auto const sponsorID = getTxReserveSponsorAccountID(tx); + if (sponsorID) + { + auto sle = view.read(keylet::account(*sponsorID)); + + // already checked in Transactor::checkSponsor + if (!sle) + return std::unexpected(tecINTERNAL); + return sle; + } + return SLE::pointer(); +} + +std::optional +getLedgerEntryReserveSponsorAccountID(SLE::const_ref sle, SF_ACCOUNT const& field) +{ + if (sle->isFieldPresent(field)) + return sle->getAccountID(field); + return {}; +} + +SLE::pointer +getLedgerEntryReserveSponsor(ApplyView& view, SLE::const_ref sle, SF_ACCOUNT const& field) +{ + auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field); + if (sponsorID) + return view.peek(keylet::account(*sponsorID)); + return {}; +} + +SLE::const_pointer +getLedgerEntryReserveSponsor(ReadView const& view, SLE::const_ref sle, SF_ACCOUNT const& field) +{ + auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field); + if (sponsorID) + return view.read(keylet::account(*sponsorID)); + return {}; +} + +void +addSponsorToLedgerEntry(SLE::ref sle, SLE::const_ref sponsorSle, SF_ACCOUNT const& field) +{ + XRPL_ASSERT( + (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) || + (sle->getType() != ltRIPPLE_STATE && field == sfSponsor), + "addSponsorToLedgerEntry : Invalid field to the LedgerEntry"); + if (sponsorSle) + sle->setAccountID(field, sponsorSle->getAccountID(sfAccount)); +} + +void +removeSponsorFromLedgerEntry(SLE::ref sle, SF_ACCOUNT const& field) +{ + XRPL_ASSERT( + (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) || + (sle->getType() != ltRIPPLE_STATE && field == sfSponsor), + "removeSponsorFromLedgerEntry : Invalid field to the LedgerEntry"); + if (sle->isFieldPresent(field)) + sle->makeFieldAbsent(field); +} + +} // namespace xrpl