rippled
Loading...
Searching...
No Matches
RPCHelpers.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012=2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_RPC_RPCHELPERS_H_INCLUDED
21#define RIPPLE_RPC_RPCHELPERS_H_INCLUDED
22
23#include <xrpl/beast/core/SemanticVersion.h>
24#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.pb.h>
25#include <xrpl/protocol/ApiVersion.h>
26#include <xrpl/protocol/TxMeta.h>
27
28#include <xrpld/app/misc/NetworkOPs.h>
29#include <xrpld/app/misc/TxQ.h>
30#include <xrpld/rpc/Context.h>
31#include <xrpld/rpc/Status.h>
32#include <xrpld/rpc/detail/Tuning.h>
33#include <xrpl/protocol/SecretKey.h>
34
35#include <optional>
36#include <variant>
37
38namespace Json {
39class Value;
40}
41
42namespace ripple {
43
44class ReadView;
45class Transaction;
46
47namespace RPC {
48
49struct JsonContext;
50
54
55// --> strIdent: public key, account ID, or regular seed.
56// --> bStrict: Only allow account id or public key.
57//
58// Returns a Json::objectValue, containing error information if there was one.
61 AccountID& result,
62 std::string const& strIdent,
63 bool bStrict = false);
64
73 AccountID& result,
74 std::string const& strIdent,
75 bool bStrict = false);
76
82getStartHint(std::shared_ptr<SLE const> const& sle, AccountID const& accountID);
83
90bool
92 ReadView const& ledger,
94 AccountID const& accountID);
95
105bool
107 ReadView const& ledger,
108 AccountID const& account,
110 uint256 dirIndex,
111 uint256 entryIndex,
112 std::uint32_t const limit,
113 Json::Value& jvResult);
114
119template <class T>
120Status
121getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
122
127template <class T>
128Status
129getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
130
136template <class T>
137Status
138getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
139
148
154Status
157 JsonContext&,
158 Json::Value& result);
159
160template <class T, class R>
161Status
162ledgerFromRequest(T& ledger, GRPCContext<R>& context);
163
164template <class T>
165Status
167 T& ledger,
168 org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
169 Context& context);
170
172parseAccountIds(Json::Value const& jvArray);
173
174bool
176
185void
186injectSLE(Json::Value& jv, SLE const& sle);
187
195 unsigned int& limit,
196 Tuning::LimitRange const&,
197 JsonContext const&);
198
200getSeedFromRPC(Json::Value const& params, Json::Value& error);
201
203parseRippleLibSeed(Json::Value const& params);
204
211
212template <class Object>
213void
214setVersion(Object& parent, unsigned int apiVersion, bool betaEnabled)
215{
216 XRPL_ASSERT(
218 "ripple::RPC::setVersion : input is valid");
219 auto&& object = addObject(parent, jss::version);
221 {
222 object[jss::first] = firstVersion.print();
223 object[jss::good] = goodVersion.print();
224 object[jss::last] = lastVersion.print();
225 }
226 else
227 {
228 object[jss::first] = apiMinimumSupportedVersion.value;
229 object[jss::last] =
231 }
232}
233
236
243bool
245
260unsigned int
261getAPIVersionNumber(const Json::Value& value, bool betaEnabled);
262
267
270 Json::Value const& params,
271 Json::Value& error,
272 unsigned int apiVersion = apiVersionIfUnspecified);
273} // namespace RPC
274} // namespace ripple
275
276#endif
Represents a JSON value.
Definition: json_value.h:147
A Semantic Version number.
std::string print() const
Produce a string from semantic version components.
JSON (JavaScript Object Notation).
Definition: json_errors.h:25
Status
Return codes from Backend operations.
beast::SemanticVersion const firstVersion("1.0.0")
API version numbers used in API version 1.
Definition: RPCHelpers.h:208
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Definition: RPCHelpers.cpp:408
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
error_code_i accountFromStringWithCode(AccountID &result, std::string const &strIdent, bool bStrict)
Decode account ID from string.
Definition: RPCHelpers.cpp:60
std::optional< Seed > getSeedFromRPC(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:736
beast::SemanticVersion const lastVersion("1.0.0")
Definition: RPCHelpers.h:210
static constexpr auto apiMaximumSupportedVersion
Definition: ApiVersion.h:58
std::variant< std::shared_ptr< Ledger const >, Json::Value > getLedgerByContext(RPC::JsonContext &context)
Return a ledger based on ledger_hash or ledger_index, or an RPC error.
bool isAccountObjectsValidType(LedgerEntryType const &type)
Check if the type is a valid filtering type for account_objects method.
Definition: RPCHelpers.cpp:986
static constexpr std::integral_constant< unsigned, Version > apiVersion
Definition: ApiVersion.h:54
bool isRelatedToAccount(ReadView const &ledger, std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Tests if a SLE is owned by accountID.
Definition: RPCHelpers.cpp:115
void injectSLE(Json::Value &jv, SLE const &sle)
Inject JSON describing ledger entry.
Definition: RPCHelpers.cpp:673
Status getLedger(T &ledger, uint256 const &ledgerHash, Context &context)
Get ledger by hash If there is no error in the return value, the ledger pointer will have been filled...
Definition: RPCHelpers.cpp:488
static constexpr auto apiBetaVersion
Definition: ApiVersion.h:62
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:931
bool getAccountObjects(ReadView const &ledger, AccountID const &account, std::optional< std::vector< LedgerEntryType > > const &typeFilter, uint256 dirIndex, uint256 entryIndex, std::uint32_t const limit, Json::Value &jvResult)
Gathers all objects for an account in a ledger.
Definition: RPCHelpers.cpp:153
std::optional< Json::Value > readLimitField(unsigned int &limit, Tuning::LimitRange const &range, JsonContext const &context)
Retrieve the limit value from a JsonContext, or set a default - then restrict the limit by max and mi...
Definition: RPCHelpers.cpp:698
beast::SemanticVersion const goodVersion("1.0.0")
Definition: RPCHelpers.h:209
void setVersion(Object &parent, unsigned int apiVersion, bool betaEnabled)
Definition: RPCHelpers.h:214
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:88
static constexpr auto apiVersionIfUnspecified
Definition: ApiVersion.h:59
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.
Definition: RPCHelpers.cpp:622
Status ledgerFromSpecifier(T &ledger, org::xrpl::rpc::v1::LedgerSpecifier const &specifier, Context &context)
Definition: RPCHelpers.cpp:434
std::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
Definition: RPCHelpers.cpp:44
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:657
static constexpr auto apiInvalidVersion
Definition: ApiVersion.h:56
std::uint64_t getStartHint(std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
Definition: RPCHelpers.cpp:98
static constexpr auto apiMinimumSupportedVersion
Definition: ApiVersion.h:57
bool isHexTxID(std::string const &txid)
std::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Definition: RPCHelpers.cpp:717
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(Json::Value const &params, Json::Value &error, unsigned int apiVersion)
Definition: RPCHelpers.cpp:795
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
error_code_i
Definition: ErrorCodes.h:40
base_uint< 256 > uint256
Definition: base_uint.h:557
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:54
Represents RPC limit parameter values that have a min, default and max.