xrpld
Loading...
Searching...
No Matches
xrpl::SeqProxy Class Reference

A type that represents either a sequence value or a ticket value. More...

#include <SeqProxy.h>

Collaboration diagram for xrpl::SeqProxy:

Public Types

enum class  Type : std::uint8_t { Seq = 0 , Ticket }

Public Member Functions

constexpr SeqProxy (Type t, std::uint32_t v)
 SeqProxy (SeqProxy const &other)=default
SeqProxyoperator= (SeqProxy const &other)=default
constexpr std::uint32_t value () const
constexpr bool isSeq () const
constexpr bool isTicket () const
SeqProxyadvanceBy (std::uint32_t amount)

Static Public Member Functions

static constexpr SeqProxy rawSequence (std::uint32_t v)
 Factory function to return a sequence-based SeqProxy.
static constexpr SeqProxy rawTicket (std::uint32_t v)
 Factory function to return a ticket-based SeqProxy.

Private Attributes

std::uint32_t value_
Type type_

Friends

constexpr bool operator== (SeqProxy lhs, SeqProxy rhs)
constexpr bool operator< (SeqProxy lhs, SeqProxy rhs)
constexpr bool operator> (SeqProxy lhs, SeqProxy rhs)
constexpr bool operator>= (SeqProxy lhs, SeqProxy rhs)
constexpr bool operator<= (SeqProxy lhs, SeqProxy rhs)
std::ostreamoperator<< (std::ostream &os, SeqProxy seqProx)

Detailed Description

A type that represents either a sequence value or a ticket value.

We use the value() of a SeqProxy in places where a sequence was used before. An example of this is the sequence of an Offer stored in the ledger. We do the same thing with the in-ledger identifier of a Check, Payment Channel, and Escrow.

Why is this safe? If we use the SeqProxy::value(), how do we know that each ledger entry will be unique?

There are two components that make this safe:

  1. A "TicketCreate" transaction carefully avoids creating a ticket that corresponds with an already used Sequence or Ticket value. The transactor does this by referring to the account root's sequence number. Creating the ticket advances the account root's sequence number so the same ticket (or sequence) value cannot be used again.
  2. When a "TicketCreate" transaction creates a batch of tickets it advances the account root sequence to one past the largest created ticket.

    Therefore all tickets in a batch other than the first may never have the same value as a sequence on that same account. And since a ticket may only be used once there will never be any duplicates within this account.

Definition at line 36 of file SeqProxy.h.

Member Enumeration Documentation

◆ Type

enum class xrpl::SeqProxy::Type : std::uint8_t
strong
Enumerator
Seq 
Ticket 

Definition at line 39 of file SeqProxy.h.

Constructor & Destructor Documentation

◆ SeqProxy() [1/2]

xrpl::SeqProxy::SeqProxy ( Type t,
std::uint32_t v )
explicitconstexpr

Definition at line 46 of file SeqProxy.h.

◆ SeqProxy() [2/2]

xrpl::SeqProxy::SeqProxy ( SeqProxy const & other)
default

Member Function Documentation

◆ operator=()

SeqProxy & xrpl::SeqProxy::operator= ( SeqProxy const & other)
default

◆ rawSequence()

constexpr SeqProxy xrpl::SeqProxy::rawSequence ( std::uint32_t v)
staticconstexpr

Factory function to return a sequence-based SeqProxy.

Outside of tests, this function should only be used for "secondary" transaction sequences, e.g. sfOfferSequence, or sequence fields in an existing ledger object. DO NOT use this for the "primary" sequence of a transaction, sfSequence.

Definition at line 62 of file SeqProxy.h.

◆ rawTicket()

constexpr SeqProxy xrpl::SeqProxy::rawTicket ( std::uint32_t v)
staticconstexpr

Factory function to return a ticket-based SeqProxy.

Outside of tests, this function should only be used for "secondary" transaction sequences, e.g. sfOfferSequence, or sequence fields in an existing ledger object. DO NOT use this for the "primary" ticket sequence of a transaction, sfTicketSequence.

Definition at line 74 of file SeqProxy.h.

◆ value()

std::uint32_t xrpl::SeqProxy::value ( ) const
nodiscardconstexpr

Definition at line 80 of file SeqProxy.h.

◆ isSeq()

bool xrpl::SeqProxy::isSeq ( ) const
nodiscardconstexpr

Definition at line 86 of file SeqProxy.h.

◆ isTicket()

bool xrpl::SeqProxy::isTicket ( ) const
nodiscardconstexpr

Definition at line 92 of file SeqProxy.h.

◆ advanceBy()

SeqProxy & xrpl::SeqProxy::advanceBy ( std::uint32_t amount)

Definition at line 102 of file SeqProxy.h.

◆ operator==

bool operator== ( SeqProxy lhs,
SeqProxy rhs )
friend

Definition at line 119 of file SeqProxy.h.

◆ operator<

bool operator< ( SeqProxy lhs,
SeqProxy rhs )
friend

Definition at line 126 of file SeqProxy.h.

◆ operator>

bool operator> ( SeqProxy lhs,
SeqProxy rhs )
friend

Definition at line 135 of file SeqProxy.h.

◆ operator>=

bool operator>= ( SeqProxy lhs,
SeqProxy rhs )
friend

Definition at line 141 of file SeqProxy.h.

◆ operator<=

bool operator<= ( SeqProxy lhs,
SeqProxy rhs )
friend

Definition at line 146 of file SeqProxy.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
SeqProxy seqProx )
friend

Definition at line 152 of file SeqProxy.h.

Member Data Documentation

◆ value_

std::uint32_t xrpl::SeqProxy::value_
private

Definition at line 42 of file SeqProxy.h.

◆ type_

Type xrpl::SeqProxy::type_
private

Definition at line 43 of file SeqProxy.h.