rippled
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 <ripple/beast/core/SemanticVersion.h>
24 #include <ripple/protocol/TxMeta.h>
25 
26 #include <ripple/app/misc/NetworkOPs.h>
27 #include <ripple/app/misc/TxQ.h>
28 #include <ripple/protocol/SecretKey.h>
29 #include <ripple/rpc/Context.h>
30 #include <ripple/rpc/Status.h>
31 #include <ripple/rpc/impl/Tuning.h>
32 #include <optional>
33 #include <org/xrpl/rpc/v1/xrp_ledger.pb.h>
34 #include <variant>
35 
36 namespace Json {
37 class Value;
38 }
39 
40 namespace ripple {
41 
42 class ReadView;
43 class Transaction;
44 
45 namespace RPC {
46 
47 struct JsonContext;
48 
52 
53 // --> strIdent: public key, account ID, or regular seed.
54 // --> bStrict: Only allow account id or public key.
55 //
56 // Returns a Json::objectValue, containing error information if there was one.
59  AccountID& result,
60  std::string const& strIdent,
61  bool bStrict = false);
62 
71  AccountID& result,
72  std::string const& strIdent,
73  bool bStrict = false);
74 
80 getStartHint(std::shared_ptr<SLE const> const& sle, AccountID const& accountID);
81 
88 bool
90  ReadView const& ledger,
91  std::shared_ptr<SLE const> const& sle,
92  AccountID const& accountID);
93 
103 bool
105  ReadView const& ledger,
106  AccountID const& account,
107  std::optional<std::vector<LedgerEntryType>> const& typeFilter,
108  uint256 dirIndex,
109  uint256 entryIndex,
110  std::uint32_t const limit,
111  Json::Value& jvResult);
112 
117 template <class T>
118 Status
119 getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
120 
125 template <class T>
126 Status
127 getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
128 
134 template <class T>
135 Status
136 getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
137 
146 
152 Status
155  JsonContext&,
156  Json::Value& result);
157 
158 template <class T, class R>
159 Status
160 ledgerFromRequest(T& ledger, GRPCContext<R>& context);
161 
162 template <class T>
163 Status
165  T& ledger,
166  org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
167  Context& context);
168 
169 bool
171  LedgerMaster& ledgerMaster,
172  ReadView const& ledger,
173  Application& app);
174 
176 parseAccountIds(Json::Value const& jvArray);
177 
178 bool
179 isHexTxID(std::string const& txid);
180 
189 void
190 injectSLE(Json::Value& jv, SLE const& sle);
191 
199  unsigned int& limit,
200  Tuning::LimitRange const&,
201  JsonContext const&);
202 
204 getSeedFromRPC(Json::Value const& params, Json::Value& error);
205 
207 parseRippleLibSeed(Json::Value const& params);
208 
210 keypairForSignature(Json::Value const& params, Json::Value& error);
211 
218 
241 constexpr unsigned int apiInvalidVersion = 0;
242 constexpr unsigned int apiVersionIfUnspecified = 1;
243 constexpr unsigned int apiMinimumSupportedVersion = 1;
244 constexpr unsigned int apiMaximumSupportedVersion = 1;
245 constexpr unsigned int apiBetaVersion = 2;
246 
250 
251 template <class Object>
252 void
253 setVersion(Object& parent, unsigned int apiVersion, bool betaEnabled)
254 {
255  assert(apiVersion != apiInvalidVersion);
256  auto&& object = addObject(parent, jss::version);
257  if (apiVersion == apiVersionIfUnspecified)
258  {
259  object[jss::first] = firstVersion.print();
260  object[jss::good] = goodVersion.print();
261  object[jss::last] = lastVersion.print();
262  }
263  else
264  {
265  object[jss::first] = apiMinimumSupportedVersion;
266  object[jss::last] =
268  }
269 }
270 
272 chooseLedgerEntryType(Json::Value const& params);
273 
288 unsigned int
289 getAPIVersionNumber(const Json::Value& value, bool betaEnabled);
290 
295 
296 } // namespace RPC
297 } // namespace ripple
298 
299 #endif
ripple::RPC::apiInvalidVersion
constexpr unsigned int apiInvalidVersion
API version numbers used in later API versions.
Definition: RPCHelpers.h:241
ripple::Application
Definition: Application.h:115
ripple::RPC::apiVersionIfUnspecified
constexpr unsigned int apiVersionIfUnspecified
Definition: RPCHelpers.h:242
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::RPC::CURRENT
@ CURRENT
Definition: RPCHelpers.h:129
ripple::STLedgerEntry
Definition: STLedgerEntry.h:30
ripple::RPC::firstVersion
const beast::SemanticVersion firstVersion("1.0.0")
API version numbers used in API version 1.
Definition: RPCHelpers.h:215
ripple::RPC::goodVersion
const beast::SemanticVersion goodVersion("1.0.0")
Definition: RPCHelpers.h:216
std::string
STL class.
std::shared_ptr
STL class.
ripple::RPC::isHexTxID
bool isHexTxID(std::string const &txid)
std::unordered_set
STL class.
ripple::RPC::injectSLE
void injectSLE(Json::Value &jv, SLE const &sle)
Inject JSON describing ledger entry.
Definition: RPCHelpers.cpp:727
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:129
ripple::LedgerMaster
Definition: LedgerMaster.h:70
ripple::RPC::getAccountObjects
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:151
ripple::RPC::getAPIVersionNumber
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Definition: RPCHelpers.cpp:1033
std::vector
STL class.
beast::SemanticVersion::print
std::string print() const
Produce a string from semantic version components.
Definition: SemanticVersion.cpp:236
ripple::RPC::readLimitField
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:752
beast::SemanticVersion
A Semantic Version number.
Definition: SemanticVersion.h:35
ripple::RPC::getLedgerByContext
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.
Definition: RPCHelpers.cpp:1054
ripple::RPC::apiBetaVersion
constexpr unsigned int apiBetaVersion
Definition: RPCHelpers.h:245
ripple::RPC::lookupLedger
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:675
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::RPC::parseRippleLibSeed
std::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Definition: RPCHelpers.cpp:771
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:27
ripple::RPC::accountFromStringWithCode
error_code_i accountFromStringWithCode(AccountID &result, std::string const &strIdent, bool bStrict)
Decode account ID from string.
Definition: RPCHelpers.cpp:58
ripple::RPC::VALIDATED
@ VALIDATED
Definition: RPCHelpers.h:129
ripple::RPC::CLOSED
@ CLOSED
Definition: RPCHelpers.h:129
std::uint64_t
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:44
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple::RPC::apiMinimumSupportedVersion
constexpr unsigned int apiMinimumSupportedVersion
Definition: RPCHelpers.h:243
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RPC::isValidated
bool isValidated(LedgerMaster &ledgerMaster, ReadView const &ledger, Application &app)
Definition: RPCHelpers.cpp:603
ripple::RPC::getLedger
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:479
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:979
ripple::RPC::getStartHint
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:96
ripple::RPC::keypairForSignature
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:849
ripple::RPC::getSeedFromRPC
std::optional< Seed > getSeedFromRPC(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:790
ripple::RPC::apiMaximumSupportedVersion
constexpr unsigned int apiMaximumSupportedVersion
Definition: RPCHelpers.h:244
ripple::RPC::ledgerFromSpecifier
Status ledgerFromSpecifier(T &ledger, org::xrpl::rpc::v1::LedgerSpecifier const &specifier, Context &context)
Definition: RPCHelpers.cpp:420
optional
ripple::RPC::parseAccountIds
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:711
ripple::RPC::accountFromStringStrict
std::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
Definition: RPCHelpers.cpp:42
ripple::RPC::lastVersion
const beast::SemanticVersion lastVersion("1.0.0")
Definition: RPCHelpers.h:217
ripple::RPC::ledgerFromRequest
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Definition: RPCHelpers.cpp:394
ripple::RPC::accountFromString
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:86
ripple::RPC::isRelatedToAccount
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:113
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::RPC::setVersion
void setVersion(Object &parent, unsigned int apiVersion, bool betaEnabled)
Definition: RPCHelpers.h:253
variant