include searched_all in error response of tx (#407)

This commit is contained in:
CJ Cobb
2022-11-21 15:52:59 -06:00
committed by GitHub
parent 5c9dce0f8a
commit cf7a6ecc89
3 changed files with 33 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ makeError(Status const& status)
return str.empty() ? nullopt : make_optional(str);
};
return visit(
auto res = visit(
overloadSet{
[&status, &wrapOptional](RippledError err) {
if (err == ripple::rpcUNKNOWN)
@@ -130,6 +130,14 @@ makeError(Status const& status)
},
},
status.code);
if (status.extraInfo)
{
for (auto& [key, value] : status.extraInfo.value())
{
res[key] = value;
}
}
return res;
}
} // namespace RPC

View File

@@ -50,9 +50,12 @@ struct Status
CombinedError code = RippledError::rpcSUCCESS;
std::string error = "";
std::string message = "";
std::optional<boost::json::object> extraInfo;
Status() = default;
/* implicit */ Status(CombinedError code) : code(code){};
Status(CombinedError code, boost::json::object&& extraInfo)
: code(code), extraInfo(std::move(extraInfo)){};
// HACK. Some rippled handlers explicitly specify errors.
// This means that we have to be able to duplicate this

View File

@@ -31,6 +31,17 @@ doTx(Context const& context)
binary = request.at(JS(binary)).as_bool();
}
auto minLedger = getUInt(request, JS(min_ledger));
auto maxLedger = getUInt(request, JS(max_ledger));
bool rangeSupplied = minLedger && maxLedger;
if (rangeSupplied)
{
if (*minLedger > *maxLedger)
return Status{RippledError::rpcINVALID_LGR_RANGE};
if (*maxLedger - *minLedger > 1000)
return Status{RippledError::rpcEXCESSIVE_LGR_RANGE};
}
auto range = context.backend->fetchLedgerRange();
if (!range)
@@ -38,7 +49,17 @@ doTx(Context const& context)
auto dbResponse = context.backend->fetchTransaction(hash, context.yield);
if (!dbResponse)
{
if (rangeSupplied)
{
bool searchedAll = range->maxSequence >= *maxLedger &&
range->minSequence <= *minLedger;
boost::json::object extra;
extra["searched_all"] = searchedAll;
return Status{RippledError::rpcTXN_NOT_FOUND, std::move(extra)};
}
return Status{RippledError::rpcTXN_NOT_FOUND};
}
if (!binary)
{