xrpld
Loading...
Searching...
No Matches
xrpl::OrderBookDBImpl Class Referencefinal

#include <OrderBookDBImpl.h>

Inheritance diagram for xrpl::OrderBookDBImpl:
Collaboration diagram for xrpl::OrderBookDBImpl:

Public Member Functions

 OrderBookDBImpl (ServiceRegistry &registry, OrderBookDBConfig const &config)
void setup (std::shared_ptr< ReadView const > const &ledger) override
 Initialize or update the order book database with a new ledger.
void addOrderBook (Book const &book) override
 Add an order book to track.
std::vector< BookgetBooksByTakerPays (Asset const &asset, std::optional< Domain > const &domain=std::nullopt) override
 Get all order books that want a specific issue.
int getBookSize (Asset const &asset, std::optional< Domain > const &domain=std::nullopt) override
 Get the count of order books that want a specific issue.
bool isBookToXRP (Asset const &asset, std::optional< Domain > const &domain=std::nullopt) override
 Check if an order book to XRP exists for the given issue.
void update (std::shared_ptr< ReadView const > const &ledger)

Private Attributes

std::reference_wrapper< ServiceRegistryregistry_
int const pathSearchMax_
bool const standalone_
hardened_hash_map< Asset, hardened_hash_set< Asset > > allBooks_
hardened_hash_map< std::pair< Asset, Domain >, hardened_hash_set< Asset > > domainBooks_
hash_set< AssetxrpBooks_
hash_set< std::pair< Asset, Domain > > xrpDomainBooks_
std::recursive_mutex lock_
std::atomic< std::uint32_tseq_
beast::Journal const j_

Detailed Description

Definition at line 28 of file OrderBookDBImpl.h.

Constructor & Destructor Documentation

◆ OrderBookDBImpl()

xrpl::OrderBookDBImpl::OrderBookDBImpl ( ServiceRegistry & registry,
OrderBookDBConfig const & config )

Definition at line 33 of file OrderBookDBImpl.cpp.

Member Function Documentation

◆ setup()

void xrpl::OrderBookDBImpl::setup ( std::shared_ptr< ReadView const > const & ledger)
overridevirtual

Initialize or update the order book database with a new ledger.

This method should be called when a new ledger is accepted to update the order book database with the current state of all order books.

Parameters
ledgerThe ledger to scan for order books

Implements xrpl::OrderBookDB.

Definition at line 49 of file OrderBookDBImpl.cpp.

◆ addOrderBook()

void xrpl::OrderBookDBImpl::addOrderBook ( Book const & book)
overridevirtual

Add an order book to track.

Parameters
bookThe order book to add

Implements xrpl::OrderBookDB.

Definition at line 222 of file OrderBookDBImpl.cpp.

◆ getBooksByTakerPays()

std::vector< Book > xrpl::OrderBookDBImpl::getBooksByTakerPays ( Asset const & asset,
std::optional< Domain > const & domain = std::nullopt )
overridevirtual

Get all order books that want a specific issue.

Returns a list of all order books where the taker pays the specified issue. This is useful for pathfinding to find all possible next hops from a given currency.

Parameters
assetThe asset to search for
domainOptional domain restriction for the order book
Returns
Vector of books that want this issue

Implements xrpl::OrderBookDB.

Definition at line 249 of file OrderBookDBImpl.cpp.

◆ getBookSize()

int xrpl::OrderBookDBImpl::getBookSize ( Asset const & asset,
std::optional< Domain > const & domain = std::nullopt )
overridevirtual

Get the count of order books that want a specific issue.

Parameters
assetThe asset to search for
domainOptional domain restriction for the order book
Returns
Number of books that want this issue

Implements xrpl::OrderBookDB.

Definition at line 281 of file OrderBookDBImpl.cpp.

◆ isBookToXRP()

bool xrpl::OrderBookDBImpl::isBookToXRP ( Asset const & asset,
std::optional< Domain > const & domain = std::nullopt )
overridevirtual

Check if an order book to XRP exists for the given issue.

Parameters
assetThe asset to check
domainOptional domain restriction for the order book
Returns
true if a book from this issue to XRP exists

Implements xrpl::OrderBookDB.

Definition at line 300 of file OrderBookDBImpl.cpp.

◆ update()

void xrpl::OrderBookDBImpl::update ( std::shared_ptr< ReadView const > const & ledger)

Definition at line 92 of file OrderBookDBImpl.cpp.

Member Data Documentation

◆ registry_

std::reference_wrapper<ServiceRegistry> xrpl::OrderBookDBImpl::registry_
private

Definition at line 55 of file OrderBookDBImpl.h.

◆ pathSearchMax_

int const xrpl::OrderBookDBImpl::pathSearchMax_
private

Definition at line 56 of file OrderBookDBImpl.h.

◆ standalone_

bool const xrpl::OrderBookDBImpl::standalone_
private

Definition at line 57 of file OrderBookDBImpl.h.

◆ allBooks_

hardened_hash_map<Asset, hardened_hash_set<Asset> > xrpl::OrderBookDBImpl::allBooks_
private

Definition at line 60 of file OrderBookDBImpl.h.

◆ domainBooks_

hardened_hash_map<std::pair<Asset, Domain>, hardened_hash_set<Asset> > xrpl::OrderBookDBImpl::domainBooks_
private

Definition at line 62 of file OrderBookDBImpl.h.

◆ xrpBooks_

hash_set<Asset> xrpl::OrderBookDBImpl::xrpBooks_
private

Definition at line 65 of file OrderBookDBImpl.h.

◆ xrpDomainBooks_

hash_set<std::pair<Asset, Domain> > xrpl::OrderBookDBImpl::xrpDomainBooks_
private

Definition at line 68 of file OrderBookDBImpl.h.

◆ lock_

std::recursive_mutex xrpl::OrderBookDBImpl::lock_
private

Definition at line 70 of file OrderBookDBImpl.h.

◆ seq_

std::atomic<std::uint32_t> xrpl::OrderBookDBImpl::seq_
private

Definition at line 72 of file OrderBookDBImpl.h.

◆ j_

beast::Journal const xrpl::OrderBookDBImpl::j_
private

Definition at line 74 of file OrderBookDBImpl.h.