mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Remove the type filter from "ledger" RPC command (#4934)
This issue was reported on the Javascript client library: XRPLF/xrpl.js#2611 The type filter (Note: as of the latest version of rippled, type parameter is deprecated) does not work as expected. This PR removes the type filter from the ledger command.
This commit is contained in:
committed by
GitHub
parent
90e6380383
commit
1a40f18bdd
@@ -169,6 +169,8 @@ enum warning_code_i {
|
||||
warnRPC_AMENDMENT_BLOCKED = 1002,
|
||||
warnRPC_EXPIRED_VALIDATOR_LIST = 1003,
|
||||
// unused = 1004
|
||||
warnRPC_FIELDS_DEPRECATED = 2004, // rippled needs to maintain
|
||||
// compatibility with Clio on this code.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -711,6 +711,7 @@ class LedgerRPC_test : public beast::unit_test::suite
|
||||
env.close();
|
||||
|
||||
std::string index;
|
||||
int hashesLedgerEntryIndex = -1;
|
||||
{
|
||||
Json::Value jvParams;
|
||||
jvParams[jss::ledger_index] = 3u;
|
||||
@@ -721,11 +722,27 @@ class LedgerRPC_test : public beast::unit_test::suite
|
||||
env.rpc("json", "ledger", to_string(jvParams))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::ledger].isMember(jss::accountState));
|
||||
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].isArray());
|
||||
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 1u);
|
||||
|
||||
for (auto i = 0; i < jrr[jss::ledger][jss::accountState].size();
|
||||
i++)
|
||||
if (jrr[jss::ledger][jss::accountState][i]["LedgerEntryType"] ==
|
||||
jss::LedgerHashes)
|
||||
{
|
||||
index = jrr[jss::ledger][jss::accountState][i]["index"]
|
||||
.asString();
|
||||
hashesLedgerEntryIndex = i;
|
||||
}
|
||||
|
||||
for (auto const& object : jrr[jss::ledger][jss::accountState])
|
||||
if (object["LedgerEntryType"] == jss::LedgerHashes)
|
||||
index = object["index"].asString();
|
||||
|
||||
// jss::type is a deprecated field
|
||||
BEAST_EXPECT(
|
||||
jrr[jss::ledger][jss::accountState][0u]["LedgerEntryType"] ==
|
||||
jss::LedgerHashes);
|
||||
index = jrr[jss::ledger][jss::accountState][0u]["index"].asString();
|
||||
jrr.isMember(jss::warnings) && jrr[jss::warnings].isArray() &&
|
||||
jrr[jss::warnings].size() == 1 &&
|
||||
jrr[jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_FIELDS_DEPRECATED);
|
||||
}
|
||||
{
|
||||
Json::Value jvParams;
|
||||
@@ -737,8 +754,17 @@ class LedgerRPC_test : public beast::unit_test::suite
|
||||
env.rpc("json", "ledger", to_string(jvParams))[jss::result];
|
||||
BEAST_EXPECT(jrr[jss::ledger].isMember(jss::accountState));
|
||||
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].isArray());
|
||||
BEAST_EXPECT(jrr[jss::ledger][jss::accountState].size() == 1u);
|
||||
BEAST_EXPECT(jrr[jss::ledger][jss::accountState][0u] == index);
|
||||
BEAST_EXPECT(
|
||||
hashesLedgerEntryIndex > 0 &&
|
||||
jrr[jss::ledger][jss::accountState][hashesLedgerEntryIndex] ==
|
||||
index);
|
||||
|
||||
// jss::type is a deprecated field
|
||||
BEAST_EXPECT(
|
||||
jrr.isMember(jss::warnings) && jrr[jss::warnings].isArray() &&
|
||||
jrr[jss::warnings].size() == 1 &&
|
||||
jrr[jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_FIELDS_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,8 @@ struct LedgerFill
|
||||
ReadView const& l,
|
||||
RPC::Context* ctx,
|
||||
int o = 0,
|
||||
std::vector<TxQ::TxDetails> q = {},
|
||||
LedgerEntryType t = ltANY)
|
||||
: ledger(l), options(o), txQueue(std::move(q)), type(t), context(ctx)
|
||||
std::vector<TxQ::TxDetails> q = {})
|
||||
: ledger(l), options(o), txQueue(std::move(q)), context(ctx)
|
||||
{
|
||||
if (context)
|
||||
closeTime = context->ledgerMaster.getCloseTimeBySeq(ledger.seq());
|
||||
@@ -58,7 +57,6 @@ struct LedgerFill
|
||||
ReadView const& ledger;
|
||||
int options;
|
||||
std::vector<TxQ::TxDetails> txQueue;
|
||||
LedgerEntryType type;
|
||||
RPC::Context* context;
|
||||
std::optional<NetClock::time_point> closeTime;
|
||||
};
|
||||
|
||||
@@ -268,19 +268,16 @@ fillJsonState(Object& json, LedgerFill const& fill)
|
||||
|
||||
for (auto const& sle : ledger.sles)
|
||||
{
|
||||
if (fill.type == ltANY || sle->getType() == fill.type)
|
||||
if (binary)
|
||||
{
|
||||
if (binary)
|
||||
{
|
||||
auto&& obj = appendObject(array);
|
||||
obj[jss::hash] = to_string(sle->key());
|
||||
obj[jss::tx_blob] = serializeHex(*sle);
|
||||
}
|
||||
else if (expanded)
|
||||
array.append(sle->getJson(JsonOptions::none));
|
||||
else
|
||||
array.append(to_string(sle->key()));
|
||||
auto&& obj = appendObject(array);
|
||||
obj[jss::hash] = to_string(sle->key());
|
||||
obj[jss::tx_blob] = serializeHex(*sle);
|
||||
}
|
||||
else if (expanded)
|
||||
array.append(sle->getJson(JsonOptions::none));
|
||||
else
|
||||
array.append(to_string(sle->key()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,10 +54,6 @@ LedgerHandler::check()
|
||||
bool const binary = params[jss::binary].asBool();
|
||||
bool const owner_funds = params[jss::owner_funds].asBool();
|
||||
bool const queue = params[jss::queue].asBool();
|
||||
auto type = chooseLedgerEntryType(params);
|
||||
if (type.first)
|
||||
return type.first;
|
||||
type_ = type.second;
|
||||
|
||||
options_ = (full ? LedgerFill::full : 0) |
|
||||
(expand ? LedgerFill::expand : 0) |
|
||||
|
||||
@@ -76,7 +76,6 @@ private:
|
||||
std::vector<TxQ::TxDetails> queueTxs_;
|
||||
Json::Value result_;
|
||||
int options_ = 0;
|
||||
LedgerEntryType type_;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -91,7 +90,7 @@ LedgerHandler::writeResult(Object& value)
|
||||
if (ledger_)
|
||||
{
|
||||
Json::copyFrom(value, result_);
|
||||
addJson(value, {*ledger_, &context_, options_, queueTxs_, type_});
|
||||
addJson(value, {*ledger_, &context_, options_, queueTxs_});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -105,6 +104,21 @@ LedgerHandler::writeResult(Object& value)
|
||||
addJson(open, {*master.getCurrentLedger(), &context_, 0});
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value warnings{Json::arrayValue};
|
||||
if (context_.params.isMember(jss::type))
|
||||
{
|
||||
Json::Value& w = warnings.append(Json::objectValue);
|
||||
w[jss::id] = warnRPC_FIELDS_DEPRECATED;
|
||||
w[jss::message] =
|
||||
"Some fields from your request are deprecated. Please check the "
|
||||
"documentation at "
|
||||
"https://xrpl.org/docs/references/http-websocket-apis/ "
|
||||
"and update your request. Field `type` is deprecated.";
|
||||
}
|
||||
|
||||
if (warnings.size())
|
||||
value[jss::warnings] = std::move(warnings);
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
|
||||
Reference in New Issue
Block a user