1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/GRPCHandlers.h>
3#include <xrpld/rpc/detail/RPCHelpers.h>
4#include <xrpld/rpc/handlers/LedgerEntryHelpers.h>
6#include <xrpl/basics/StringUtilities.h>
7#include <xrpl/basics/strHex.h>
8#include <xrpl/beast/core/LexicalCast.h>
9#include <xrpl/json/json_errors.h>
10#include <xrpl/ledger/CredentialHelpers.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/RPCErr.h>
16#include <xrpl/protocol/STXChainBridge.h>
17#include <xrpl/protocol/jss.h>
23static Expected<uint256, Json::Value>
27 std::string const& expectedType =
"hex string or object")
29 if (
auto const uNodeIndex = LedgerEntryHelpers::parse<uint256>(params))
34 "malformedRequest", fieldName, expectedType);
37static Expected<uint256, Json::Value>
43static Expected<uint256, Json::Value>
46 if (
auto const account = LedgerEntryHelpers::parse<AccountID>(params))
52 "malformedAddress", fieldName,
"AccountID");
55static Expected<uint256, Json::Value>
61static Expected<uint256, Json::Value>
69 if (
auto const value =
88static Expected<uint256, Json::Value>
96 if (params[jss::bridge].isString())
107 params, jss::bridge_account,
"malformedBridgeAccount");
113 if (account.value() != bridge->door(chainType))
119static Expected<uint256, Json::Value>
125static Expected<uint256, Json::Value>
134 cred, jss::subject,
"malformedRequest");
139 cred, jss::issuer,
"malformedRequest");
145 jss::credential_type,
152 *subject, *issuer,
Slice(credType->data(), credType->size()))
156static Expected<uint256, Json::Value>
165 params, jss::account,
"malformedAddress");
170 params, jss::authorize,
"malformedAddress");
177static Expected<STArray, Json::Value>
182 "malformedAuthorizedCredentials",
183 jss::authorized_credentials,
186 for (
auto const& jo : jv)
190 "malformedAuthorizedCredentials",
191 jss::authorized_credentials,
195 {jss::issuer, jss::credential_type},
196 "malformedAuthorizedCredentials");
203 jo, jss::issuer,
"malformedAuthorizedCredentials");
209 jss::credential_type,
211 "malformedAuthorizedCredentials");
217 credential.setFieldVL(sfCredentialType, *credentialType);
224static Expected<uint256, Json::Value>
232 if ((dp.
isMember(jss::authorized) ==
233 dp.
isMember(jss::authorized_credentials)))
237 "Must have exactly one of `authorized` and "
238 "`authorized_credentials`.");
251 LedgerEntryHelpers::parse<AccountID>(dp[jss::authorized]))
256 "malformedAuthorized", jss::authorized,
"AccountID");
259 auto const& ac(dp[jss::authorized_credentials]);
261 if (!arr.has_value())
266 "malformedAuthorizedCredentials",
267 jss::authorized_credentials,
276 "malformedAuthorizedCredentials",
277 jss::authorized_credentials,
284static Expected<uint256, Json::Value>
287 auto const account = LedgerEntryHelpers::parse<AccountID>(params);
291 "malformedAddress", fieldName,
"AccountID");
297static Expected<uint256, Json::Value>
307 if (params.
isMember(jss::sub_index) &&
309 params[jss::sub_index].
isBool()))
312 "malformedRequest", jss::sub_index,
"number");
319 "Must have exactly one of `owner` and `dir_root` fields.");
326 if (
auto const uDirRoot =
327 LedgerEntryHelpers::parse<uint256>(params[jss::dir_root]))
333 "malformedDirRoot", jss::dir_root,
"hash");
339 LedgerEntryHelpers::parse<AccountID>(params[jss::owner]);
343 "malformedAddress", jss::owner,
"AccountID");
352static Expected<uint256, Json::Value>
361 params, jss::owner,
"malformedOwner");
372static Expected<uint256, Json::Value>
378static Expected<uint256, Json::Value>
384static Expected<uint256, Json::Value>
393 params, jss::mpt_issuance_id,
"malformedMPTIssuanceID");
398 params, jss::account,
"malformedAccount");
405static Expected<uint256, Json::Value>
410 auto const mptIssuanceID = LedgerEntryHelpers::parse<uint192>(params);
413 "malformedMPTokenIssuance", fieldName,
"Hash192");
418static Expected<uint256, Json::Value>
424static Expected<uint256, Json::Value>
430static Expected<uint256, Json::Value>
436static Expected<uint256, Json::Value>
445 params, jss::account,
"malformedAddress");
450 params, jss::seq,
"malformedRequest");
457static Expected<uint256, Json::Value>
466 params, jss::account,
"malformedAccount");
471 params, jss::oracle_document_id,
"malformedDocumentID");
478static Expected<uint256, Json::Value>
484static Expected<uint256, Json::Value>
497 "malformedRequest", fieldName,
"hex string or object");
501 pd, jss::account,
"malformedAddress");
513static Expected<uint256, Json::Value>
526 jvRippleState, {jss::currency, jss::accounts});
532 if (!jvRippleState[jss::accounts].isArray() ||
533 jvRippleState[jss::accounts].size() != 2)
536 "malformedRequest", jss::accounts,
"length-2 array of Accounts");
540 LedgerEntryHelpers::parse<AccountID>(jvRippleState[jss::accounts][0u]);
542 LedgerEntryHelpers::parse<AccountID>(jvRippleState[jss::accounts][1u]);
546 "malformedAddress", jss::accounts,
"array of Accounts");
551 "malformedRequest",
"Cannot have a trustline to self.");
554 if (!jvRippleState[jss::currency].isString() ||
555 jvRippleState[jss::currency] ==
"" ||
556 !
to_currency(uCurrency, jvRippleState[jss::currency].asString()))
559 "malformedCurrency", jss::currency,
"Currency");
565static Expected<uint256, Json::Value>
571static Expected<uint256, Json::Value>
580 params, jss::account,
"malformedAddress");
585 params, jss::ticket_seq,
"malformedRequest");
592static Expected<uint256, Json::Value>
601 params, jss::owner,
"malformedOwner");
606 params, jss::seq,
"malformedRequest");
613static Expected<uint256, Json::Value>
628 claim_id, jss::xchain_owned_claim_id,
"malformedXChainOwnedClaimID");
638static Expected<uint256, Json::Value>
654 jss::xchain_owned_create_account_claim_id,
655 "malformedXChainOwnedCreateAccountClaimID");
685#pragma push_macro("LEDGER_ENTRY")
688#define LEDGER_ENTRY(tag, value, name, rpcName, fields) \
689 {jss::rpcName, parse##name, tag},
691#include <xrpl/protocol/detail/ledger_entries.macro>
694#pragma pop_macro("LEDGER_ENTRY")
701 auto hasMoreThanOneMember = [&]() {
704 for (
auto const& ledgerEntry : ledgerEntryParsers)
716 if (hasMoreThanOneMember)
733 for (
auto const& ledgerEntry : ledgerEntryParsers)
737 expectedType = ledgerEntry.expectedType;
742 Json::Value const& params = ledgerEntry.fieldName == jss::bridge
744 : context.
params[ledgerEntry.fieldName];
746 ledgerEntry.parseFunction(params, ledgerEntry.fieldName);
748 return result.error();
750 uNodeIndex = result.value();
759 jvResult[jss::error] =
"unknownOption";
784 bool bNodeBinary =
false;
794 if ((expectedType !=
ltANY) && (expectedType != sleNode->getType()))
806 jvResult[jss::index] =
to_string(uNodeIndex);
811 jvResult[jss::index] =
to_string(uNodeIndex);
821 org::xrpl::rpc::v1::GetLedgerEntryRequest& request = context.
params;
822 org::xrpl::rpc::v1::GetLedgerEntryResponse response;
823 grpc::Status status = grpc::Status::OK;
828 grpc::Status errorStatus;
831 errorStatus = grpc::Status(
832 grpc::StatusCode::INVALID_ARGUMENT, status.message());
837 grpc::Status(grpc::StatusCode::NOT_FOUND, status.message());
839 return {response, errorStatus};
845 grpc::Status errorStatus{
846 grpc::StatusCode::INVALID_ARGUMENT,
"index malformed"};
847 return {response, errorStatus};
853 grpc::Status errorStatus{
854 grpc::StatusCode::NOT_FOUND,
"object not found"};
855 return {response, errorStatus};
861 auto& stateObject = *response.mutable_ledger_object();
863 stateObject.set_key(request.key());
864 *(response.mutable_ledger()) = request.ledger();
865 return {response, status};
Lightweight wrapper to tag static string.
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
bool isConvertibleTo(ValueType other) const
void push_back(STObject const &object)
static STObject makeInnerObject(SField const &name)
static ChainType srcChain(bool wasLockingChainSend)
Blob const & peekData() const
An immutable linear range of bytes.
static std::optional< base_uint > fromVoidChecked(T const &from)
@ uintValue
unsigned integer value
Expected< STXChainBridge, Json::Value > parseBridgeFields(Json::Value const ¶ms)
Unexpected< Json::Value > malformedError(std::string const &err, std::string const &message)
Unexpected< Json::Value > invalidFieldError(std::string const &err, Json::StaticString const field, std::string const &type)
Unexpected< Json::Value > missingFieldError(Json::StaticString const field, std::optional< std::string > err=std::nullopt)
Expected< bool, Json::Value > hasRequired(Json::Value const ¶ms, std::initializer_list< Json::StaticString > fields, std::optional< std::string > err=std::nullopt)
Expected< AccountID, Json::Value > requiredAccountID(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< std::uint32_t, Json::Value > requiredUInt32(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< uint192, Json::Value > requiredUInt192(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &err)
Expected< Blob, Json::Value > requiredHexBlob(Json::Value const ¶ms, Json::StaticString const fieldName, std::size_t maxLength, std::string const &err)
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
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.
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet oracle(AccountID const &account, std::uint32_t const &documentID) noexcept
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet xChainClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Keylet did(AccountID const &account) noexcept
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Keylet bridge(STXChainBridge const &bridge, STXChainBridge::ChainType chainType)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet xChainCreateAccountClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static Expected< uint256, Json::Value > parseOracle(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseCredential(Json::Value const &cred, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseFeeSettings(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseXChainOwnedClaimID(Json::Value const &claim_id, Json::StaticString const fieldName)
Json::Value doLedgerEntry(RPC::JsonContext &)
static Expected< uint256, Json::Value > parsePayChannel(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseNFTokenOffer(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseCheck(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseEscrow(Json::Value const ¶ms, Json::StaticString const fieldName)
@ rpcUNEXPECTED_LEDGER_TYPE
static Expected< uint256, Json::Value > parseXChainOwnedCreateAccountClaimID(Json::Value const &claim_id, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseIndex(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseDelegate(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseDepositPreauth(Json::Value const &dp, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseSignerList(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parsePermissionedDomain(Json::Value const &pd, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseBridge(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseAMM(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseMPToken(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< STArray, Json::Value > parseAuthorizeCredentials(Json::Value const &jv)
Issue issueFromJson(Json::Value const &v)
std::string strHex(FwdIt begin, FwdIt end)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
std::pair< org::xrpl::rpc::v1::GetLedgerEntryResponse, grpc::Status > doLedgerEntryGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetLedgerEntryRequest > &context)
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
static Expected< uint256, Json::Value > parseOffer(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseNegativeUNL(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseVault(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseMPTokenIssuance(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseNFTokenPage(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseDirectoryNode(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseAmendments(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseAccountRoot(Json::Value const ¶ms, Json::StaticString const fieldName)
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
static Expected< uint256, Json::Value > parseTicket(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseObjectID(Json::Value const ¶ms, Json::StaticString const fieldName, std::string const &expectedType="hex string or object")
std::string to_string(base_uint< Bits, Tag > const &a)
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
Expected< uint256, Json::Value >(*)(Json::Value const &, Json::StaticString const) FunctionType
static Expected< uint256, Json::Value > parseLedgerHashes(Json::Value const ¶ms, Json::StaticString const fieldName)
@ credential
Credentials signature.
static Expected< uint256, Json::Value > parseDID(Json::Value const ¶ms, Json::StaticString const fieldName)
static Expected< uint256, Json::Value > parseRippleState(Json::Value const &jvRippleState, Json::StaticString const fieldName)
static bool authorized(Port const &port, std::map< std::string, std::string > const &h)
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
A pair of SHAMap key and LedgerEntryType.
LedgerEntryType expectedType
Json::StaticString fieldName
FunctionType parseFunction