xrpld
Loading...
Searching...
No Matches
xrpl::SLEBase< ViewT, EntryType > Class Template Reference

View-parameterized base class for all ledger entries. More...

#include <SLEBase.h>

Inherited by xrpl::AMMEntry< ReadView >, xrpl::AMMEntry< ApplyView >, xrpl::AccountRootEntry< ReadView >, xrpl::AccountRootEntry< ApplyView >, xrpl::AmendmentsEntry< ReadView >, xrpl::AmendmentsEntry< ApplyView >, xrpl::BridgeEntry< ReadView >, xrpl::BridgeEntry< ApplyView >, xrpl::CheckEntry< ReadView >, xrpl::CheckEntry< ApplyView >, xrpl::CredentialEntry< ReadView >, xrpl::CredentialEntry< ApplyView >, xrpl::DIDEntry< ReadView >, xrpl::DIDEntry< ApplyView >, xrpl::DelegateEntry< ReadView >, xrpl::DelegateEntry< ApplyView >, xrpl::DepositPreauthEntry< ReadView >, xrpl::DepositPreauthEntry< ApplyView >, xrpl::DirectoryNodeEntry< ReadView >, xrpl::DirectoryNodeEntry< ApplyView >, xrpl::EscrowEntry< ReadView >, xrpl::EscrowEntry< ApplyView >, xrpl::FeeSettingsEntry< ReadView >, xrpl::FeeSettingsEntry< ApplyView >, xrpl::LedgerHashesEntry< ReadView >, xrpl::LedgerHashesEntry< ApplyView >, xrpl::LoanBrokerEntry< ReadView >, xrpl::LoanBrokerEntry< ApplyView >, xrpl::LoanEntry< ReadView >, xrpl::LoanEntry< ApplyView >, xrpl::MPTokenEntry< ReadView >, xrpl::MPTokenEntry< ApplyView >, xrpl::MPTokenIssuanceEntry< ReadView >, xrpl::MPTokenIssuanceEntry< ApplyView >, xrpl::NFTokenOfferEntry< ReadView >, xrpl::NFTokenOfferEntry< ApplyView >, xrpl::NFTokenPageEntry< ReadView >, xrpl::NFTokenPageEntry< ApplyView >, xrpl::NegativeUNLEntry< ReadView >, xrpl::NegativeUNLEntry< ApplyView >, xrpl::OfferEntry< ReadView >, xrpl::OfferEntry< ApplyView >, xrpl::OracleEntry< ReadView >, xrpl::OracleEntry< ApplyView >, xrpl::PayChannelEntry< ReadView >, xrpl::PayChannelEntry< ApplyView >, xrpl::PermissionedDomainEntry< ReadView >, xrpl::PermissionedDomainEntry< ApplyView >, xrpl::RippleStateEntry< ReadView >, xrpl::RippleStateEntry< ApplyView >, xrpl::SignerListEntry< ReadView >, xrpl::SignerListEntry< ApplyView >, xrpl::SponsorshipEntry< ReadView >, xrpl::SponsorshipEntry< ApplyView >, xrpl::TicketEntry< ReadView >, xrpl::TicketEntry< ApplyView >, xrpl::TransactionProposalEntry< ReadView >, xrpl::TransactionProposalEntry< ApplyView >, xrpl::VaultEntry< ReadView >, xrpl::VaultEntry< ApplyView >, xrpl::XChainOwnedClaimIDEntry< ReadView >, xrpl::XChainOwnedClaimIDEntry< ApplyView >, xrpl::XChainOwnedCreateAccountClaimIDEntry< ReadView >, and xrpl::XChainOwnedCreateAccountClaimIDEntry< ApplyView >.

Collaboration diagram for xrpl::SLEBase< ViewT, EntryType >:

Classes

struct  Empty

Public Types

using SlePtrType = std::conditional_t<kIsWritable, SLE::pointer, SLE::const_pointer>
using ViewRefType = std::conditional_t<kIsWritable, ApplyView&, ReadView const&>

Public Member Functions

 ~SLEBase ()=default
 SLEBase (SLEBase const &)=default
 SLEBase (SLEBase &&)=default
