mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
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:
1449
src/clio/rpc/RPCHelpers.cpp
Normal file
1449
src/clio/rpc/RPCHelpers.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@
|
||||
#include <cstdint>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace RPC {
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user