xrpld
Loading...
Searching...
No Matches
SponsorHelpers.h
1#pragma once
2
3#include <xrpl/ledger/ApplyView.h>
4#include <xrpl/ledger/ReadView.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/STLedgerEntry.h>
8#include <xrpl/protocol/STTx.h>
9#include <xrpl/protocol/TER.h>
10#include <xrpl/protocol/TxFlags.h>
11#include <xrpl/protocol/TxFormats.h>
12
13#include <cstdint>
14#include <expected>
15#include <optional>
16
17namespace xrpl {
18
25bool
27
31inline bool
33{
34 return tx.isFieldPresent(sfSponsor) && ((tx.getFieldU32(sfSponsorFlags) & spfSponsorFee) != 0u);
35}
36
40inline bool
42{
43 return tx.isFieldPresent(sfSponsor) &&
44 ((tx.getFieldU32(sfSponsorFlags) & spfSponsorReserve) != 0u);
45}
46
51getTxReserveSponsorID(STTx const& tx);
52
61std::expected<SLE::pointer, TER>
62getTxReserveSponsor(ApplyViewContext ctx);
63
73std::expected<SLE::const_pointer, TER>
74getTxReserveSponsor(ReadView const& view, STTx const& tx);
75
90[[nodiscard]] std::expected<SLE::pointer, TER>
91getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::const_ref accountSle);
92
97getLedgerEntryReserveSponsorID(SLE::const_ref sle, SF_ACCOUNT const& field = sfSponsor);
98
112 ApplyView& view,
113 SLE::const_ref sle,
114 SF_ACCOUNT const& field = sfSponsor);
115
128void
130 SLE::ref sle,
131 SLE::const_ref sponsorSle,
132 SF_ACCOUNT const& field = sfSponsor);
133
143void
144addSponsorToLedgerEntry(ApplyViewContext ctx, SLE::ref sle, SF_ACCOUNT const& field = sfSponsor);
145
156void
157removeSponsorFromLedgerEntry(SLE::ref sle, SF_ACCOUNT const& field = sfSponsor);
158
171bool
172isLedgerEntryOwner(ReadView const& view, SLE const& sle, AccountID const& account);
173
177bool
179
188getLedgerEntryOwnerCount(SLE const& sle);
189
201SF_ACCOUNT const&
202getLedgerEntrySponsorField(SLE const& sle, AccountID const& owner);
203
204} // namespace xrpl
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:601
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:464
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr FlagValue spfSponsorFee
Definition TxFlags.h:459
TxType
Transaction type identifiers.
Definition TxFormats.h:45
bool isReserveSponsored(STTx const &tx)
Whether the transaction's reserve is sponsored (sfSponsor present + spfSponsorReserve set).
std::optional< AccountID > getLedgerEntryReserveSponsorID(SLE::const_ref sle, SF_ACCOUNT const &field=sfSponsor)
Return the AccountID stored in the given sponsor field of a ledger entry, or nullopt if absent.
STLedgerEntry SLE
std::expected< SLE::pointer, TER > getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::const_ref accountSle)
The transaction's reserve sponsor for the given account, if applicable.
bool isReserveSponsorAllowed(TxType txType)
Whether the given transaction type may use reserve sponsorship (v1).
std::expected< SLE::pointer, TER > getTxReserveSponsor(ApplyViewContext ctx)
Return a mutable SLE for the transaction's reserve sponsor account.
void addSponsorToLedgerEntry(SLE::ref sle, SLE::const_ref sponsorSle, SF_ACCOUNT const &field=sfSponsor)
Stamp a reserve sponsor onto a ledger entry using an explicit sponsor SLE.
void removeSponsorFromLedgerEntry(SLE::ref sle, SF_ACCOUNT const &field=sfSponsor)
Remove the reserve sponsor field from a ledger entry.
bool isFeeSponsored(STTx const &tx)
Whether the transaction's fee is sponsored (sfSponsor present + spfSponsorFee set).
std::uint32_t getLedgerEntryOwnerCount(SLE const &sle)
Return the number of owner-count units the ledger entry consumes.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
SLE::pointer getLedgerEntryReserveSponsor(ApplyView &view, SLE::const_ref sle, SF_ACCOUNT const &field=sfSponsor)
Return a mutable SLE for the reserve sponsor recorded on a ledger entry.
std::optional< AccountID > getTxReserveSponsorID(STTx const &tx)
Return the AccountID of the transaction's reserve sponsor, or nullopt if unsponsored.
TypedField< STAccount > SF_ACCOUNT
Definition SField.h:354
bool isLedgerEntryOwner(ReadView const &view, SLE const &sle, AccountID const &account)
Whether account is the owner of a ledger entry for sponsorship purposes.
constexpr FlagValue spfSponsorReserve
Definition TxFlags.h:460
SF_ACCOUNT const & getLedgerEntrySponsorField(SLE const &sle, AccountID const &owner)
Return the SField used to store the reserve sponsor for owner on sle.
bool isLedgerEntrySupportedBySponsorship(SLE const &sle)
Whether this ledger entry type can have a reserve sponsor attached to it.