rippled
Public Types | Public Member Functions | Public Attributes | Private Member Functions | List of all members
ripple::ApplyView Class Referenceabstract

Writeable view to a ledger, for applying a transaction. More...

Inheritance diagram for ripple::ApplyView:
Inheritance graph
[legend]
Collaboration diagram for ripple::ApplyView:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 ApplyView ()=default
 
virtual ApplyFlags flags () const =0
 Returns the tx apply flags. More...
 
virtual std::shared_ptr< SLEpeek (Keylet const &k)=0
 Prepare to modify the SLE associated with key. More...
 
virtual void erase (std::shared_ptr< SLE > const &sle)=0
 Remove a peeked SLE. More...
 
virtual void insert (std::shared_ptr< SLE > const &sle)=0
 Insert a new state SLE. More...
 
bool dirDelete (Keylet const &directory, std::function< void(uint256 const &)> const &)
 Remove the specified directory, invoking the callback for every node. More...
 
bool emptyDirDelete (Keylet const &directory)
 Remove the specified directory, if it is empty. More...
 
virtual LedgerInfo const & info () const =0
 Returns information about the ledger. More...
 
virtual bool open () const =0
 Returns true if this reflects an open ledger. More...
 
NetClock::time_point parentCloseTime () const
 Returns the close time of the previous ledger. More...
 
LedgerIndex seq () const
 Returns the sequence number of the base ledger. More...
 
virtual Fees const & fees () const =0
 Returns the fees for the base ledger. More...
 
virtual Rules const & rules () const =0
 Returns the tx processing rules. More...
 
virtual bool exists (Keylet const &k) const =0
 Determine if a state item exists. More...
 
