rippled
Public Types | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ripple::ApplyViewImpl Class Referencefinal

Editable, discardable view that can build metadata for one tx. More...

Inheritance diagram for ripple::ApplyViewImpl:
Inheritance graph
[legend]
Collaboration diagram for ripple::ApplyViewImpl:
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

 ApplyViewImpl ()=delete
 
 ApplyViewImpl (ApplyViewImpl const &)=delete
 
ApplyViewImploperator= (ApplyViewImpl &&)=delete
 
ApplyViewImploperator= (ApplyViewImpl const &)=delete
 
 ApplyViewImpl (ApplyViewImpl &&)=default
 
 ApplyViewImpl (ReadView const *base, ApplyFlags flags)
 
void apply (OpenView &to, STTx const &tx, TER ter, beast::Journal j)
 Apply the transaction. More...
 
void deliver (STAmount const &amount)
 Set the amount of currency delivered. More...
 
std::size_t size ()
 Get the number of modified entries. More...
 
void visit (OpenView &target, std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func)
 Visit modified entries. More...
 
bool open () const override
 Returns true if this reflects an open ledger. More...
 
LedgerInfo const & info () const override
 Returns information about the ledger. More...
 
Fees const & fees () const override
 Returns the fees for the base ledger. More...
 
Rules const & rules () const override
 Returns the tx processing rules. More...
 
bool exists (Keylet const &k) const override
 Determine if a state item exists. More...
 
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. More...
 
std::shared_ptr< SLE const > read (Keylet const &k) const override
 Return the state item associated with a key. More...
 
std::unique_ptr< sles_type::iter_baseslesBegin () const override
 
std::unique_ptr< sles_type::iter_baseslesEnd () const override
 
std::unique_ptr< sles_type::iter_baseslesUpperBound (uint256 const &key) const override
 
std::unique_ptr< txs_type::iter_basetxsBegin () const override
 
std::unique_ptr< txs_type::iter_basetxsEnd () const override
 
bool txExists (key_type const &key) const override
 Returns true if a tx exists in the tx map. More...
 
tx_type txRead (key_type const &key) const override
 Read a transaction from the tx map. More...
 
ApplyFlags flags () const override
 Returns the tx apply flags. More...
 
std::shared_ptr< SLEpeek (Keylet const &k) override
 Prepare to modify the SLE associated with key. More...
 
void erase (std::shared_ptr< SLE > const &sle) override
 Remove a peeked SLE. More...
 
void insert (std::shared_ptr< SLE > const &sle) override
 Insert a new state SLE. More...
 
void update (std::shared_ptr< SLE > const &sle) override
 Indicate changes to a peeked SLE. More...
 
void rawErase (std::shared_ptr< SLE > const &sle) override
 Delete an existing state item. More...
 
void rawInsert (std::shared_ptr< SLE > const &sle) override
 Unconditionally insert a state item. More...
 
void rawReplace (std::shared_ptr< SLE > const &sle) override
 Unconditionally replace a state item. More...
 
void rawDestroyXRP (XRPAmount const &feeDrops) override
 Destroy XRP. 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...
 
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 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
 

Public Attributes

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

Protected Attributes

ApplyFlags flags_
 
ReadView const * base_
 
detail::ApplyStateTable items_
 

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

Private Attributes

std::optional< STAmountdeliver_
 

Detailed Description

Editable, discardable view that can build metadata for one tx.

Iteration of the tx map is delegated to the base.

Note
Presented as ApplyView to clients.

Definition at line 36 of file ApplyViewImpl.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

◆ ApplyViewImpl() [1/4]

ripple::ApplyViewImpl::ApplyViewImpl ( )
delete

◆ ApplyViewImpl() [2/4]

ripple::ApplyViewImpl::ApplyViewImpl ( ApplyViewImpl const &  )
delete

◆ ApplyViewImpl() [3/4]

