Skip to content

Commit

Permalink
Unify MultivarJson::select and visit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Nov 28, 2023
1 parent e70a1e8 commit aaa843f
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 184 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/ledger/BookListeners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ BookListeners::publish(
// Only publish jvObj if this is the first occurence
if (havePublished.emplace(p->getSeq()).second)
{
jvObj.select(p->getApiVersion(), [&](Json::Value const& jv) {
jvObj.visit(p->getApiVersion(), [&](Json::Value const& jv) {
p->send(jv, true);
});
}
Expand Down
61 changes: 31 additions & 30 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,23 +2224,24 @@ NetworkOPsImp::pubValidation(std::shared_ptr<STValidation> const& val)

// TODO Replace multiObj with jvObj when API versions 1 is retired
MultiApiJson multiObj{jvObj};
multiObj.select(1, [](Json::Value& jvTx) {
// Type conversion for older API versions to string
if (jvTx.isMember(jss::ledger_index))
{
jvTx[jss::ledger_index] =
std::to_string(jvTx[jss::ledger_index].asUInt());
}
});
multiObj.visit(
std::integral_constant<unsigned int, 1>{}, [](Json::Value& jvTx) {
// Type conversion for older API versions to string
if (jvTx.isMember(jss::ledger_index))
{
jvTx[jss::ledger_index] =
std::to_string(jvTx[jss::ledger_index].asUInt());
}
});

for (auto i = mStreamMaps[sValidations].begin();
i != mStreamMaps[sValidations].end();)
{
if (auto p = i->second.lock())
{
multiObj.select(p->getApiVersion(), [&](Json::Value const& jv) {
p->send(jv, true);
});
multiObj.visit(
p->getApiVersion(), //
[&](Json::Value const& jv) { p->send(jv, true); });
++i;
}
else
Expand Down Expand Up @@ -2777,9 +2778,9 @@ NetworkOPsImp::pubProposedTransaction(

if (p)
{
jvObj.select(p->getApiVersion(), [&](Json::Value const& jv) {
p->send(jv, true);
});
jvObj.visit(
p->getApiVersion(), //
[&](Json::Value const& jv) { p->send(jv, true); });
++it;
}
else
Expand Down Expand Up @@ -3219,9 +3220,9 @@ NetworkOPsImp::pubValidatedTransaction(

if (p)
{
jvObj.select(p->getApiVersion(), [&](Json::Value const& jv) {
p->send(jv, true);
});
jvObj.visit(
p->getApiVersion(), //
[&](Json::Value const& jv) { p->send(jv, true); });
++it;
}
else
Expand All @@ -3236,9 +3237,9 @@ NetworkOPsImp::pubValidatedTransaction(

if (p)
{
jvObj.select(p->getApiVersion(), [&](Json::Value const& jv) {
p->send(jv, true);
});
jvObj.visit(
p->getApiVersion(), //
[&](Json::Value const& jv) { p->send(jv, true); });
++it;
}
else
Expand Down Expand Up @@ -3358,8 +3359,8 @@ NetworkOPsImp::pubAccountTransaction(

for (InfoSub::ref isrListener : notify)
{
jvObj.select(
isrListener->getApiVersion(),
jvObj.visit(
isrListener->getApiVersion(), //
[&](Json::Value const& jv) { isrListener->send(jv, true); });
}

Expand All @@ -3377,8 +3378,8 @@ NetworkOPsImp::pubAccountTransaction(

jvObj.set(jss::account_history_tx_index, index->forwardTxIndex_++);

jvObj.select(
info.sink_->getApiVersion(),
jvObj.visit(
info.sink_->getApiVersion(), //
[&](Json::Value const& jv) { info.sink_->send(jv, true); });
}
}
Expand Down Expand Up @@ -3437,8 +3438,8 @@ NetworkOPsImp::pubProposedAccountTransaction(
MultiApiJson jvObj = transJson(tx, result, false, ledger, std::nullopt);

for (InfoSub::ref isrListener : notify)
jvObj.select(
isrListener->getApiVersion(),
jvObj.visit(
isrListener->getApiVersion(), //
[&](Json::Value const& jv) { isrListener->send(jv, true); });

assert(
Expand All @@ -3450,8 +3451,8 @@ NetworkOPsImp::pubProposedAccountTransaction(
if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
jvObj.set(jss::account_history_tx_first, true);
jvObj.set(jss::account_history_tx_index, index->forwardTxIndex_++);
jvObj.select(
info.sink_->getApiVersion(),
jvObj.visit(
info.sink_->getApiVersion(), //
[&](Json::Value const& jv) { info.sink_->send(jv, true); });
}
}
Expand Down Expand Up @@ -3658,8 +3659,8 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo)
bool unsubscribe) -> bool {
if (auto sptr = subInfo.sinkWptr_.lock())
{
jvObj.select(
sptr->getApiVersion(),
jvObj.visit(
sptr->getApiVersion(), //
[&](Json::Value const& jv) { sptr->send(jv, true); });

if (unsubscribe)
Expand Down
Loading

0 comments on commit aaa843f

Please sign in to comment.