1#include <xrpl/ledger/helpers/SponsorHelpers.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/OracleHelpers.h>
8#include <xrpl/ledger/helpers/ProposalHelpers.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Feature.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/LedgerFormats.h>
13#include <xrpl/protocol/Rules.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/STArray.h>
16#include <xrpl/protocol/STLedgerEntry.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/TER.h>
19#include <xrpl/protocol/TxFormats.h>
50 ttMPTOKEN_ISSUANCE_CREATE,
51 ttMPTOKEN_ISSUANCE_DESTROY,
52 ttMPTOKEN_ISSUANCE_SET,
59 ttSPONSORSHIP_TRANSFER,
60 ttTRANSACTION_PROPOSAL_CREATE,
62 return kReserveSponsorAllowed.
contains(txType);
73 "xrpl::getTxReserveSponsorID : sponsor exists + Sponsor enabled");
79std::expected<SLE::pointer, TER>
87 "xrpl::getTxReserveSponsor : sponsor exists + Sponsor enabled");
98std::expected<SLE::const_pointer, TER>
106 "xrpl::getTxReserveSponsor : sponsor exists + Sponsor enabled");
117std::expected<SLE::pointer, TER>
124 accountSle && accountSle->getType() == ltACCOUNT_ROOT,
125 "xrpl::getEffectiveTxReserveSponsor : accountSle exists and is account type");
131 ((accountSle->getType() == ltACCOUNT_ROOT) || (accountSle->getType() == ltESCROW)),
132 "xrpl::getEffectiveTxReserveSponsor : accountSle exists and is account type");
135 if (
isPseudoAccount(accountSle) || accountSle->getAccountID(sfAccount) != ctx.
tx[sfAccount])
145 ((sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) ||
146 (sle->getType() != ltRIPPLE_STATE && field == sfSponsor))),
147 "xrpl::getLedgerEntryReserveSponsorID : correct sfield");
149 if (sle->isFieldPresent(field))
150 return sle->getAccountID(field);
162 "xrpl::getLedgerEntryReserveSponsor : sponsor exists + Sponsor enabled");
172 (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) ||
173 (sle->getType() != ltRIPPLE_STATE && field == sfSponsor),
174 "addSponsorToLedgerEntry : Invalid field to the LedgerEntry");
180 "xrpl::addSponsorToLedgerEntry : sponsor exists + Sponsor enabled");
181 sle->setAccountID(field, sponsorSle->getAccountID(sfAccount));
192 if (sponsorSle && *sponsorSle)
196 "xrpl::addSponsorToLedgerEntry : sponsor exists + Sponsor enabled");
205 (sle->getType() == ltRIPPLE_STATE && (field == sfHighSponsor || field == sfLowSponsor)) ||
206 (sle->getType() != ltRIPPLE_STATE && field == sfSponsor),
207 "removeSponsorFromLedgerEntry : Invalid field to the LedgerEntry");
208 if (sle->isFieldPresent(field))
213 "xrpl::removeSponsorFromLedgerEntry : sponsor exists + Sponsor enabled");
214 sle->makeFieldAbsent(field);
228 case ltDEPOSIT_PREAUTH:
230 case ltMPTOKEN_ISSUANCE:
232 case ltSIGNER_LIST: {
236 return signerList->
key() == sle.
key();
239 auto const& ownerField = sle.
isFlag(lsfAccepted) ? sfSubject : sfIssuer;
242 case ltRIPPLE_STATE: {
243 if (sle.
isFlag(lsfHighReserve))
246 if (highAccount == account)
249 if (sle.
isFlag(lsfLowReserve))
252 if (lowAccount == account)
260 case ltTRANSACTION_PROPOSAL:
264 UNREACHABLE(
"xrpl::isLedgerEntryOwner : object is not supported by sponsorship.");
280 case ltDEPOSIT_PREAUTH:
281 case ltMPTOKEN_ISSUANCE:
285 case ltTRANSACTION_PROPOSAL:
303 case ltSIGNER_LIST: {
308 if (sle.
isFlag(lsfOneOwnerCount))
312 case ltTRANSACTION_PROPOSAL:
319 UNREACHABLE(
"AccountRoots are not supported by object sponsorship.");
332 case ltRIPPLE_STATE: {
333 if (sle.
isFlag(lsfHighReserve))
336 if (highAccount == owner)
337 return sfHighSponsor;
339 if (sle.
isFlag(lsfLowReserve))
342 if (lowAccount == owner)
346 UNREACHABLE(
"xrpl::getLedgerEntrySponsorField : unknown owner for RippleState");
Writeable view to a ledger, for applying a transaction.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
AccountID const & getIssuer() const
UInt256 const & key() const
Returns the 'key' (or 'index') of this item.
std::shared_ptr< STLedgerEntry > pointer
LedgerEntryType getType() const
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
STArray const & getFieldArray(SField const &field) const
bool isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
STObject getFieldObject(SField const &field) const
AccountID getAccountID(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Keylet account(AccountID const &id) noexcept
AccountID root.
std::uint32_t proposalOwnerCount(STObject const &proposedTx)
Owner-reserve increments held by a proposal of the given transaction.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::uint32_t calculateOracleReserve(T const &priceDataSeries)
void removeSponsorFromLedgerEntry(SLE::Ref sle, SF_ACCOUNT const &field=sfSponsor)
Remove the reserve sponsor field from a ledger entry.
TxType
Transaction type identifiers.
std::optional< AccountID > getLedgerEntryReserveSponsorID(SLE::ConstRef sle, SF_ACCOUNT const &field=sfSponsor)
Return the AccountID stored in the given sponsor field of a ledger entry, or nullopt if absent.
std::optional< Rules > const & getCurrentTransactionRules()
std::expected< SLE::pointer, TER > getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::ConstRef accountSle)
The transaction's reserve sponsor for the given account, if applicable.
void addSponsorToLedgerEntry(SLE::Ref sle, SLE::ConstRef sponsorSle, SF_ACCOUNT const &field=sfSponsor)
Stamp a reserve sponsor onto a ledger entry using an explicit sponsor SLE.
bool isReserveSponsored(STTx const &tx)
Whether the transaction's reserve is sponsored (sfSponsor present + spfSponsorReserve set).
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.
std::uint32_t getLedgerEntryOwnerCount(SLE const &sle)
Return the number of owner-count units the ledger entry consumes.
bool isPseudoAccount(SLE::const_pointer sleAcct)
Returns true if and only if sleAcct is a pseudo-account of any kind (i.e.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
SLE::pointer getLedgerEntryReserveSponsor(ApplyView &view, SLE::ConstRef 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
bool isLedgerEntryOwner(ReadView const &view, SLE const &sle, AccountID const &account)
Whether account is the owner of a ledger entry for sponsorship purposes.
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.
Bundles the mutable ledger view and the transaction being applied.