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/basics/base_uint.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/ledger/ReadView.h>
12#include <xrpl/protocol/ErrorCodes.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/jss.h>
17#include <xrpl/protocol/serialize.h>
19#include <grpcpp/support/status.h>
20#include <org/xrpl/rpc/v1/get_ledger_data.pb.h>
42 auto const& params = context.
params;
48 bool const isMarker = params.isMember(jss::marker);
57 bool isBinary =
false;
58 if (params.isMember(jss::binary))
60 if (!params[jss::binary].isBool())
62 isBinary = params[jss::binary].asBool();
66 if (params.isMember(jss::limit))
72 limit = jLimit.
asInt();
76 if ((limit < 0) || ((limit > maxLimit) && (!
isUnlimited(context.
role))))
79 jvResult[jss::ledger_hash] =
to_string(lpLedger->header().hash);
80 jvResult[jss::ledger_index] = lpLedger->header().seq;
93 rpcStatus.inject(jvResult);
102 auto e = lpLedger->sles.end();
103 for (
auto i = lpLedger->sles.upperBound(key); i != e; ++i)
114 if (type ==
ltANY || sle->getType() == type)
120 entry[jss::index] =
to_string(sle->key());
125 entry[jss::index] =
to_string(sle->key());
136 org::xrpl::rpc::v1::GetLedgerDataRequest
const& request = context.
params;
137 org::xrpl::rpc::v1::GetLedgerDataResponse response;
138 grpc::Status
const status = grpc::Status::OK;
143 grpc::Status errorStatus;
146 errorStatus = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, status.message());
150 errorStatus = grpc::Status(grpc::StatusCode::NOT_FOUND, status.message());
152 return {response, errorStatus};
160 else if (!request.marker().empty())
162 grpc::Status
const errorStatus{grpc::StatusCode::INVALID_ARGUMENT,
"marker malformed"};
163 return {response, errorStatus};
166 auto e = ledger->sles.end();
167 if (!request.end_marker().empty())
172 return {response, {grpc::StatusCode::INVALID_ARGUMENT,
"end marker malformed"}};
175 return {response, {grpc::StatusCode::INVALID_ARGUMENT,
"end marker out of range"}};
177 e = ledger->sles.upperBound(*key);
182 for (
auto i = ledger->sles.upperBound(startKey); i != e; ++i)
190 response.set_marker(k.data(), k.size());
193 auto stateObject = response.mutable_ledger_objects()->add_objects();
197 stateObject->set_key(sle->key().data(), sle->key().size());
199 return {response, status};
Value & append(Value const &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
static std::optional< BaseUInt > fromVoidChecked(T const &from)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Blob const & peekData() const
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
constexpr int pageLength(bool isBinary)
Maximum number of pages in a LedgerData response.
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.
Status ledgerFromRequest(T &ledger, GRPCContext< R > const &context)
Retrieves a ledger from a gRPC request context.
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(json::Value const ¶ms)
Chooses the ledger entry type based on RPC parameters.
json::Value expectedFieldError(std::string const &name, std::string const &type)
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::pair< org::xrpl::rpc::v1::GetLedgerDataResponse, grpc::Status > doLedgerDataGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetLedgerDataRequest > &context)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value doLedgerData(RPC::JsonContext &)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
@ ltANY
A special type, matching any ledger entry type.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.