xrpld
Loading...
Searching...
No Matches
xrpl::OpenView Class Referencefinalabstract

Writable ledger view that accumulates state and tx changes. More...

#include <OpenView.h>

Inheritance diagram for xrpl::OpenView:
Collaboration diagram for xrpl::OpenView:

Classes

struct  TxData
class  TxsIterImpl

Public Types

using tx_type = std::pair<std::shared_ptr<STTx const>, std::shared_ptr<STObject const>>
using key_type = uint256
using mapped_type = SLE::const_pointer

Public Member Functions

 OpenView ()=delete
OpenViewoperator= (OpenView &&)=delete
OpenViewoperator= (OpenView const &)=delete
 OpenView (OpenView &&)=default
 OpenView (OpenView const &)
 Construct a shallow copy.
 OpenView (OpenLedgerT, ReadView const *base, Rules rules, std::shared_ptr< void const > hold=nullptr)
 Construct an open ledger view.
 OpenView (OpenLedgerT, Rules const &rules, std::shared_ptr< ReadView const > const &base)
 OpenView (BatchViewT, OpenView &base)
 OpenView (ReadView const *base, std::shared_ptr< void const > hold=nullptr)
 Construct a new last closed ledger.
bool open () const override
 Returns true if this reflects an open ledger.
std::size_t txCount () const
 Return the number of tx inserted since creation.
void apply (TxsRawView &to) const
 Apply changes.
LedgerHeader const & header () const override
 Returns information about the ledger.
Fees const & fees () const override
 Returns the fees for the base ledger.
Rules const & rules () const override
 Returns the tx processing rules.
bool exists (Keylet const &k) const override
 Determine if a state item exists.
