Improve handling of RPC ledger_index argument:

Some RPC commands return `ledger_index` as a quoted numeric
string. This change allows the returned value to be directly
copied and used for follow-on RPC commands.

This commit fixes #3533
This commit is contained in:
Gregory Tsipenyuk
2020-08-05 18:28:20 -04:00
committed by Nik Bougalis
parent 707868be33
commit 801b1580f5
4 changed files with 57 additions and 30 deletions

View File

@@ -228,31 +228,23 @@ ledgerFromRequest(T& ledger, JsonContext& context)
return {rpcINVALID_PARAMS, "ledgerHashMalformed"};
return getLedger(ledger, ledgerHash, context);
}
else if (indexValue.isNumeric())
{
return getLedger(ledger, indexValue.asInt(), context);
}
else
{
auto const index = indexValue.asString();
if (index == "validated")
{
return getLedger(ledger, LedgerShortcut::VALIDATED, context);
}
else
{
if (index.empty() || index == "current")
return getLedger(ledger, LedgerShortcut::CURRENT, context);
else if (index == "closed")
return getLedger(ledger, LedgerShortcut::CLOSED, context);
else
{
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
}
}
}
return Status::OK;
auto const index = indexValue.asString();
if (index.empty() || index == "current")
return getLedger(ledger, LedgerShortcut::CURRENT, context);
if (index == "validated")
return getLedger(ledger, LedgerShortcut::VALIDATED, context);
if (index == "closed")
return getLedger(ledger, LedgerShortcut::CLOSED, context);
std::uint32_t iVal;
if (beast::lexicalCastChecked(iVal, index))
return getLedger(ledger, iVal, context);
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
}
} // namespace