virtual std::optional< key_typesucc (key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
 Return the key of the next state item. More...
 
virtual std::shared_ptr< SLE const > read (Keylet const &k) const =0
 Return the state item associated with a key. More...
 
virtual STAmount balanceHook (AccountID const &account, AccountID const &issuer, STAmount const &amount) const
 
virtual std::uint32_t ownerCountHook (AccountID const &account, std::uint32_t count) const
 
virtual std::unique_ptr< sles_type::iter_baseslesBegin () const =0
 
virtual std::unique_ptr< sles_type::iter_baseslesEnd () const =0
 
virtual std::unique_ptr< sles_type::iter_baseslesUpperBound (key_type const &key) const =0
 
virtual std::unique_ptr< txs_type::iter_basetxsBegin () const =0
 
virtual std::unique_ptr< txs_type::iter_basetxsEnd () const =0
 
virtual bool txExists (key_type const &key) const =0
 Returns true if a tx exists in the tx map. More...
 
virtual tx_type txRead (key_type const &key) const =0
 Read a transaction from the tx map. More...
 

Public Attributes

sles_type sles
 Iterable range of ledger state items. More...
 
txs_type txs
 

Private Member Functions

std::optional< std::uint64_tdirAdd (bool preserveOrder, Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
 Add an entry to a directory using the specified insert strategy. More...
 
virtual void update (std::shared_ptr< SLE > const &sle)=0
 Indicate changes to a peeked SLE. More...
 
virtual void creditHook (AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
 
virtual void adjustOwnerCountHook (AccountID const &account, std::uint32_t cur, std::uint32_t next)
 
std::optional< std::uint64_tdirAppend (Keylet const &directory, Keylet const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
 Append an entry to a directory. More...
 

Detailed Description

Writeable view to a ledger, for applying a transaction.

This refinement of ReadView provides an interface where the SLE can be "checked out" for modifications and put back in an updated or removed state. Also added is an interface to provide contextual information necessary to calculate the results of transaction processing, including the metadata if the view is later applied to the parent (using an interface in the derived class). The context info also includes values from the base ledger such as sequence number and the network time.

This allows implementations to journal changes made to the state items in a ledger, with the option to apply those changes to the base or discard the changes without affecting the base.

Typical usage is to call read() for non-mutating operations.

For mutating operations the sequence is as follows:

Add a new value v.insert(sle);

Check out a value for modification sle = v.peek(k);

Indicate that changes were made v.update(sle)

Or, erase the value v.erase(sle)

The invariant is that insert, update, and erase may not be called with any SLE which belongs to different view.

Definition at line 134 of file ApplyView.h.

Member Typedef Documentation

◆ tx_type

Definition at line 129 of file ReadView.h.

◆ key_type

Definition at line 131 of file ReadView.h.

◆ mapped_type

Definition at line 133 of file ReadView.h.

Constructor & Destructor Documentation

◆ ApplyView()

ripple::ApplyView::ApplyView ( )
default

Member Function Documentation

◆ dirAdd()

std::optional< std::uint64_t > ripple::ApplyView::dirAdd ( bool  preserveOrder,
Keylet const &  directory,
uint256 const &  key,
std::function< void(std::shared_ptr< SLE > const &)> const &  describe 
)
private

Add an entry to a directory using the specified insert strategy.

Definition at line 28 of file ApplyView.cpp.

◆ flags()

virtual ApplyFlags ripple::ApplyView::flags ( ) const
pure virtual

Returns the tx apply flags.

Flags can affect the outcome of transaction processing. For example, transactions applied to an open ledger generate "local" failures, while transactions applied to the consensus ledger produce hard failures (and claim a fee).

Implemented in ripple::detail::ApplyViewBase.

◆ peek()

virtual std::shared_ptr<SLE> ripple::ApplyView::peek ( Keylet const &  k)
pure virtual

Prepare to modify the SLE associated with key.

Effects:

Gives the caller ownership of a modifiable
SLE associated with the specified key.

The returned SLE may be used in a subsequent call to erase or update.

The SLE must not be passed to any other ApplyView.

Returns
nullptr if the key is not present

Implemented in ripple::detail::ApplyViewBase.

◆ erase()

virtual void ripple::ApplyView::erase ( std::shared_ptr< SLE > const &  sle)
pure virtual

Remove a peeked SLE.

Requirements:

`sle` was obtained from prior call to peek()
on this instance of the RawView.

Effects:

The key is no longer associated with the SLE.

Implemented in ripple::detail::ApplyViewBase.

◆ insert()

virtual void ripple::ApplyView::insert ( std::shared_ptr< SLE > const &  sle)
pure virtual

Insert a new state SLE.

Requirements:

`sle` was not obtained from any calls to
peek() on any instances of RawView.

The SLE's key must not already exist.

Effects:

The key in the state map is associated
with the SLE.

The RawView acquires ownership of the shared_ptr.
Note
The key is taken from the SLE

Implemented in ripple::detail::ApplyViewBase.

◆ update()

virtual void ripple::ApplyView::update ( std::shared_ptr< SLE > const &  sle)
pure virtual

Indicate changes to a peeked SLE.

Requirements:

The SLE's key must exist.

`sle` was obtained from prior call to peek()
on this instance of the RawView.

Effects:

The SLE is updated
Note
The key is taken from the SLE

Implemented in ripple::detail::ApplyViewBase.

◆ creditHook()

virtual void ripple::ApplyView::creditHook ( AccountID const &  from,
AccountID const &  to,
STAmount const &  amount,
STAmount const &  preCreditBalance 
)
virtual

Reimplemented in ripple::PaymentSandbox.

Definition at line 235 of file ApplyView.h.

◆ adjustOwnerCountHook()

virtual void ripple::ApplyView::adjustOwnerCountHook ( AccountID const &  account,
std::uint32_t  cur,
std::uint32_t  next 
)
virtual

Reimplemented in ripple::PaymentSandbox.

Definition at line 246 of file ApplyView.h.

◆ dirAppend()

std::optional<std::uint64_t> ripple::ApplyView::dirAppend ( Keylet const &  directory,
Keylet const &  key,
std::function< void(std::shared_ptr< SLE > const &)> const &  describe 
)

Append an entry to a directory.

Entries in the directory will be stored in order of insertion, i.e. new entries will always be added at the tail end of the last page.

Parameters
directorythe base of the directory
keythe entry to insert
describecallback to add required entries to a new page
Returns
a std::optional which, if insertion was successful, will contain the page number in which the item was stored.
Note
this function may create a page (including a root page), if no page with space is available. This function will only fail if the page counter exceeds the protocol-defined maximum number of allowable pages.

Definition at line 272 of file ApplyView.h.

◆ dirInsert() [1/2]

std::optional<std::uint64_t> ripple::ApplyView::dirInsert ( Keylet const &  directory,
uint256 const &  key,
std::function< void(std::shared_ptr< SLE > const &)> const &  describe 
)

Insert an entry to a directory.

Entries in the directory will be stored in a semi-random order, but each page will be maintained in sorted order.

Parameters
directorythe base of the directory
keythe entry to insert
describecallback to add required entries to a new page
Returns
a std::optional which, if insertion was successful, will contain the page number in which the item was stored.
Note
this function may create a page (including a root page), if no page with space is available.this function will only fail if the page counter exceeds the protocol-defined maximum number of allowable pages.

Definition at line 306 of file ApplyView.h.

◆ dirInsert() [2/2]

std::optional<std::uint64_t> ripple::ApplyView::dirInsert ( Keylet const &  directory,
Keylet const &  key,
std::function< void(std::shared_ptr< SLE > const &)> const &  describe 
)

Definition at line 315 of file ApplyView.h.

◆ dirRemove() [1/2]

bool ripple::ApplyView::dirRemove ( Keylet const &  directory,
std::uint64_t  page,
uint256 const &  key,
bool  keepRoot 
)

Remove an entry from a directory.

Parameters
directorythe base of the directory
pagethe page number for this page
keythe entry to remove
keepRootif deleting the last entry, don't delete the root page (i.e. the directory itself).
Returns
true if the entry was found and deleted and false otherwise.
Note
This function will remove zero or more pages from the directory; the root page will not be deleted even if it is empty, unless keepRoot is not set and the directory is empty.

Definition at line 189 of file ApplyView.cpp.

◆ dirRemove() [2/2]

bool ripple::ApplyView::dirRemove ( Keylet const &  directory,
std::uint64_t  page,
Keylet const &  key,
bool  keepRoot 
)

Definition at line 348 of file ApplyView.h.

◆ dirDelete()

bool ripple::ApplyView::dirDelete ( Keylet const &  directory,
std::function< void(uint256 const &)> const &  callback 
)

Remove the specified directory, invoking the callback for every node.

Definition at line 338 of file ApplyView.cpp.

◆ emptyDirDelete()

bool ripple::ApplyView::emptyDirDelete ( Keylet const &  directory)

Remove the specified directory, if it is empty.

Parameters
directorythe identifier of the directory node to be deleted
Returns
true if the directory was found and was successfully deleted false otherwise.
Note
The function should only be called with the root entry (i.e. with the first page) of a directory.

Definition at line 125 of file ApplyView.cpp.

◆ info()

virtual LedgerInfo const& ripple::ReadView::info ( ) const
pure virtualinherited

Returns information about the ledger.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::CachedViewImpl, and ripple::detail::ApplyViewBase.

◆ open()

virtual bool ripple::ReadView::open ( ) const
pure virtualinherited

Returns true if this reflects an open ledger.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::CachedViewImpl, and ripple::detail::ApplyViewBase.

◆ parentCloseTime()

NetClock::time_point ripple::ReadView::parentCloseTime ( ) const
inherited

Returns the close time of the previous ledger.

Definition at line 186 of file ReadView.h.

◆ seq()

LedgerIndex ripple::ReadView::seq ( ) const
inherited

Returns the sequence number of the base ledger.

Definition at line 193 of file ReadView.h.

◆ fees()

virtual Fees const& ripple::ReadView::fees ( ) const
pure virtualinherited

Returns the fees for the base ledger.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::CachedViewImpl, and ripple::detail::ApplyViewBase.

◆ rules()

virtual Rules const& ripple::ReadView::rules ( ) const
pure virtualinherited

Returns the tx processing rules.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::CachedViewImpl, and ripple::detail::ApplyViewBase.

◆ exists()

virtual bool ripple::ReadView::exists ( Keylet const &  k) const
pure virtualinherited

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.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::CachedViewImpl, and ripple::detail::ApplyViewBase.

◆ succ()

virtual std::optional<key_type> ripple::ReadView::succ ( key_type const &  key,
std::optional< key_type > const &  last = std::nullopt 
) const
pure virtualinherited

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).

Implemented in ripple::Ledger, ripple::OpenView, and ripple::detail::ApplyViewBase.

◆ read()

virtual std::shared_ptr<SLE const> ripple::ReadView::read ( Keylet const &  k) const
pure virtualinherited

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.

Implemented in ripple::OpenView, ripple::Ledger, ripple::detail::ApplyViewBase, and ripple::detail::CachedViewImpl.

◆ balanceHook()

virtual STAmount ripple::ReadView::balanceHook ( AccountID const &  account,
AccountID const &  issuer,
STAmount const &  amount 
) const
virtualinherited

Reimplemented in ripple::PaymentSandbox.

Definition at line 253 of file ReadView.h.

◆ ownerCountHook()

virtual std::uint32_t ripple::ReadView::ownerCountHook ( AccountID const &  account,
std::uint32_t  count 
) const
virtualinherited

Reimplemented in ripple::PaymentSandbox.

Definition at line 267 of file ReadView.h.

◆ slesBegin()

virtual std::unique_ptr<sles_type::iter_base> ripple::ReadView::slesBegin ( ) const
pure virtualinherited

◆ slesEnd()

virtual std::unique_ptr<sles_type::iter_base> ripple::ReadView::slesEnd ( ) const
pure virtualinherited

◆ slesUpperBound()

virtual std::unique_ptr<sles_type::iter_base> ripple::ReadView::slesUpperBound ( key_type const &  key) const
pure virtualinherited

◆ txsBegin()

virtual std::unique_ptr<txs_type::iter_base> ripple::ReadView::txsBegin ( ) const
pure virtualinherited

◆ txsEnd()

virtual std::unique_ptr<txs_type::iter_base> ripple::ReadView::txsEnd ( ) const
pure virtualinherited

◆ txExists()

virtual bool ripple::ReadView::txExists ( key_type const &  key) const
pure virtualinherited

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.

Implemented in ripple::Ledger, ripple::OpenView, and ripple::detail::ApplyViewBase.

◆ txRead()

virtual tx_type ripple::ReadView::txRead ( key_type const &  key) const
pure virtualinherited

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.

Implemented in ripple::OpenView, ripple::Ledger, and ripple::detail::ApplyViewBase.

Member Data Documentation

◆ sles

sles_type ripple::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 320 of file ReadView.h.

◆ txs

txs_type ripple::ReadView::txs
inherited

Definition at line 323 of file ReadView.h.