1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/GRPCHandlers.h>
3#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
4#include <xrpld/rpc/handlers/ledger/LedgerEntryHelpers.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/basics/strHex.h>
8#include <xrpl/json/json_errors.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/ledger/helpers/CredentialHelpers.h>
12#include <xrpl/protocol/AccountID.h>
13#include <xrpl/protocol/ErrorCodes.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/Keylet.h>
16#include <xrpl/protocol/LedgerFormats.h>
17#include <xrpl/protocol/Protocol.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/STArray.h>
20#include <xrpl/protocol/STObject.h>
21#include <xrpl/protocol/SeqProxy.h>
22#include <xrpl/protocol/Serializer.h>
23#include <xrpl/protocol/UintTypes.h>
24#include <xrpl/protocol/jss.h>
26#include <grpcpp/support/status.h>
27#include <org/xrpl/rpc/v1/get_ledger_entry.pb.h>
42 unsigned const apiVersion)>;
44static std::expected<UInt256, json::Value>
49 unsigned const apiVersion);
60 unsigned const apiVersion) -> std::expected<UInt256, json::Value> {
65static std::expected<UInt256, json::Value>
69 std::string const& expectedType =
"hex string or object")
78static std::expected<UInt256, json::Value>
81 if (apiVersion > 2u && params.
isString())
84 if (index == jss::amendments.cStr())
86 if (index == jss::fee.cStr())
88 if (index == jss::nunl)
90 if (index == jss::hashes)
100static std::expected<UInt256, json::Value>
104 [[maybe_unused]]
unsigned const apiVersion)
116static std::expected<UInt256, json::Value>
120 [[maybe_unused]]
unsigned const apiVersion)
145static std::expected<UInt256, json::Value>
149 [[maybe_unused]]
unsigned const apiVersion)
161 auto const sequence =
170static std::expected<UInt256, json::Value>
174 [[maybe_unused]]
unsigned const apiVersion)
199static std::expected<UInt256, json::Value>
203 [[maybe_unused]]
unsigned const apiVersion)
215 auto const authorize =
223static std::expected<STArray, json::Value>
229 "malformedAuthorizedCredentials", jss::authorized_credentials,
"array");
237 "malformedAuthorizedCredentials",
238 "Invalid field '" +
std::string(jss::authorized_credentials) +
239 "', array too long."));
246 "malformedAuthorizedCredentials",
247 "Invalid field '" +
std::string(jss::authorized_credentials) +
"', array empty."));
250 STArray arr(sfAuthorizeCredentials, n);
251 for (
auto const& jo : jv)
256 "malformedAuthorizedCredentials", jss::authorized_credentials,
"array of objects");
260 jo, {jss::issuer, jss::credential_type},
"malformedAuthorizedCredentials");
267 jo, jss::issuer,
"malformedAuthorizedCredentials");
277 credential.setAccountID(sfIssuer, *issuer);
278 credential.setFieldVL(sfCredentialType, *credentialType);
279 arr.
pushBack(std::move(credential));
285static std::expected<UInt256, json::Value>
289 [[maybe_unused]]
unsigned const apiVersion)
296 if ((dp.
isMember(jss::authorized) == dp.
isMember(jss::authorized_credentials)))
300 "Must have exactly one of `authorized` and "
301 "`authorized_credentials`.");
317 "malformedAuthorized", jss::authorized,
"AccountID");
320 auto const& ac(dp[jss::authorized_credentials]);
322 if (!arr.has_value())
330 "malformedAuthorizedCredentials", jss::authorized_credentials,
"array");
336static std::expected<UInt256, json::Value>
340 [[maybe_unused]]
unsigned const apiVersion)
351static std::expected<UInt256, json::Value>
355 [[maybe_unused]]
unsigned const apiVersion)
362 if (params.
isMember(jss::sub_index) &&
364 params[jss::sub_index].
isBool()))
367 "malformedRequest", jss::sub_index,
"number");
373 "malformedRequest",
"Must have exactly one of `owner` and `dir_root` fields.");
394 "malformedAddress", jss::owner,
"AccountID");
403static std::expected<UInt256, json::Value>
407 [[maybe_unused]]
unsigned const apiVersion)
427static std::expected<UInt256, json::Value>
432 [[maybe_unused]]
unsigned const apiVersion)
446static std::expected<UInt256, json::Value>
450 unsigned const apiVersion)
455 auto const index = params.
asUInt();
466static std::expected<UInt256, json::Value>
470 [[maybe_unused]]
unsigned const apiVersion)
488static std::expected<UInt256, json::Value>
492 [[maybe_unused]]
unsigned const apiVersion)
511static std::expected<UInt256, json::Value>
515 [[maybe_unused]]
unsigned const apiVersion)
523 params, jss::mpt_issuance_id,
"malformedMPTIssuanceID");
535static std::expected<UInt256, json::Value>
539 [[maybe_unused]]
unsigned const apiVersion)
545 "malformedMPTokenIssuance", fieldName,
"Hash192");
551static std::expected<UInt256, json::Value>
555 [[maybe_unused]]
unsigned const apiVersion)
567 auto const sequence =
576static std::expected<UInt256, json::Value>
580 [[maybe_unused]]
unsigned const apiVersion)
587static std::expected<UInt256, json::Value>
591 [[maybe_unused]]
unsigned const apiVersion)
611static std::expected<UInt256, json::Value>
615 [[maybe_unused]]
unsigned const apiVersion)
628 params, jss::oracle_document_id,
"malformedDocumentID");
635static std::expected<UInt256, json::Value>
639 [[maybe_unused]]
unsigned const apiVersion)
651 auto const destination =
656 auto const sequence =
665static std::expected<UInt256, json::Value>
669 [[maybe_unused]]
unsigned const apiVersion)
679 "malformedRequest", fieldName,
"hex string or object");
695static std::expected<UInt256, json::Value>
699 [[maybe_unused]]
unsigned const apiVersion)
708 if (
auto const value =
715 if (!jvRippleState[jss::accounts].isArray() || jvRippleState[jss::accounts].size() != 2)
718 "malformedRequest", jss::accounts,
"length-2 array of Accounts");
726 "malformedAddress", jss::accounts,
"array of Accounts");
731 "malformedRequest",
"Cannot have a trustline to self.");
734 if (!jvRippleState[jss::currency].isString() || jvRippleState[jss::currency] ==
"" ||
735 !
toCurrency(uCurrency, jvRippleState[jss::currency].asString()))
738 "malformedCurrency", jss::currency,
"Currency");
744static std::expected<UInt256, json::Value>
748 [[maybe_unused]]
unsigned const apiVersion)
763static std::expected<UInt256, json::Value>
767 [[maybe_unused]]
unsigned const apiVersion)
772 auto const sponsorID =
777 auto const sponseeID =
785static std::expected<UInt256, json::Value>
789 [[maybe_unused]]
unsigned const apiVersion)
799 auto const targetID =
806 auto const ticketSequence =
814static std::expected<UInt256, json::Value>
818 [[maybe_unused]]
unsigned const apiVersion)
839static std::expected<UInt256, json::Value>
843 [[maybe_unused]]
unsigned const apiVersion)
877 static auto const kLedgerEntryParsers = std::to_array<LedgerEntry>({
878#pragma push_macro("LEDGER_ENTRY")
881#define LEDGER_ENTRY(tag, value, name, rpcName, fields) {jss::rpcName, parse##name, tag},
883#include <xrpl/protocol/detail/ledger_entries.macro>
886#pragma pop_macro("LEDGER_ENTRY")
887 {.fieldName = jss::index, .parseFunction =
parseIndex, .expectedType =
ltANY},
890 .fieldName = jss::account_root,
892 .expectedType = ltACCOUNT_ROOT,
895 .fieldName = jss::ripple_state,
897 .expectedType = ltRIPPLE_STATE,
901 auto const hasMoreThanOneMember = [&] {
904 for (
auto const& ledgerEntry : kLedgerEntryParsers)
916 if (hasMoreThanOneMember)
933 for (
auto const& ledgerEntry : kLedgerEntryParsers)
937 expectedType = ledgerEntry.expectedType;
938 auto const result = ledgerEntry.parseFunction(
939 context.
params[ledgerEntry.fieldName],
940 ledgerEntry.fieldName,
943 return result.error();
945 uNodeIndex = result.value();
954 jvResult[jss::error] =
"unknownOption";
973 jvResult[jss::index] =
to_string(uNodeIndex);
983 bool bNodeBinary =
false;
994 if ((expectedType !=
ltANY) && (expectedType != sleNode->getType()))
1019 org::xrpl::rpc::v1::GetLedgerEntryRequest
const& request = context.
params;
1020 org::xrpl::rpc::v1::GetLedgerEntryResponse response;
1021 grpc::Status
const status = grpc::Status::OK;
1026 grpc::Status errorStatus;
1029 errorStatus = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, status.message);
1033 errorStatus = grpc::Status(grpc::StatusCode::NOT_FOUND, status.message);
1035 return {response, errorStatus};
1041 grpc::Status
const errorStatus{grpc::StatusCode::INVALID_ARGUMENT,
"index malformed"};
1042 return {response, errorStatus};
1048 grpc::Status
const errorStatus{grpc::StatusCode::NOT_FOUND,
"object not found"};
1049 return {response, errorStatus};
1055 auto& stateObject = *response.mutable_ledger_object();
1057 stateObject.set_key(request.key());
1058 *response.mutable_ledger() = request.ledger();
1059 return {response, status};
Lightweight wrapper to tag static string.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
UInt size() const
Number of values in array or object.
bool isConvertibleTo(ValueType other) const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
static std::optional< BaseUInt > fromVoidChecked(T const &from)
void pushBack(STObject const &object)
static STObject makeInnerObject(SField const &name)
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
Blob const & peekData() const
An immutable linear range of bytes.
@ UInt
unsigned integer value
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet computation functions.
Keylet const & skip() noexcept
The index of the "short" skip list.
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Keylet oracle(AccountID const &account, std::uint32_t const documentID) noexcept
Keylet payChannel(AccountID const &src, AccountID const &dst, SeqProxy const &seq) noexcept
A PaymentChannel.
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Keylet did(AccountID const &account) noexcept
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet const & feeSettings() noexcept
The (fixed) index of the object containing the ledger fees.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet unchecked(UInt256 const &key) noexcept
Any ledger entry.
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Keylet page(UInt256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
Keylet loan(UInt256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
std::optional< T > parse(json::Value const ¶m)
std::expected< AccountID, json::Value > requiredAccountID(json::Value const ¶ms, json::StaticString const fieldName, std::string const &err)
std::expected< UInt192, json::Value > requiredUInt192(json::Value const ¶ms, json::StaticString const fieldName, std::string const &err)
std::expected< Asset, json::Value > requiredAsset(json::Value const ¶ms, json::StaticString const fieldName, std::string const &err)
std::expected< Blob, json::Value > requiredHexBlob(json::Value const ¶ms, json::StaticString const fieldName, std::size_t maxLength, std::string const &err)
std::unexpected< json::Value > malformedError(std::string const &err, std::string const &message)
std::expected< std::uint32_t, json::Value > requiredUInt32(json::Value const ¶ms, json::StaticString const fieldName, std::string const &err)
std::expected< UInt256, json::Value > requiredUInt256(json::Value const ¶ms, json::StaticString const fieldName, std::string const &err)
std::unexpected< json::Value > invalidFieldError(std::string const &err, json::StaticString const field, std::string const &type)
std::expected< bool, json::Value > hasRequired(json::Value const ¶ms, std::initializer_list< json::StaticString > fields, std::optional< std::string > err=std::nullopt)
::rpc::Status ledgerFromRequest(T &ledger, GRPCContext< R > const &context)
Retrieves a ledger from a gRPC request context.
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
::rpc::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.
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::function< std::expected< UInt256, json::Value >( json::Value const &, json::StaticString const, unsigned const apiVersion)> FunctionType
@ RpcUnexpectedLedgerType
static std::expected< STArray, json::Value > parseAuthorizeCredentials(json::Value const &jv)
static std::expected< UInt256, json::Value > parseFixed(Keylet const &keylet, json::Value const ¶ms, json::StaticString const &fieldName, unsigned const apiVersion)
auto const parseFeeSettings
std::pair< org::xrpl::rpc::v1::GetLedgerEntryResponse, grpc::Status > doLedgerEntryGrpc(rpc::GRPCContext< org::xrpl::rpc::v1::GetLedgerEntryRequest > const &context)
static std::expected< UInt256, json::Value > parseEscrow(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
constexpr std::size_t kMaxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
static std::expected< UInt256, json::Value > parseCredential(json::Value const &cred, json::StaticString const fieldName, unsigned const apiVersion)
std::string strHex(FwdIt begin, FwdIt end)
static std::expected< UInt256, json::Value > parseSponsorship(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseLoan(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseMPToken(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseRippleState(json::Value const &jvRippleState, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseIndex(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseTransactionProposal(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
static bool authorized(Port const &port, std::map< std::string, std::string > const &h)
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
static std::expected< UInt256, json::Value > parseLoanBroker(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseDirectoryNode(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static FunctionType fixed(Keylet const &keylet)
std::string to_string(BaseUInt< Bits, Tag > const &a)
auto const parseAmendments
static std::expected< UInt256, json::Value > parseTicket(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseOracle(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.
static std::expected< UInt256, json::Value > parseAccountRoot(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parsePermissionedDomain(json::Value const &pd, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseLedgerHashes(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
auto const parseNegativeUNL
static std::expected< UInt256, json::Value > parseCheck(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
json::Value doLedgerEntry(rpc::JsonContext &)
static std::expected< UInt256, json::Value > parseOffer(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseSignerList(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseVault(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseMPTokenIssuance(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseNFTokenOffer(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
static std::expected< UInt256, json::Value > parseDID(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parsePayChannel(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseDepositPreauth(json::Value const &dp, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseNFTokenPage(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseObjectID(json::Value const ¶ms, json::StaticString const fieldName, std::string const &expectedType="hex string or object")
static std::expected< UInt256, json::Value > parseAMM(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
static std::expected< UInt256, json::Value > parseDelegate(json::Value const ¶ms, json::StaticString const fieldName, unsigned const apiVersion)
A pair of SHAMap key and LedgerEntryType.
json::StaticString fieldName
FunctionType parseFunction
LedgerEntryType expectedType