mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 01:06:48 +00:00
Refactor: sponsorship-related helpers
This commit is contained in:
77
include/xrpl/ledger/SponsorHelpers.h
Normal file
77
include/xrpl/ledger/SponsorHelpers.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/SField.h>
|
||||
#include <xrpl/protocol/STTx.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx);
|
||||
|
||||
bool
|
||||
isSponsorReserveCoSigning(STTx const& tx);
|
||||
|
||||
std::optional<AccountID>
|
||||
getTxReserveSponsorAccountID(STTx const& tx);
|
||||
|
||||
inline std::shared_ptr<SLE>
|
||||
getTxReserveSponsor(ApplyView& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::shared_ptr<SLE const>
|
||||
getTxReserveSponsor(ReadView const& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
inline std::shared_ptr<SLE>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::shared_ptr<SLE const>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
void
|
||||
removeSponsorFromLedgerEntry(std::shared_ptr<SLE> const& sle, SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -474,11 +474,11 @@ ownerCount(std::shared_ptr<SLE const> const& sponsorSle);
|
||||
XRPAmount
|
||||
calculateReserve(std::shared_ptr<SLE const> const& sle, Fees const& fees);
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx);
|
||||
// bool
|
||||
// isReserveSponsored(STTx const& tx);
|
||||
|
||||
bool
|
||||
isSponsorReserveCoSigning(STTx const& tx);
|
||||
// bool
|
||||
// isSponsorReserveCoSigning(STTx const& tx);
|
||||
|
||||
TER
|
||||
checkInsufficientReserve(
|
||||
@@ -490,41 +490,6 @@ checkInsufficientReserve(
|
||||
std::int32_t ownerCountDelta,
|
||||
std::int32_t accountCountDelta = 0);
|
||||
|
||||
std::optional<AccountID>
|
||||
getTxReserveSponsorAccountID(STTx const& tx);
|
||||
|
||||
std::shared_ptr<SLE>
|
||||
getTxReserveSponsor(ApplyView& view, STTx const& tx);
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
getTxReserveSponsor(ReadView const& view, STTx const& tx);
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
std::shared_ptr<SLE>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
void
|
||||
removeSponsorFromLedgerEntry(std::shared_ptr<SLE> const& sle, SF_ACCOUNT const& field = sfSponsor);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Modifiers
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/WrappedSink.h>
|
||||
#include <xrpl/ledger/SponsorHelpers.h>
|
||||
#include <xrpl/protocol/Permissions.h>
|
||||
#include <xrpl/protocol/XRPAmount.h>
|
||||
#include <xrpl/tx/ApplyContext.h>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <xrpl/ledger/CredentialHelpers.h>
|
||||
#include <xrpl/ledger/SponsorHelpers.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/TER.h>
|
||||
#include <xrpl/protocol/digest.h>
|
||||
|
||||
65
src/libxrpl/ledger/SponsorHelpers.cpp
Normal file
65
src/libxrpl/ledger/SponsorHelpers.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <xrpl/ledger/SponsorHelpers.h>
|
||||
#include <xrpl/protocol/TxFlags.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx)
|
||||
{
|
||||
return tx.getFieldU32(sfSponsorFlags) & spfSponsorReserve;
|
||||
}
|
||||
|
||||
bool
|
||||
isSponsorReserveCoSigning(STTx const& tx)
|
||||
{
|
||||
if (!tx.isFieldPresent(sfSponsorSignature))
|
||||
return false;
|
||||
return isReserveSponsored(tx);
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getTxReserveSponsorAccountID(STTx const& tx)
|
||||
{
|
||||
if (tx.isFieldPresent(sfSponsor) && isReserveSponsored(tx))
|
||||
{
|
||||
return tx.getAccountID(sfSponsor);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
if (sle->isFieldPresent(field))
|
||||
return sle->getAccountID(field);
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::shared_ptr<SLE> const& 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(std::shared_ptr<SLE> const& 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
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <xrpl/ledger/CredentialHelpers.h>
|
||||
#include <xrpl/ledger/Credit.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/SponsorHelpers.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
@@ -1040,20 +1041,6 @@ calculateReserve(std::shared_ptr<SLE const> const& sle, Fees const& fees)
|
||||
sle->getFieldU32(sfSponsoringAccountCount));
|
||||
}
|
||||
|
||||
bool
|
||||
isReserveSponsored(STTx const& tx)
|
||||
{
|
||||
return tx.getFieldU32(sfSponsorFlags) & spfSponsorReserve;
|
||||
}
|
||||
|
||||
bool
|
||||
isSponsorReserveCoSigning(STTx const& tx)
|
||||
{
|
||||
if (!tx.isFieldPresent(sfSponsorSignature))
|
||||
return false;
|
||||
return isReserveSponsored(tx);
|
||||
}
|
||||
|
||||
TER
|
||||
checkInsufficientReserve(
|
||||
ReadView const& view,
|
||||
@@ -1118,93 +1105,6 @@ checkInsufficientReserve(
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getTxReserveSponsorAccountID(STTx const& tx)
|
||||
{
|
||||
if (tx.isFieldPresent(sfSponsor) && isReserveSponsored(tx))
|
||||
{
|
||||
return tx.getAccountID(sfSponsor);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE>
|
||||
getTxReserveSponsor(ApplyView& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
getTxReserveSponsor(ReadView const& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
if (sle->isFieldPresent(field))
|
||||
return sle->getAccountID(field);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE const>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::shared_ptr<SLE> const& 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(std::shared_ptr<SLE> const& 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);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Modifiers
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/tx/Transactor.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class SponsorshipSet : public Transactor
|
||||
{
|
||||
public:
|
||||
static constexpr ConsequencesFactoryType ConsequencesFactory{Normal};
|
||||
|
||||
explicit SponsorshipSet(ApplyContext& ctx) : Transactor(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static std::uint32_t
|
||||
getFlagsMask(PreflightContext const& ctx);
|
||||
|
||||
static NotTEC
|
||||
preflight(PreflightContext const& ctx);
|
||||
|
||||
static NotTEC
|
||||
checkPermission(ReadView const& view, STTx const& tx);
|
||||
|
||||
static TER
|
||||
preclaim(PreclaimContext const& ctx);
|
||||
|
||||
TER
|
||||
doApply() override;
|
||||
|
||||
// Interface used by DeleteAccount
|
||||
static TER
|
||||
deleteSponsorship(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/tx/Transactor.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
class SponsorshipTransfer : public Transactor
|
||||
{
|
||||
public:
|
||||
static constexpr ConsequencesFactoryType ConsequencesFactory{Normal};
|
||||
|
||||
explicit SponsorshipTransfer(ApplyContext& ctx) : Transactor(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static NotTEC
|
||||
preflight(PreflightContext const& ctx);
|
||||
|
||||
static TER
|
||||
preclaim(PreclaimContext const& ctx);
|
||||
|
||||
TER
|
||||
doApply() override;
|
||||
};
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/ledger/SponsorHelpers.h>
|
||||
#include <xrpl/ledger/View.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user