handle string ledger_index values in doAccountTx (#162)

* handle string ledger_index values in doAccountTx

* return ledgerInfo when ledger_hash is specified
This commit is contained in:
Nathan Nichols
2022-06-02 15:53:12 -05:00
committed by GitHub
parent f90dac2f85
commit 31cc06d4f4
4 changed files with 1464 additions and 22 deletions

1449
src/clio/rpc/RPCHelpers.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
#include <cstdint>
#include <shared_mutex>
#include <string>
#include <unordered_map>
namespace RPC {

View File

@@ -558,6 +558,11 @@ ledgerInfoFromRequest(Context const& ctx)
return Status{Error::rpcINVALID_PARAMS, "ledgerHashMalformed"};
auto lgrInfo = ctx.backend->fetchLedgerByHash(ledgerHash, ctx.yield);
if (!lgrInfo)
return Status{Error::rpcLGR_NOT_FOUND, "ledgerNotFound"};
return *lgrInfo;
}
auto indexValue = ctx.params.contains("ledger_index")

View File

@@ -99,31 +99,18 @@ doAccountTx(Context const& context)
cursor = {maxIndex, INT32_MAX};
}
if (request.contains(JS(ledger_index)))
if (request.contains(JS(ledger_index)) || request.contains(JS(ledger_hash)))
{
if (!request.at(JS(ledger_index)).is_int64())
return Status{Error::rpcINVALID_PARAMS, "ledgerIndexNotNumber"};
if (request.contains(JS(ledger_index_max)) ||
request.contains(JS(ledger_index_min)))
return Status{
Error::rpcINVALID_PARAMS, "containsLedgerSpecifierAndRange"};
auto ledgerIndex =
boost::json::value_to<std::uint32_t>(request.at(JS(ledger_index)));
maxIndex = minIndex = ledgerIndex;
}
auto v = ledgerInfoFromRequest(context);
if (auto status = std::get_if<Status>(&v))
return *status;
if (request.contains(JS(ledger_hash)))
{
if (!request.at(JS(ledger_hash)).is_string())
return RPC::Status{
RPC::Error::rpcINVALID_PARAMS, "ledgerHashNotString"};
ripple::uint256 ledgerHash;
if (!ledgerHash.parseHex(
request.at(JS(ledger_hash)).as_string().c_str()))
return RPC::Status{
RPC::Error::rpcINVALID_PARAMS, "ledgerHashMalformed"};
auto lgrInfo =
context.backend->fetchLedgerByHash(ledgerHash, context.yield);
maxIndex = minIndex = lgrInfo->seq;
maxIndex = minIndex = std::get<ripple::LedgerInfo>(v).seq;
}
if (!cursor)