1#include <xrpld/app/ledger/LedgerToJson.h>
2#include <xrpld/rpc/Context.h>
3#include <xrpld/rpc/GRPCHandlers.h>
4#include <xrpld/rpc/Role.h>
5#include <xrpld/rpc/detail/RPCHelpers.h>
6#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
7#include <xrpld/rpc/detail/Tuning.h>
9#include <xrpl/ledger/ReadView.h>
10#include <xrpl/protocol/ErrorCodes.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/jss.h>
31 auto const& params = context.
params;
37 bool const isMarker = params.isMember(jss::marker);
46 bool const isBinary = params[jss::binary].asBool();
49 if (params.isMember(jss::limit))
55 limit = jLimit.
asInt();
59 if ((limit < 0) || ((limit > maxLimit) && (!
isUnlimited(context.
role))))
62 jvResult[jss::ledger_hash] =
to_string(lpLedger->header().hash);
63 jvResult[jss::ledger_index] = lpLedger->header().seq;
68 jvResult[jss::ledger] =
76 rpcStatus.inject(jvResult);
85 auto e = lpLedger->sles.end();
86 for (
auto i = lpLedger->sles.upper_bound(key); i != e; ++i)
97 if (type ==
ltANY || sle->getType() == type)
103 entry[jss::index] =
to_string(sle->key());
108 entry[jss::index] =
to_string(sle->key());
119 org::xrpl::rpc::v1::GetLedgerDataRequest
const& request = context.
params;
120 org::xrpl::rpc::v1::GetLedgerDataResponse response;
121 grpc::Status
const status = grpc::Status::OK;
126 grpc::Status errorStatus;
129 errorStatus = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, status.message());
133 errorStatus = grpc::Status(grpc::StatusCode::NOT_FOUND, status.message());
135 return {response, errorStatus};
143 else if (!request.marker().empty())
145 grpc::Status
const errorStatus{grpc::StatusCode::INVALID_ARGUMENT,
"marker malformed"};
146 return {response, errorStatus};
149 auto e = ledger->sles.end();
150 if (!request.end_marker().empty())
155 return {response, {grpc::StatusCode::INVALID_ARGUMENT,
"end marker malformed"}};
158 return {response, {grpc::StatusCode::INVALID_ARGUMENT,
"end marker out of range"}};
160 e = ledger->sles.upper_bound(*key);
165 for (
auto i = ledger->sles.upper_bound(startKey); i != e; ++i)
173 response.set_marker(k.data(), k.size());
176 auto stateObject = response.mutable_ledger_objects()->add_objects();
180 stateObject->set_key(sle->key().data(), sle->key().size());
182 return {response, status};
Value & append(Value const &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
Blob const & peekData() const
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
static std::optional< base_uint > fromVoidChecked(T const &from)
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
int constexpr pageLength(bool isBinary)
Maximum number of pages in a LedgerData response.
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
Chooses the ledger entry type based on RPC parameters.
Json::Value expected_field_error(std::string const &name, std::string const &type)
Status ledgerFromRequest(T &ledger, GRPCContext< R > const &context)
Retrieves a ledger from a gRPC request context.
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, Json::Value &result)
Looks up a ledger from a request and fills a Json::Value with ledger data.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value doLedgerData(RPC::JsonContext &)
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
std::string to_string(base_uint< Bits, Tag > const &a)
std::pair< org::xrpl::rpc::v1::GetLedgerDataResponse, grpc::Status > doLedgerDataGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetLedgerDataRequest > &context)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
@ ltANY
A special type, matching any ledger entry type.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.