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 <xrpld/app/misc/NetworkOPs.h>
24#include <xrpld/app/misc/TxQ.h>
25#include <xrpld/rpc/Context.h>
26#include <xrpld/rpc/Status.h>
27#include <xrpld/rpc/detail/Tuning.h>
28
29#include <xrpl/beast/core/SemanticVersion.h>
30#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.pb.h>
31#include <xrpl/protocol/ApiVersion.h>
32#include <xrpl/protocol/SecretKey.h>
33
34#include <optional>
35#include <variant>
36
37namespace Json {
38class Value;
39}
40
41namespace ripple {
42
43class ReadView;
44class Transaction;
45
46namespace RPC {
47
48struct JsonContext;
49
53
54// --> strIdent: public key, account ID, or regular seed.
55// --> bStrict: Only allow account id or public key.
56//
57// Returns a Json::objectValue, containing error information if there was one.
60 AccountID& result,
61 std::string const& strIdent,
62 bool bStrict = false);
63
72 AccountID& result,
73 std::string const& strIdent,
74 bool bStrict = false);
75
81getStartHint(std::shared_ptr<SLE const> const& sle, AccountID const& accountID);
82
89bool
91 ReadView const& ledger,
93 AccountID const& accountID);
94
104bool
106 ReadView const& ledger,
107 AccountID const& account,
109 uint256 dirIndex,
110 uint256 entryIndex,
111 std::uint32_t const limit,
112 Json::Value& jvResult);
113
118template <class T>
119Status
120getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
121
126template <class T>
127Status
128getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
129
135template <class T>
136Status
137getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
138
147
153Status
156 JsonContext&,
157 Json::Value& result);
158
159template <class T, class R>
160Status
161ledgerFromRequest(T& ledger, GRPCContext<R>& context);
162
163template <class T>
164Status
166 T& ledger,
167 org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
168 Context& context);
169
171parseAccountIds(Json::Value const& jvArray);
172
173bool
175
184void
185injectSLE(Json::Value& jv, SLE const& sle);
186
194 unsigned int& limit,
195 Tuning::LimitRange const&,
196 JsonContext const&);
197
199getSeedFromRPC(Json::Value const& params, Json::Value& error);
200
202parseRippleLibSeed(Json::Value const& params);
203
210
211template <class Object>
212void
213setVersion(Object& parent, unsigned int apiVersion, bool betaEnabled)
214{
215 XRPL_ASSERT(
217 "ripple::RPC::setVersion : input is valid");
218 auto&& object = addObject(parent, jss::version);
220 {
221 object[jss::first] = firstVersion.print();
222 object[jss::good] = goodVersion.print();
223 object[jss::last] = lastVersion.print();
224 }
225 else
226 {
227 object[jss::first] = apiMinimumSupportedVersion.value;
228 object[jss::last] =
230 }
231}
232
235
242bool
244
259unsigned int
260getAPIVersionNumber(const Json::Value& value, bool betaEnabled);
261
266
269 Json::Value const& params,
270 Json::Value& error,
271 unsigned int apiVersion = apiVersionIfUnspecified);
272} // namespace RPC
273} // namespace ripple
274
275#endif
Represents a JSON value.
Definition: json_value.h:148
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:207
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:209
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:208
void setVersion(Object &parent, unsigned int apiVersion, bool betaEnabled)
Definition: RPCHelpers.h:213
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:558
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:54
Represents RPC limit parameter values that have a min, default and max.