Skip to content

Commit

Permalink
Factor out MultivarJson for transaction streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 6, 2023
1 parent 7a04799 commit cc0cc5e
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 123 deletions.
9 changes: 3 additions & 6 deletions src/ripple/app/ledger/BookListeners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ BookListeners::removeSubscriber(std::uint64_t seq)

void
BookListeners::publish(
Json::Value const& jvObj,
Json::Value const& jvObjApiVer2,
MultiApiJson const& jvObj,
hash_set<std::uint64_t>& havePublished)
{
std::lock_guard sl(mLock);
Expand All @@ -55,10 +54,8 @@ BookListeners::publish(
// Only publish jvObj if this is the first occurence
if (havePublished.emplace(p->getSeq()).second)
{
if (p->getApiVersion() == 1)
p->send(jvObj, true);
else
p->send(jvObjApiVer2, true);
p->send(
jvObj.select(apiVersionSelector(p->getApiVersion())), true);
}
++it;
}
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/app/ledger/BookListeners.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#ifndef RIPPLE_APP_LEDGER_BOOKLISTENERS_H_INCLUDED
#define RIPPLE_APP_LEDGER_BOOKLISTENERS_H_INCLUDED

#include <ripple/basics/MultivarJson.h>
#include <ripple/net/InfoSub.h>

#include <memory>
#include <mutex>

Expand Down Expand Up @@ -58,7 +60,7 @@ class BookListeners
*/
void
publish(Json::Value const& jvObj, Json::Value const& jvObjApiVer2, hash_set<std::uint64_t>& havePublished);
publish(MultiApiJson const& jvObj, hash_set<std::uint64_t>& havePublished);

private:
std::recursive_mutex mLock;
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/app/ledger/OrderBookDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ void
OrderBookDB::processTxn(
std::shared_ptr<ReadView const> const& ledger,
const AcceptedLedgerTx& alTx,
Json::Value const& jvObj,
Json::Value const& jvObjApiVer2)
MultiApiJson const& jvObj)
{
std::lock_guard sl(mLock);

Expand All @@ -278,7 +277,7 @@ OrderBookDB::processTxn(
{data->getFieldAmount(sfTakerGets).issue(),
data->getFieldAmount(sfTakerPays).issue()});
if (listeners)
listeners->publish(jvObj, jvObjApiVer2, havePublished);
listeners->publish(jvObj, havePublished);
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/ripple/app/ledger/OrderBookDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <ripple/app/ledger/AcceptedLedgerTx.h>
#include <ripple/app/ledger/BookListeners.h>
#include <ripple/app/main/Application.h>
#include <ripple/basics/MultivarJson.h>

#include <mutex>

namespace ripple {
Expand Down Expand Up @@ -63,8 +65,7 @@ class OrderBookDB
processTxn(
std::shared_ptr<ReadView const> const& ledger,
const AcceptedLedgerTx& alTx,
Json::Value const& jvObj,
Json::Value const& jvObjApiVer2);
MultiApiJson const& jvObj);

private:
Application& app_;
Expand Down
Loading

0 comments on commit cc0cc5e

Please sign in to comment.