Skip to content

Commit

Permalink
respond to more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Oct 11, 2023
1 parent ed92a27 commit ebe4258
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
7 changes: 6 additions & 1 deletion src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,15 @@ class SField
static int
compare(const SField& f1, const SField& f2);

static std::map<int, SField const*> knownCodeToField;
static std::map<int, SField const*> const&
getKnownCodeToField()
{
return knownCodeToField;
}

private:
static int num;
static std::map<int, SField const*> knownCodeToField;
};

/** A field with a type known at compile time. */
Expand Down
16 changes: 12 additions & 4 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ JSS(fee_mult_max); // in: TransactionSign
JSS(fee_ref); // out: NetworkOPs, DEPRECATED
JSS(fetch_pack); // out: NetworkOPs
JSS(FIELDS); // out: RPC server_definitions
// matches server_definitions.json format
JSS(first); // out: rpc/Version
JSS(firstSequence); // out: NodeToShardStatus
JSS(firstShardIndex); // out: NodeToShardStatus
Expand Down Expand Up @@ -363,8 +364,11 @@ JSS(io_latency_ms); // out: NetworkOPs
JSS(ip); // in: Connect, out: OverlayImpl
JSS(is_burned); // out: nft_info (clio)
JSS(isSerialized); // out: RPC server_definitions
// matches server_definitions.json format
JSS(isSigningField); // out: RPC server_definitions
// matches server_definitions.json format
JSS(isVLEncoded); // out: RPC server_definitions
// matches server_definitions.json format
JSS(issuer); // in: RipplePathFind, Subscribe,
// Unsubscribe, BookOffers
// out: STPathSet, STAmount
Expand Down Expand Up @@ -405,6 +409,7 @@ JSS(ledger_max); // in, out: AccountTx*
JSS(ledger_min); // in, out: AccountTx*
JSS(ledger_time); // out: NetworkOPs
JSS(LEDGER_ENTRY_TYPES); // out: RPC server_definitions
// matches server_definitions.json format
JSS(levels); // LogLevels
JSS(limit); // in/out: AccountTx*, AccountOffers,
// AccountLines, AccountObjects
Expand Down Expand Up @@ -651,6 +656,12 @@ JSS(transaction); // in: Tx
JSS(transaction_hash); // out: RCLCxPeerPos, LedgerToJson
JSS(transactions); // out: LedgerToJson,
// in: AccountTx*, Unsubscribe
JSS(TRANSACTION_RESULTS); // out: RPC server_definitions
// matches server_definitions.json format
JSS(TRANSACTION_TYPES); // out: RPC server_definitions
// matches server_definitions.json format
JSS(TYPES); // out: RPC server_definitions
// matches server_definitions.json format
JSS(transfer_rate); // out: nft_info (clio)
JSS(transitions); // out: NetworkOPs
JSS(treenode_cache_size); // out: GetCounts
Expand Down Expand Up @@ -682,11 +693,8 @@ JSS(txr_not_enabled_cnt); // out: peers with tx reduce-relay disabled count
JSS(txr_missing_tx_freq); // out: missing tx frequency average
JSS(txs); // out: TxHistory
JSS(type); // in: AccountObjects
// out: NetworkOPs RPC server_definitions
// out: NetworkOPs, RPC server_definitions
// OverlayImpl, Logic
JSS(TRANSACTION_RESULTS); // out: RPC server_definitions
JSS(TRANSACTION_TYPES); // out: RPC server_definitions
JSS(TYPES); // out: RPC server_definitions
JSS(type_hex); // out: STPathSet
JSS(unl); // out: UnlList
JSS(unlimited); // out: Connection.h
Expand Down
54 changes: 25 additions & 29 deletions src/ripple/rpc/handlers/ServerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
#include <ripple/protocol/jss.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/Role.h>

#include <boost/algorithm/string.hpp>
#include <sstream>

#include <unordered_map>

namespace ripple {

Expand Down Expand Up @@ -86,37 +88,31 @@ ServerDefinitions::translate(std::string const& inp)
return replace("UINT", "UInt");
}

if (inp == "OBJECT")
return "STObject";
if (inp == "ARRAY")
return "STArray";
if (inp == "AMM")
return "AMM";
if (inp == "ACCOUNT")
return "AccountID";
if (inp == "LEDGERENTRY")
return "LedgerEntry";
if (inp == "NOTPRESENT")
return "NotPresent";
if (inp == "PATHSET")
return "PathSet";
if (inp == "VL")
return "Blob";
if (inp == "DIR_NODE")
return "DirectoryNode";
if (inp == "PAYCHAN")
return "PayChannel";
if (inp == "XCHAIN_BRIDGE")
return "XChainBridge";
std::unordered_map<std::string, std::string> replacements{
{"OBJECT", "STObject"},
{"ARRAY", "STArray"},
{"ACCOUNT", "AccountID"},
{"LEDGERENTRY", "LedgerEntry"},
{"NOTPRESENT", "NotPresent"},
{"PATHSET", "PathSet"},
{"VL", "Blob"},
{"XCHAIN_BRIDGE", "XChainBridge"},
};

if (auto const& it = replacements.find(inp); it != replacements.end())
{
return it->second;
}

std::string out;
size_t pos = 0;
std::string inpToProcess = inp;
for (;;)
{
pos = inp.find("_");
pos = inpToProcess.find("_");
if (pos == std::string::npos)
pos = inp.size();
std::string token = inp.substr(0, pos);
pos = inpToProcess.size();
std::string token = inpToProcess.substr(0, pos);
if (token.size() > 1)
{
boost::algorithm::to_lower(token);
Expand All @@ -125,9 +121,9 @@ ServerDefinitions::translate(std::string const& inp)
}
else
out += token;
if (pos == inp.size())
if (pos == inpToProcess.size())
break;
inp = inp.substr(pos + 1);
inpToProcess = inpToProcess.substr(pos + 1);
}
return out;
};
Expand Down Expand Up @@ -237,7 +233,7 @@ ServerDefinitions::generate()
ret[jss::FIELDS][i++] = a;
}

for (auto const& [code, f] : ripple::SField::knownCodeToField)
for (auto const& [code, f] : ripple::SField::getKnownCodeToField())
{
if (f->fieldName == "")
continue;
Expand Down

0 comments on commit ebe4258

Please sign in to comment.