rippled
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Attributes | List of all members
xrpl::OrderBookDBImpl Class Referencefinal

#include <OrderBookDBImpl.h>

Inheritance diagram for xrpl::OrderBookDBImpl:
Inheritance graph
[legend]
Collaboration diagram for xrpl::OrderBookDBImpl:
Collaboration graph
[legend]

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 (Issue const &issue, std::optional< Domain > const &domain=std::nullopt) override
 Get all order books that want a specific issue.
 
int getBookSize (Issue const &issue, std::optional< Domain > const &domain=std::nullopt) override
 Get the count of order books that want a specific issue.
 
bool isBookToXRP (Issue const &issue, 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)
 
void processTxn (std::shared_ptr< ReadView const > const &ledger, AcceptedLedgerTx const &alTx, MultiApiJson const &jvObj) override
 Process a transaction for order book tracking.
 
BookListeners::pointer getBookListeners (Book const &) override
 Get the book listeners for a book.
 
BookListeners::pointer makeBookListeners (Book const &) override
 Create a new book listeners for a book.
 

Private Types

using BookToListenersMap = hash_map< Book, BookListeners::pointer >
 

Private Attributes

std::reference_wrapper< ServiceRegistryregistry_
 
int const pathSearchMax_
 
bool const standalone_
 
hardened_hash_map< Issue, hardened_hash_set< Issue > > allBooks_
 
hardened_hash_map< std::pair< Issue, Domain >, hardened_hash_set< Issue > > domainBooks_
 
hash_set< IssuexrpBooks_
 
hash_set< std::pair< Issue, Domain > > xrpDomainBooks_
 
std::recursive_mutex mLock
 
BookToListenersMap mListeners
 
std::atomic< std::uint32_tseq_
 
beast::Journal const j_
 

Detailed Description

Definition at line 31 of file OrderBookDBImpl.h.

Member Typedef Documentation

◆ BookToListenersMap

Definition at line 87 of file OrderBookDBImpl.h.

Constructor & Destructor Documentation

◆ OrderBookDBImpl()

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

Definition at line 11 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 27 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 176 of file OrderBookDBImpl.cpp.

◆ getBooksByTakerPays()

std::vector< Book > xrpl::OrderBookDBImpl::getBooksByTakerPays ( Issue const &  issue,
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
issueThe issue to search for
domainOptional domain restriction for the order book
Returns
Vector of books that want this issue

Implements xrpl::OrderBookDB.

Definition at line 203 of file OrderBookDBImpl.cpp.

◆ getBookSize()

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

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

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

Implements xrpl::OrderBookDB.

Definition at line 235 of file OrderBookDBImpl.cpp.

◆ isBookToXRP()

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

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

Parameters
issueThe issue 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 254 of file OrderBookDBImpl.cpp.

◆ update()

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

Definition at line 70 of file OrderBookDBImpl.cpp.

◆ processTxn()

void xrpl::OrderBookDBImpl::processTxn ( std::shared_ptr< ReadView const > const &  ledger,
AcceptedLedgerTx const &  alTx,
MultiApiJson const &  jvObj 
)
overridevirtual

Process a transaction for order book tracking.

Parameters
ledgerThe ledger the transaction was applied to
alTxThe transaction to process
jvObjThe JSON object of the transaction

Implements xrpl::OrderBookDB.

Definition at line 298 of file OrderBookDBImpl.cpp.

◆ getBookListeners()

BookListeners::pointer xrpl::OrderBookDBImpl::getBookListeners ( Book const &  )
overridevirtual

Get the book listeners for a book.

Parameters
bookThe book to get the listeners for
Returns
The book listeners for the book

Implements xrpl::OrderBookDB.

Definition at line 283 of file OrderBookDBImpl.cpp.

◆ makeBookListeners()

BookListeners::pointer xrpl::OrderBookDBImpl::makeBookListeners ( Book const &  )
overridevirtual

Create a new book listeners for a book.

Parameters
bookThe book to create the listeners for
Returns
The new book listeners for the book

Implements xrpl::OrderBookDB.

Definition at line 263 of file OrderBookDBImpl.cpp.

Member Data Documentation

◆ registry_

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

Definition at line 70 of file OrderBookDBImpl.h.

◆ pathSearchMax_

int const xrpl::OrderBookDBImpl::pathSearchMax_
private

Definition at line 71 of file OrderBookDBImpl.h.

◆ standalone_

bool const xrpl::OrderBookDBImpl::standalone_
private

Definition at line 72 of file OrderBookDBImpl.h.

◆ allBooks_

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

Definition at line 75 of file OrderBookDBImpl.h.

◆ domainBooks_

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

Definition at line 77 of file OrderBookDBImpl.h.

◆ xrpBooks_

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

Definition at line 80 of file OrderBookDBImpl.h.

◆ xrpDomainBooks_

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

Definition at line 83 of file OrderBookDBImpl.h.

◆ mLock

std::recursive_mutex xrpl::OrderBookDBImpl::mLock
private

Definition at line 85 of file OrderBookDBImpl.h.

◆ mListeners

BookToListenersMap xrpl::OrderBookDBImpl::mListeners
private

Definition at line 89 of file OrderBookDBImpl.h.

◆ seq_

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

Definition at line 91 of file OrderBookDBImpl.h.

◆ j_

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

Definition at line 93 of file OrderBookDBImpl.h.