SLEBase & operator= (SLEBase const &)=delete
SLEBase & operator= (SLEBase &&)=delete
 SLEBase ()=delete
 SLEBase (SLE::const_pointer sle, ViewRefType view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
 Constructor for read-only context (adopt an already-fetched SLE).
 SLEBase (Keylet const &key, ViewRefType view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
 Constructor for read-only context (read from view by keylet).
template<typename OtherViewT, LedgerEntryType OtherType>
requires (!kIsWritable && IsWritableView<OtherViewT> && (OtherType == EntryType || EntryType == ltANY))
 SLEBase (SLEBase< OtherViewT, OtherType > const &other)
 Converting constructor: writable → read-only.
 SLEBase (Keylet const &key, ApplyView &view, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
 Constructor for writable context (peek from view by keylet).
 SLEBase (Keylet const &key, ApplyViewContext const &ctx, beast::Journal j=beast::Journal{beast::Journal::getNullSink()})
 Constructor for writable context, for call sites that hold an ApplyViewContext (peek from ctx.view by keylet).
bool exists () const
 Returns true if the ledger entry exists.
 operator bool () const
 Explicit conversion to bool for convenient existence checking.
SLE::const_pointer rawSle () const
 Returns the underlying SLE for read access.
LedgerEntryType type () const
 Returns the ledger entry type of this entry.
Keylet keylet () const
 Returns the keylet identifying this entry.
UInt256 key () const
 Returns the ledger key of this entry.
ReadView const & readView () const
 Returns the read view (always available; ApplyView inherits ReadView).
STLedgerEntry const * operator-> () const
 Const dereference operators (always available).
STLedgerEntry const & operator* () const
SlePtrType const & mutableRawSle ()
 Returns the underlying SLE for write access.
ApplyView & applyView ()
 Returns the apply view for write operations.
STLedgerEntry * operator-> ()
 Mutable dereference operators.
STLedgerEntry & operator* ()
void insert ()
 Inserts the entry into the view.
void erase ()
 Erases the entry from the view.
void update ()
void newSLE ()
beast::Journal journal () const

Static Public Attributes

static constexpr bool kIsWritable = IsWritableView<ViewT>
static constexpr LedgerEntryType kEntryType = EntryType
static constexpr bool kIsTyped = (EntryType != ltANY)

Protected Attributes

ViewRefType view_
std::conditional_t< kIsWritable, Keylet, Empty > key_
SlePtrType sle_ {}
beast::Journal j_

Detailed Description

template<typename ViewT, LedgerEntryType EntryType = ltANY>
class xrpl::SLEBase< ViewT, EntryType >

View-parameterized base class for all ledger entries.

SLEBase<ReadView> — read-only: holds shared_ptr<SLE const> + ReadView const& SLEBase<ApplyView> — writable: holds shared_ptr<SLE> + ApplyView& + Keylet, plus insert/update/erase operations

Write-only members are gated by requires clauses, providing compile-time guarantees that read-only entries cannot mutate state.

Template Parameters
EntryTypethe ledger entry type this entry is statically bound to. Derived per-type entries pass their own type (e.g. ltACCOUNT_ROOT); the generic ReadOnlySLE / WritableSLE aliases leave it at ltANY, which opts out of the static type check. Binding the type here is what keeps an entry for one entry type from being constructed or converted from another – see the converting constructor below.

Derived classes should provide domain-specific accessors that hide implementation details of the underlying ledger entry format.

Definition at line 91 of file SLEBase.h.

Member Typedef Documentation

◆ SlePtrType

template<typename ViewT, LedgerEntryType EntryType = ltANY>
using xrpl::SLEBase< ViewT, EntryType >::SlePtrType = std::conditional_t<kIsWritable, SLE::pointer, SLE::const_pointer>

Definition at line 102 of file SLEBase.h.

◆ ViewRefType

template<typename ViewT, LedgerEntryType EntryType = ltANY>
using xrpl::SLEBase< ViewT, EntryType >::ViewRefType = std::conditional_t<kIsWritable, ApplyView&, ReadView const&>

Definition at line 106 of file SLEBase.h.

Constructor & Destructor Documentation

◆ ~SLEBase()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::~SLEBase ( )
default

◆ SLEBase() [1/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( SLEBase< ViewT, EntryType > const & )
default

◆ SLEBase() [2/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( SLEBase< ViewT, EntryType > && )
default

◆ SLEBase() [3/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( )
delete

◆ SLEBase() [4/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( SLE::const_pointer sle,
ViewRefType view,
beast::Journal j = beast::Journal{beast::Journal::getNullSink()} )
explicit

Constructor for read-only context (adopt an already-fetched SLE).

There is deliberately no writable equivalent: a writable entry needs a Keylet so that newSLE() can still build an entry when none exists, and that cannot be recovered from a null SLE.

Definition at line 140 of file SLEBase.h.

◆ SLEBase() [5/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( Keylet const & key,
ViewRefType view,
beast::Journal j = beast::Journal{beast::Journal::getNullSink()} )
explicit

Constructor for read-only context (read from view by keylet).

Definition at line 155 of file SLEBase.h.

◆ SLEBase() [6/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
template<typename OtherViewT, LedgerEntryType OtherType>
requires (!kIsWritable && IsWritableView<OtherViewT> && (OtherType == EntryType || EntryType == ltANY))
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( SLEBase< OtherViewT, OtherType > const & other)

Converting constructor: writable → read-only.

Enables implicit conversion from SLEBase<ApplyView> to SLEBase<ReadView>, so functions taking ReadOnlySLE const& can accept WritableSLE.

Constrained to the same entry type (or to a ltANY target, i.e. widening a typed entry to a generic ReadOnlySLE). The constraint is load-bearing: this constructor is inherited into every per-type entry, and unconstrained it would bind any writable entry that slices to SLEBase, so an OfferEntryW would convert to an AccountRootEntryR with no cast at the call site.

Definition at line 181 of file SLEBase.h.

◆ SLEBase() [7/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( Keylet const & key,
ApplyView & view,
beast::Journal j = beast::Journal{beast::Journal::getNullSink()} )
explicit

Constructor for writable context (peek from view by keylet).

Definition at line 191 of file SLEBase.h.

◆ SLEBase() [8/8]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::SLEBase ( Keylet const & key,
ApplyViewContext const & ctx,
beast::Journal j = beast::Journal{beast::Journal::getNullSink()} )
explicit

Constructor for writable context, for call sites that hold an ApplyViewContext (peek from ctx.view by keylet).

ctx.tx is not retained: this exists purely so transactors can pass the context they already have instead of spelling out ctx.view. If an entry ever needs the applying transaction, store it here rather than adding another overload.

Definition at line 212 of file SLEBase.h.

Member Function Documentation

◆ operator=() [1/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
SLEBase & xrpl::SLEBase< ViewT, EntryType >::operator= ( SLEBase< ViewT, EntryType > const & )
delete

◆ operator=() [2/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
SLEBase & xrpl::SLEBase< ViewT, EntryType >::operator= ( SLEBase< ViewT, EntryType > && )
delete

◆ exists()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
bool xrpl::SLEBase< ViewT, EntryType >::exists ( ) const
nodiscard

Returns true if the ledger entry exists.

Definition at line 227 of file SLEBase.h.

◆ operator bool()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
xrpl::SLEBase< ViewT, EntryType >::operator bool ( ) const
explicit

Explicit conversion to bool for convenient existence checking.

Definition at line 236 of file SLEBase.h.

◆ rawSle()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
SLE::const_pointer xrpl::SLEBase< ViewT, EntryType >::rawSle ( ) const
nodiscard

Returns the underlying SLE for read access.

Prefer operator-> / operator* for field access; this is for the call sites that need the shared_ptr itself.

Definition at line 248 of file SLEBase.h.

◆ type()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
LedgerEntryType xrpl::SLEBase< ViewT, EntryType >::type ( ) const
nodiscard

Returns the ledger entry type of this entry.

For a per-type entry this is kEntryType, known at compile time and valid whether or not the entry exists. Only the generic ReadOnlySLE / WritableSLE aliases have to read it back out of the SLE.

Exceptions
std::logic_errorfor a generic (ltANY) entry if exists() is false.

Definition at line 264 of file SLEBase.h.

◆ keylet()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
Keylet xrpl::SLEBase< ViewT, EntryType >::keylet ( ) const
nodiscard

Returns the keylet identifying this entry.

Writable entries keep the keylet they were built from, so it is valid even before newSLE(). Read-only entries derive it from the SLE, which must therefore exist.

Exceptions
std::logic_errorfor a read-only entry if exists() is false.

Definition at line 288 of file SLEBase.h.

◆ key()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
UInt256 xrpl::SLEBase< ViewT, EntryType >::key ( ) const
nodiscard

Returns the ledger key of this entry.

Exceptions
std::logic_errorsame as keylet(): for read-only entries, if exists() is false.

Definition at line 313 of file SLEBase.h.

◆ readView()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
ReadView const & xrpl::SLEBase< ViewT, EntryType >::readView ( ) const
nodiscard

Returns the read view (always available; ApplyView inherits ReadView).

Definition at line 322 of file SLEBase.h.

◆ operator->() [1/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
STLedgerEntry const * xrpl::SLEBase< ViewT, EntryType >::operator-> ( ) const

Const dereference operators (always available).

Exceptions
std::logic_errorif exists() is false.

Definition at line 333 of file SLEBase.h.

◆ operator*() [1/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
STLedgerEntry const & xrpl::SLEBase< ViewT, EntryType >::operator* ( ) const

Definition at line 341 of file SLEBase.h.

◆ mutableRawSle()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
SlePtrType const & xrpl::SLEBase< ViewT, EntryType >::mutableRawSle ( )
nodiscard

Returns the underlying SLE for write access.

Prefer operator-> / operator* for field access; this is for the call sites that need the shared_ptr itself.

Definition at line 361 of file SLEBase.h.

◆ applyView()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
ApplyView & xrpl::SLEBase< ViewT, EntryType >::applyView ( )
nodiscard

Returns the apply view for write operations.

Definition at line 371 of file SLEBase.h.

◆ operator->() [2/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
STLedgerEntry * xrpl::SLEBase< ViewT, EntryType >::operator-> ( )

Mutable dereference operators.

Exceptions
std::logic_errorif exists() is false.

Definition at line 383 of file SLEBase.h.

◆ operator*() [2/2]

template<typename ViewT, LedgerEntryType EntryType = ltANY>
STLedgerEntry & xrpl::SLEBase< ViewT, EntryType >::operator* ( )

Definition at line 392 of file SLEBase.h.

◆ insert()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
void xrpl::SLEBase< ViewT, EntryType >::insert ( )

Inserts the entry into the view.

Exceptions
std::logic_errorif exists() is false.

Definition at line 406 of file SLEBase.h.

◆ erase()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
void xrpl::SLEBase< ViewT, EntryType >::erase ( )

Erases the entry from the view.

Drops the SLE afterwards, so the entry reports !exists() and any further use throws here rather than either throwing from deep inside ApplyStateTable or – worse – silently succeeding. For an entry that already existed, ApplyStateTable::erase keeps holding this exact SLE and builds the DeletedNode's FinalFields from it, so a write through the entry after erase() would land in transaction metadata with no diagnostic at all.

Exceptions
std::logic_errorif exists() is false.

Definition at line 428 of file SLEBase.h.

◆ update()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
void xrpl::SLEBase< ViewT, EntryType >::update ( )
Exceptions
std::logic_errorif exists() is false.

Definition at line 441 of file SLEBase.h.

◆ newSLE()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
void xrpl::SLEBase< ViewT, EntryType >::newSLE ( )
Exceptions
std::logic_errorif exists() is true: newSLE() would otherwise silently discard the SLE already held.

Definition at line 454 of file SLEBase.h.

◆ journal()

template<typename ViewT, LedgerEntryType EntryType = ltANY>
beast::Journal xrpl::SLEBase< ViewT, EntryType >::journal ( ) const
nodiscard

Definition at line 463 of file SLEBase.h.

Member Data Documentation

◆ kIsWritable

template<typename ViewT, LedgerEntryType EntryType = ltANY>
bool xrpl::SLEBase< ViewT, EntryType >::kIsWritable = IsWritableView<ViewT>
staticconstexpr

Definition at line 94 of file SLEBase.h.

◆ kEntryType

template<typename ViewT, LedgerEntryType EntryType = ltANY>
LedgerEntryType xrpl::SLEBase< ViewT, EntryType >::kEntryType = EntryType
staticconstexpr

Definition at line 98 of file SLEBase.h.

◆ kIsTyped

template<typename ViewT, LedgerEntryType EntryType = ltANY>
bool xrpl::SLEBase< ViewT, EntryType >::kIsTyped = (EntryType != ltANY)
staticconstexpr

Definition at line 99 of file SLEBase.h.

◆ view_

template<typename ViewT, LedgerEntryType EntryType = ltANY>
ViewRefType xrpl::SLEBase< ViewT, EntryType >::view_
protected

Definition at line 469 of file SLEBase.h.

◆ key_

template<typename ViewT, LedgerEntryType EntryType = ltANY>
std::conditional_t<kIsWritable, Keylet, Empty> xrpl::SLEBase< ViewT, EntryType >::key_
protected

Definition at line 480 of file SLEBase.h.

◆ sle_

template<typename ViewT, LedgerEntryType EntryType = ltANY>
SlePtrType xrpl::SLEBase< ViewT, EntryType >::sle_ {}
protected

Definition at line 482 of file SLEBase.h.

◆ j_

template<typename ViewT, LedgerEntryType EntryType = ltANY>
beast::Journal xrpl::SLEBase< ViewT, EntryType >::j_
protected

Definition at line 483 of file SLEBase.h.