ripple::ApplyViewImpl::ApplyViewImpl ( ApplyViewImpl &&  )
default

◆ ApplyViewImpl() [4/4]

ripple::ApplyViewImpl::ApplyViewImpl ( ReadView const *  base,
ApplyFlags  flags 
)

Definition at line 26 of file ApplyViewImpl.cpp.

Member Function Documentation

◆ operator=() [1/2]

ApplyViewImpl& ripple::ApplyViewImpl::operator= ( ApplyViewImpl &&  )
delete

◆ operator=() [2/2]

ApplyViewImpl& ripple::ApplyViewImpl::operator= ( ApplyViewImpl const &  )
delete

◆ apply()

void ripple::ApplyViewImpl::apply ( OpenView to,
STTx const &  tx,
TER  ter,
beast::Journal  j 
)

Apply the transaction.

After a call to apply, the only valid operation on this object is to call the destructor.

Definition at line 32 of file ApplyViewImpl.cpp.

◆ deliver()

void ripple::ApplyViewImpl::deliver ( STAmount const &  amount)

Set the amount of currency delivered.

This value is used when generating metadata for payments, to set the DeliveredAmount field. If the amount is not specified, the field is excluded from the resulting metadata.

Definition at line 66 of file ApplyViewImpl.h.

◆ size()

std::size_t ripple::ApplyViewImpl::size ( )

Get the number of modified entries.

Definition at line 38 of file ApplyViewImpl.cpp.

◆ visit()

void ripple::ApplyViewImpl::visit ( OpenView target,
std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &  func 
)

Visit modified entries.

Definition at line 44 of file ApplyViewImpl.cpp.

◆ open()

bool ripple::detail::ApplyViewBase::open ( ) const
overridevirtualinherited

Returns true if this reflects an open ledger.

Implements ripple::ReadView.

Definition at line 34 of file ApplyViewBase.cpp.

◆ info()

LedgerInfo const & ripple::detail::ApplyViewBase::info ( ) const
overridevirtualinherited

Returns information about the ledger.

Implements ripple::ReadView.

Definition at line 40 of file ApplyViewBase.cpp.

◆ fees()

Fees const & ripple::detail::ApplyViewBase::fees ( ) const
overridevirtualinherited

Returns the fees for the base ledger.

Implements ripple::ReadView.

Definition at line 46 of file ApplyViewBase.cpp.

◆ rules()

Rules const & ripple::detail::ApplyViewBase::rules ( ) const
overridevirtualinherited

Returns the tx processing rules.

Implements ripple::ReadView.

Definition at line 52 of file ApplyViewBase.cpp.

◆ exists()

bool ripple::detail::ApplyViewBase::exists ( Keylet const &  k) const
overridevirtualinherited

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 ripple::ReadView.

Definition at line 58 of file ApplyViewBase.cpp.

◆ succ()

auto ripple::detail::ApplyViewBase::succ ( key_type const &  key,
std::optional< key_type > const &  last = std::nullopt 
) const
overridevirtualinherited

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 ripple::ReadView.

Definition at line 64 of file ApplyViewBase.cpp.

◆ read()

std::shared_ptr< SLE const > ripple::detail::ApplyViewBase::read ( Keylet const &  k) const
overridevirtualinherited

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 ripple::ReadView.

Definition at line 71 of file ApplyViewBase.cpp.

◆ slesBegin()

auto ripple::detail::ApplyViewBase::slesBegin ( ) const
overridevirtualinherited

Implements ripple::ReadView.

Definition at line 77 of file ApplyViewBase.cpp.

◆ slesEnd()

auto ripple::detail::ApplyViewBase::slesEnd ( ) const
overridevirtualinherited

Implements ripple::ReadView.

Definition at line 83 of file ApplyViewBase.cpp.

◆ slesUpperBound()

auto ripple::detail::ApplyViewBase::slesUpperBound ( uint256 const &  key) const
overridevirtualinherited