std::optional< key_typesucc (key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
 Return the key of the next state item.
SLE::const_pointer read (Keylet const &k) const override
 Return the state item associated with a key.
std::unique_ptr< SlesType::iter_base > slesBegin () const override
std::unique_ptr< SlesType::iter_base > slesEnd () const override
std::unique_ptr< SlesType::iter_base > slesUpperBound (uint256 const &key) const override
std::unique_ptr< TxsType::iter_base > txsBegin () const override
std::unique_ptr< TxsType::iter_base > txsEnd () const override
bool txExists (key_type const &key) const override
 Returns true if a tx exists in the tx map.
tx_type txRead (key_type const &key) const override
 Read a transaction from the tx map.
void rawErase (SLE::ref sle) override
 Delete an existing state item.
void rawInsert (SLE::ref sle) override
 Unconditionally insert a state item.
void rawReplace (SLE::ref sle) override
 Unconditionally replace a state item.
void rawDestroyXRP (XRPAmount const &fee) override
 Destroy XRP.
void rawTxInsert (key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
 Add a transaction to the tx map.
NetClock::time_point parentCloseTime () const
 Returns the close time of the previous ledger.
LedgerIndex seq () const
 Returns the sequence number of the base ledger.
virtual STAmount balanceHookIOU (AccountID const &account, AccountID const &issuer, STAmount const &amount) const
virtual STAmount balanceHookMPT (AccountID const &account, MPTIssue const &issue, std::int64_t amount) const
virtual STAmount balanceHookSelfIssueMPT (MPTIssue const &issue, std::int64_t amount) const
virtual std::uint32_t ownerCountHook (AccountID const &account, std::uint32_t count) const
virtual std::unique_ptr< SlesType::iter_base > slesUpperBound (key_type const &key) const =0

Public Attributes

SlesType sles
 Iterable range of ledger state items.
TxsType txs

Private Types

using txs_map

Private Attributes

std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonicResource_
txs_map txs_
Rules rules_
LedgerHeader header_
ReadView const * base_
detail::RawStateTable items_
std::shared_ptr< void const > hold_
std::size_t baseTxCount_ = 0
 In batch mode, the number of transactions already executed.
bool open_ = true

Static Private Attributes

static constexpr size_t kInitialBufferSize = kilobytes(256)

Detailed Description

Writable ledger view that accumulates state and tx changes.

Note
Presented as ReadView to clients.

Definition at line 44 of file OpenView.h.

Member Typedef Documentation

◆ txs_map

using xrpl::OpenView::txs_map
private
Initial value:
boost::container::pmr::polymorphic_allocator<std::pair<key_type const, TxData>>>
uint256 key_type
Definition ReadView.h:35

Definition at line 71 of file OpenView.h.

◆ tx_type

Definition at line 33 of file ReadView.h.

◆ key_type

using xrpl::ReadView::key_type = uint256
inherited

Definition at line 35 of file ReadView.h.

◆ mapped_type

Definition at line 37 of file ReadView.h.

Constructor & Destructor Documentation

◆ OpenView() [1/7]

xrpl::OpenView::OpenView ( )
delete

◆ OpenView() [2/7]

xrpl::OpenView::OpenView ( OpenView && )
default

◆ OpenView() [3/7]

xrpl::OpenView::OpenView ( OpenView const & rhs)

Construct a shallow copy.

Effects:

Creates a new object with a copy of
the modification state table.

The objects managed by shared pointers are not duplicated but shared between instances. Since the SLEs are immutable, calls on the RawView interface cannot break invariants.

Definition at line 78 of file OpenView.cpp.

◆ OpenView() [4/7]

xrpl::OpenView::OpenView ( OpenLedgerT ,
ReadView const * base,
Rules rules,
std::shared_ptr< void const > hold = nullptr )

Construct an open ledger view.

Effects:

The sequence number is set to the
sequence number of parent plus one.

The parentCloseTime is set to the
closeTime of parent.

If `hold` is not nullptr, retains
ownership of a copy of `hold` until
the MetaView is destroyed.

Calls to rules() will return the
rules provided on construction.

The tx list starts empty and will contain all newly inserted tx.

Definition at line 91 of file OpenView.cpp.

◆ OpenView() [5/7]

xrpl::OpenView::OpenView ( OpenLedgerT ,
Rules const & rules,
std::shared_ptr< ReadView const > const & base )

Definition at line 141 of file OpenView.h.

◆ OpenView() [6/7]

xrpl::OpenView::OpenView ( BatchViewT ,
OpenView & base )

Definition at line 146 of file OpenView.h.

◆ OpenView() [7/7]

xrpl::OpenView::OpenView ( ReadView const * base,
std::shared_ptr< void const > hold = nullptr )

Construct a new last closed ledger.

Effects:

The LedgerHeader is copied from the base.

The rules are inherited from the base.

The tx list starts empty and will contain all newly inserted tx.

Definition at line 107 of file OpenView.cpp.

Member Function Documentation

◆ operator=() [1/2]

OpenView & xrpl::OpenView::operator= ( OpenView && )
delete

◆ operator=() [2/2]

OpenView & xrpl::OpenView::operator= ( OpenView const & )
delete

◆ open()

bool xrpl::OpenView::open ( ) const
overridevirtual

Returns true if this reflects an open ledger.

Implements xrpl::ReadView.

Definition at line 166 of file OpenView.h.

◆ txCount()

std::size_t xrpl::OpenView::txCount ( ) const

Return the number of tx inserted since creation.

This is used to set the "apply ordinal" when calculating transaction metadata.

Definition at line 120 of file OpenView.cpp.

◆ apply()

void xrpl::OpenView::apply ( TxsRawView & to) const

Apply changes.

Definition at line 126 of file OpenView.cpp.

◆ header()

LedgerHeader const & xrpl::OpenView::header ( ) const
overridevirtual

Returns information about the ledger.

Implements xrpl::ReadView.

Definition at line 136 of file OpenView.cpp.

◆ fees()

Fees const & xrpl::OpenView::fees ( ) const
overridevirtual

Returns the fees for the base ledger.

Implements xrpl::ReadView.

Definition at line 142 of file OpenView.cpp.

◆ rules()

Rules const & xrpl::OpenView::rules ( ) const
overridevirtual

Returns the tx processing rules.

Implements xrpl::ReadView.

Definition at line 148 of file OpenView.cpp.

◆ exists()

bool xrpl::OpenView::exists ( Keylet const & k) const
overridevirtual

Determine if a state item exists.

Note
This can be more efficient than calling read.
Returns
true if a SLE is associated with the specified key.

Implements xrpl::ReadView.

Definition at line 154 of file OpenView.cpp.

◆ succ()

auto xrpl::OpenView::succ ( key_type const & key,
std::optional< key_type > const & last = std::nullopt ) const
overridevirtual

Return the key of the next state item.

This returns the key of the first state item whose key is greater than the specified key. If no such key is present, std::nullopt is returned.

If last is engaged, returns std::nullopt when the key returned would be outside the open interval (key, last).

Implements xrpl::ReadView.

Definition at line 160 of file OpenView.cpp.

◆ read()

SLE::const_pointer xrpl::OpenView::read ( Keylet const & k) const
overridevirtual

Return the state item associated with a key.

Effects: If the key exists, gives the caller ownership of the non-modifiable corresponding SLE.

Note
While the returned SLE is const from the perspective of the caller, it can be changed by other callers through raw operations.
Returns
nullptr if the key is not present or if the type does not match.

Implements xrpl::ReadView.

Definition at line 167 of file OpenView.cpp.

◆ slesBegin()

auto xrpl::OpenView::slesBegin ( ) const
overridevirtual

Implements xrpl::ReadView.

Definition at line 173 of file OpenView.cpp.

◆ slesEnd()

auto xrpl::OpenView::slesEnd ( ) const
overridevirtual

Implements xrpl::ReadView.

Definition at line 179 of file OpenView.cpp.

◆ slesUpperBound() [1/2]

auto xrpl::OpenView::slesUpperBound ( uint256 const & key) const
override

Definition at line 185 of file OpenView.cpp.

◆ txsBegin()

auto xrpl::OpenView::txsBegin ( ) const
overridevirtual

Implements xrpl::ReadView.

Definition at line 191 of file OpenView.cpp.

◆ txsEnd()

auto xrpl::OpenView::txsEnd ( ) const
overridevirtual

Implements xrpl::ReadView.

Definition at line 197 of file OpenView.cpp.

◆ txExists()

bool xrpl::OpenView::txExists ( key_type const & key) const
overridevirtual

Returns true if a tx exists in the tx map.

A tx exists in the map if it is part of the base ledger, or if it is a newly inserted tx.

Implements xrpl::ReadView.

Definition at line 203 of file OpenView.cpp.

◆ txRead()

auto xrpl::OpenView::txRead ( key_type const & key) const
overridevirtual

Read a transaction from the tx map.

If the view represents an open ledger, the metadata object will be empty.

Returns
A pair of nullptr if the key is not found in the tx map.

Implements xrpl::ReadView.

Definition at line 209 of file OpenView.cpp.

◆ rawErase()

void xrpl::OpenView::rawErase ( SLE::ref sle)
overridevirtual

Delete an existing state item.

The SLE is provided so the implementation can calculate metadata.

Implements xrpl::RawView.

Definition at line 231 of file OpenView.cpp.

◆ rawInsert()

void xrpl::OpenView::rawInsert ( SLE::ref sle)
overridevirtual

Unconditionally insert a state item.

Requirements: The key must not already exist.

Effects:

The key is associated with the SLE.
Note
The key is taken from the SLE

Implements xrpl::RawView.

Definition at line 237 of file OpenView.cpp.

◆ rawReplace()

void xrpl::OpenView::rawReplace ( SLE::ref sle)
overridevirtual

Unconditionally replace a state item.

Requirements:

The key must exist.

Effects:

The key is associated with the SLE.
Note
The key is taken from the SLE

Implements xrpl::RawView.

Definition at line 243 of file OpenView.cpp.

◆ rawDestroyXRP()

void xrpl::OpenView::rawDestroyXRP ( XRPAmount const & fee)
overridevirtual

Destroy XRP.

This is used to pay for transaction fees.

Implements xrpl::RawView.

Definition at line 249 of file OpenView.cpp.

◆ rawTxInsert()

void xrpl::OpenView::rawTxInsert ( key_type const & key,
std::shared_ptr< Serializer const > const & txn,
std::shared_ptr< Serializer const > const & metaData )
overridevirtual

Add a transaction to the tx map.

Closed ledgers must have metadata, while open ledgers omit metadata.

Implements xrpl::TxsRawView.

Definition at line 259 of file OpenView.cpp.

◆ parentCloseTime()

NetClock::time_point xrpl::ReadView::parentCloseTime ( ) const
nodiscardinherited

Returns the close time of the previous ledger.

Definition at line 90 of file ReadView.h.

◆ seq()

LedgerIndex xrpl::ReadView::seq ( ) const
nodiscardinherited

Returns the sequence number of the base ledger.

Definition at line 97 of file ReadView.h.

◆ balanceHookIOU()

virtual STAmount xrpl::ReadView::balanceHookIOU ( AccountID const & account,
AccountID const & issuer,
STAmount const & amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 155 of file ReadView.h.

◆ balanceHookMPT()

virtual STAmount xrpl::ReadView::balanceHookMPT ( AccountID const & account,
MPTIssue const & issue,
std::int64_t amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 165 of file ReadView.h.

◆ balanceHookSelfIssueMPT()

virtual STAmount xrpl::ReadView::balanceHookSelfIssueMPT ( MPTIssue const & issue,
std::int64_t amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 175 of file ReadView.h.

◆ ownerCountHook()

virtual std::uint32_t xrpl::ReadView::ownerCountHook ( AccountID const & account,
std::uint32_t count ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 186 of file ReadView.h.

◆ slesUpperBound() [2/2]

virtual std::unique_ptr< SlesType::iter_base > xrpl::ReadView::slesUpperBound ( key_type const & key) const
nodiscardpure virtualinherited

Member Data Documentation

◆ kInitialBufferSize

size_t xrpl::OpenView::kInitialBufferSize = kilobytes(256)
staticconstexprprivate

Definition at line 50 of file OpenView.h.

◆ monotonicResource_

std::unique_ptr<boost::container::pmr::monotonic_buffer_resource> xrpl::OpenView::monotonicResource_
private

Definition at line 79 of file OpenView.h.

◆ txs_

txs_map xrpl::OpenView::txs_
private

Definition at line 80 of file OpenView.h.

◆ rules_

Rules xrpl::OpenView::rules_
private

Definition at line 81 of file OpenView.h.

◆ header_

LedgerHeader xrpl::OpenView::header_
private

Definition at line 82 of file OpenView.h.

◆ base_

ReadView const* xrpl::OpenView::base_
private

Definition at line 83 of file OpenView.h.

◆ items_

detail::RawStateTable xrpl::OpenView::items_
private

Definition at line 84 of file OpenView.h.

◆ hold_

std::shared_ptr<void const> xrpl::OpenView::hold_
private

Definition at line 85 of file OpenView.h.

◆ baseTxCount_

std::size_t xrpl::OpenView::baseTxCount_ = 0
private

In batch mode, the number of transactions already executed.

Definition at line 88 of file OpenView.h.

◆ open_

bool xrpl::OpenView::open_ = true
private

Definition at line 90 of file OpenView.h.

◆ sles

SlesType xrpl::ReadView::sles
inherited

Iterable range of ledger state items.

Note
Visiting each state entry in the ledger can become quite expensive as the ledger grows.

Definition at line 239 of file ReadView.h.

◆ txs

TxsType xrpl::ReadView::txs
inherited

Definition at line 242 of file ReadView.h.