Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ledger_data returns an empty list (instead of null) when all entries are filtered out #4398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ripple/rpc/handlers/LedgerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ doLedgerData(RPC::JsonContext& context)
return jvResult;
}
Json::Value& nodes = jvResult[jss::state];
if (nodes.type() == Json::nullValue)
{
nodes = Json::Value(Json::arrayValue);
}

auto e = lpLedger->sles.end();
for (auto i = lpLedger->sles.upper_bound(key); i != e; ++i)
Expand Down
37 changes: 28 additions & 9 deletions src/test/rpc/LedgerData_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,34 @@ class LedgerData_test : public beast::unit_test::suite
auto const USD = gw["USD"];
env.fund(XRP(100000), gw);

auto makeRequest = [&env](Json::StaticString const& type) {
drlongle marked this conversation as resolved.
Show resolved Hide resolved
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::type] = type;
return env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams))[jss::result];
};

// Assert that state is an empty array.
for (auto const& type :
{jss::amendments,
jss::check,
jss::directory,
jss::fee,
jss::offer,
jss::signer_list,
jss::state,
jss::ticket,
jss::escrow,
jss::payment_channel,
jss::deposit_preauth})
{
auto const jrr = makeRequest(type);
BEAST_EXPECT(checkArraySize(jrr[jss::state], 0));
}

int const num_accounts = 10;

for (auto i = 0; i < num_accounts; i++)
Expand Down Expand Up @@ -372,15 +400,6 @@ class LedgerData_test : public beast::unit_test::suite
env.close();

// Now fetch each type
auto makeRequest = [&env](Json::StaticString t) {
Json::Value jvParams;
jvParams[jss::ledger_index] = "current";
jvParams[jss::type] = t;
return env.rpc(
"json",
"ledger_data",
boost::lexical_cast<std::string>(jvParams))[jss::result];
};

{ // jvParams[jss::type] = "account";
auto const jrr = makeRequest(jss::account);
Expand Down