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->info().hash);
63 jvResult[jss::ledger_index] = lpLedger->info().seq;
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());
109 entry[jss::index] =
to_string(sle->key());
121 org::xrpl::rpc::v1::GetLedgerDataRequest& request = context.
params;
122 org::xrpl::rpc::v1::GetLedgerDataResponse response;
123 grpc::Status status = grpc::Status::OK;
128 grpc::Status errorStatus;
131 errorStatus = grpc::Status(
132 grpc::StatusCode::INVALID_ARGUMENT, status.message());
137 grpc::Status(grpc::StatusCode::NOT_FOUND, status.message());
139 return {response, errorStatus};
147 else if (request.marker().size() != 0)
149 grpc::Status errorStatus{
150 grpc::StatusCode::INVALID_ARGUMENT,
"marker malformed"};
151 return {response, errorStatus};
154 auto e = ledger->sles.end();
155 if (request.end_marker().size() != 0)
162 {grpc::StatusCode::INVALID_ARGUMENT,
"end marker malformed"}};
167 {grpc::StatusCode::INVALID_ARGUMENT,
168 "end marker out of range"}};
170 e = ledger->sles.upper_bound(*key);
175 for (
auto i = ledger->sles.upper_bound(startKey); i != e; ++i)
183 response.set_marker(k.data(), k.size());
186 auto stateObject = response.mutable_ledger_objects()->add_objects();
190 stateObject->set_key(sle->key().data(), sle->key().size());
192 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
static std::optional< base_uint > fromVoidChecked(T const &from)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
@ 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.
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
Json::Value expected_field_error(std::string const &name, std::string const &type)
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Json::Value doLedgerData(RPC::JsonContext &)
std::string to_string(base_uint< Bits, Tag > const &a)
@ ltANY
A special type, matching any ledger entry type.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
std::pair< org::xrpl::rpc::v1::GetLedgerDataResponse, grpc::Status > doLedgerDataGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetLedgerDataRequest > &context)