Implement subscription for book_changes (#315)

Fixes #315
This commit is contained in:
Alex Kremer
2022-09-27 01:20:53 +02:00
committed by GitHub
parent 983aa29271
commit d4a9560c3f
10 changed files with 247 additions and 173 deletions

View File

@@ -70,7 +70,7 @@ Subscription::unsubscribe(std::shared_ptr<WsBase> const& session)
}
void
Subscription::publish(std::shared_ptr<Message>& message)
Subscription::publish(std::shared_ptr<Message> const& message)
{
boost::asio::post(strand_, [this, message]() {
sendToSubscribers(message, subscribers_, subCount_);
@@ -235,6 +235,22 @@ SubscriptionManager::unsubBook(
bookSubscribers_.unsubscribe(session, book);
}
void
SubscriptionManager::subBookChanges(std::shared_ptr<WsBase> session)
{
bookChangesSubscribers_.subscribe(session);
std::unique_lock lk(cleanupMtx_);
cleanupFuncs_[session].emplace_back(
[this](session_ptr session) { unsubBookChanges(session); });
}
void
SubscriptionManager::unsubBookChanges(std::shared_ptr<WsBase> session)
{
bookChangesSubscribers_.unsubscribe(session);
}
void
SubscriptionManager::pubLedger(
ripple::LedgerInfo const& lgrInfo,
@@ -345,6 +361,20 @@ SubscriptionManager::pubTransaction(
}
}
void
SubscriptionManager::pubBookChanges(
ripple::LedgerInfo const& lgrInfo,
std::vector<Backend::TransactionAndMetadata> const& transactions)
{
if (bookChangesSubscribers_.empty())
return;
auto const json = RPC::computeBookChanges(lgrInfo, transactions);
auto const bookChangesMsg =
std::make_shared<Message>(boost::json::serialize(json));
bookChangesSubscribers_.publish(bookChangesMsg);
}
void
SubscriptionManager::forwardProposedTransaction(
boost::json::object const& response)