Skip to content

Commit

Permalink
Output for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 26, 2023
1 parent ee53c5d commit aa6de60
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
25 changes: 21 additions & 4 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <ripple/protocol/BuildInfo.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/STParsedJSON.h>
#include <ripple/protocol/jss.h>
#include <ripple/resource/Fees.h>
#include <ripple/resource/ResourceManager.h>
#include <ripple/rpc/BookChanges.h>
Expand All @@ -74,6 +75,7 @@

#include <algorithm>
#include <mutex>
#include <optional>
#include <string>
#include <tuple>
#include <unordered_map>
Expand Down Expand Up @@ -3101,7 +3103,12 @@ NetworkOPsImp::transJson(
transResultInfo(result, sToken, sHuman);

jvObj[jss::type] = "transaction";
jvObj[jss::transaction] = transaction->getJson(JsonOptions::none);
// NOTE jvObj which is not a finished object for either API version. After
// it's populated, we need to finish it for a specific API version. This is
// done in a loop, near the end of this function.
std::string hash = {};
jvObj[jss::transaction] =
transaction->getJson(JsonOptions::none, false, {std::ref(hash)});

if (meta)
{
Expand Down Expand Up @@ -3165,11 +3172,21 @@ NetworkOPsImp::transJson(
assert(index < MultiApiJson::size);
if (index != lastIndex)
{
Json::Value& jvTx = multiObj.val[index];
RPC::insertDeliverMax(
multiObj.val[index][jss::transaction],
transaction->getTxnType(),
apiVersion);
jvTx[jss::transaction], transaction->getTxnType(), apiVersion);
lastIndex = index;

if (apiVersion > 1)
{
jvTx[jss::tx_json] = jvTx.removeMember(jss::transaction);
jvTx[jss::hash] = hash;
// TODO set `jvObj[jss::close_time_iso]` if validated
}
else
{
jvTx[jss::transaction][jss::hash] = hash;
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/ripple/protocol/STTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,16 @@ class STTx final : public STObject, public CountedObject<STTx>

Json::Value
getJson(JsonOptions options) const override;

/// If `hash` is set, will store hash inside the provided string. Otherwise
/// hash will be stored as nested jss::hash element inside the returned JSON
/// Additionally, if `hash` is set and `binary` is true, will not create
/// nested jss::tx for binary hex; instead will return it as JSON string
Json::Value
getJson(JsonOptions options, bool binary) const;
getJson(
JsonOptions options,
bool binary,
std::optional<std::reference_wrapper<std::string>> hash = {}) const;

void
sign(PublicKey const& publicKey, SecretKey const& secretKey);
Expand Down
26 changes: 21 additions & 5 deletions src/ripple/protocol/impl/STTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,33 @@ Json::Value STTx::getJson(JsonOptions) const
}

Json::Value
STTx::getJson(JsonOptions options, bool binary) const
STTx::getJson(
JsonOptions options,
bool binary,
std::optional<std::reference_wrapper<std::string>> hash) const
{
if (!hash) // Old behaviour - default because `hash = {}` in declaration
{
if (binary)
{
Json::Value ret;
Serializer s = STObject::getSerializer();
ret[jss::tx] = strHex(s.peekData());
ret[jss::hash] = to_string(getTransactionID());
return ret;
}
return getJson(options);
}

// Since `hash` is set, do not populate `hash` inside JSON output
hash->get() = to_string(getTransactionID());
if (binary)
{
Json::Value ret;
Serializer s = STObject::getSerializer();
ret[jss::tx] = strHex(s.peekData());
ret[jss::hash] = to_string(getTransactionID());
Json::Value ret = strHex(s.peekData());
return ret;
}
return getJson(options);
return STObject::getJson(JsonOptions::none); // Yes, want `none`
}

std::string const&
Expand Down

0 comments on commit aa6de60

Please sign in to comment.