Implements ripple::ReadView.

Definition at line 89 of file ApplyViewBase.cpp.

◆ txsBegin()

auto ripple::detail::ApplyViewBase::txsBegin ( ) const
overridevirtualinherited

Implements ripple::ReadView.

Definition at line 96 of file ApplyViewBase.cpp.

◆ txsEnd()

auto ripple::detail::ApplyViewBase::txsEnd ( ) const
overridevirtualinherited

Implements ripple::ReadView.

Definition at line 102 of file ApplyViewBase.cpp.

◆ txExists()

bool ripple::detail::ApplyViewBase::txExists ( key_type const &  key) const
overridevirtualinherited

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 ripple::ReadView.

Definition at line 108 of file ApplyViewBase.cpp.

◆ txRead()

auto ripple::detail::ApplyViewBase::txRead ( key_type const &  key) const
overridevirtualinherited

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 ripple::ReadView.

Definition at line 114 of file ApplyViewBase.cpp.

◆ flags()

ApplyFlags ripple::detail::ApplyViewBase::flags ( ) const
overridevirtualinherited

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

Implements ripple::ApplyView.

Definition at line 122 of file ApplyViewBase.cpp.

◆ peek()

std::shared_ptr< SLE > ripple::detail::ApplyViewBase::peek ( Keylet const &  k)
overridevirtualinherited

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

Implements ripple::ApplyView.

Definition at line 128 of file ApplyViewBase.cpp.

◆ erase()

void ripple::detail::ApplyViewBase::erase ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

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.

Implements ripple::ApplyView.

Definition at line 134 of file ApplyViewBase.cpp.

◆ insert()

void ripple::detail::ApplyViewBase::insert ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

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

Implements ripple::ApplyView.

Definition at line 140 of file ApplyViewBase.cpp.

◆ update()

void ripple::detail::ApplyViewBase::update ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

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

Implements ripple::ApplyView.

Definition at line 146 of file ApplyViewBase.cpp.

◆ rawErase()

void ripple::detail::ApplyViewBase::rawErase ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

Delete an existing state item.

The SLE is provided so the implementation can calculate metadata.

Implements ripple::RawView.

Definition at line 154 of file ApplyViewBase.cpp.

◆ rawInsert()

void ripple::detail::ApplyViewBase::rawInsert ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

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 ripple::RawView.

Definition at line 160 of file ApplyViewBase.cpp.

◆ rawReplace()

void ripple::detail::ApplyViewBase::rawReplace ( std::shared_ptr< SLE > const &  sle)
overridevirtualinherited

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 ripple::RawView.

Definition at line 166 of file ApplyViewBase.cpp.

◆ rawDestroyXRP()

void ripple::detail::ApplyViewBase::rawDestroyXRP ( XRPAmount const &  fee)
overridevirtualinherited

Destroy XRP.

This is used to pay for transaction fees.

Implements ripple::RawView.

Definition at line 172 of file ApplyViewBase.cpp.

◆ 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 
)
privateinherited

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

Definition at line 28 of file ApplyView.cpp.

◆ creditHook()

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

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

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

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

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

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

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

Definition at line 348 of file ApplyView.h.

◆ dirDelete()

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

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

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.

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

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

Member Data Documentation

◆ deliver_

std::optional<STAmount> ripple::ApplyViewImpl::deliver_
private

Definition at line 88 of file ApplyViewImpl.h.

◆ flags_

ApplyFlags ripple::detail::ApplyViewBase::flags_
protectedinherited

Definition at line 123 of file ApplyViewBase.h.

◆ base_

ReadView const* ripple::detail::ApplyViewBase::base_
protectedinherited

Definition at line 124 of file ApplyViewBase.h.

◆ items_

detail::ApplyStateTable ripple::detail::ApplyViewBase::items_
protectedinherited

Definition at line 125 of file ApplyViewBase.h.

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