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/proto/org/xrpl/rpc/v1/xrp_ledger.pb.h>
25 #include <ripple/protocol/TxMeta.h>
26 
27 #include <ripple/app/misc/NetworkOPs.h>
28 #include <ripple/app/misc/TxQ.h>
29 #include <ripple/basics/Expected.h>
30 #include <ripple/basics/SubmitSync.h>
31 #include <ripple/protocol/SecretKey.h>
32 #include <ripple/rpc/Context.h>
33 #include <ripple/rpc/Status.h>
34 #include <ripple/rpc/impl/Tuning.h>
35 #include <optional>
36 #include <variant>
37 
38 namespace Json {
39 class Value;
40 }
41 
42 namespace ripple {
43 
44 class ReadView;
45 class Transaction;
46 
47 namespace RPC {
48 
49 struct 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 
82 getStartHint(std::shared_ptr<SLE const> const& sle, AccountID const& accountID);
83 
90 bool
92  ReadView const& ledger,
93  std::shared_ptr<SLE const> const& sle,
94  AccountID const& accountID);
95 
105 bool
107  ReadView const& ledger,
108  AccountID const& account,
109  std::optional<std::vector<LedgerEntryType>> const& typeFilter,
110  uint256 dirIndex,
111  uint256 entryIndex,
112  std::uint32_t const limit,
113  Json::Value& jvResult);
114 
119 template <class T>
120 Status
121 getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
122 
127 template <class T>
128 Status
129 getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
130 
136 template <class T>
137 Status
138 getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
139 
148 
154 Status
157  JsonContext&,
158  Json::Value& result);
159 
160 template <class T, class R>
161 Status
162 ledgerFromRequest(T& ledger, GRPCContext<R>& context);
163 
164 template <class T>
165 Status
167  T& ledger,
168  org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
169  Context& context);
170 
171 bool
173  LedgerMaster& ledgerMaster,
174  ReadView const& ledger,
175  Application& app);
176 
178 parseAccountIds(Json::Value const& jvArray);
179 
180 bool
181 isHexTxID(std::string const& txid);
182 
191 void
192 injectSLE(Json::Value& jv, SLE const& sle);
193 
201  unsigned int& limit,
202  Tuning::LimitRange const&,
203  JsonContext const&);
204 
206 getSeedFromRPC(Json::Value const& params, Json::Value& error);
207 
209 parseRippleLibSeed(Json::Value const& params);
210 
212 keypairForSignature(Json::Value const& params, Json::Value& error);
213 
220 
243 constexpr unsigned int apiInvalidVersion = 0;
244 constexpr unsigned int apiVersionIfUnspecified = 1;
245 constexpr unsigned int apiMinimumSupportedVersion = 1;
246 constexpr unsigned int apiMaximumSupportedVersion = 1;
247 constexpr unsigned int apiBetaVersion = 2;
248 
252 
253 template <class Object>
254 void
255 setVersion(Object& parent, unsigned int apiVersion, bool betaEnabled)
256 {
257  assert(apiVersion != apiInvalidVersion);
258  auto&& object = addObject(parent, jss::version);
259  if (apiVersion == apiVersionIfUnspecified)
260  {
261  object[jss::first] = firstVersion.print();
262  object[jss::good] = goodVersion.print();
263  object[jss::last] = lastVersion.print();
264  }
265  else
266  {
267  object[jss::first] = apiMinimumSupportedVersion;
268  object[jss::last] =
270  }
271 }
272 
274 chooseLedgerEntryType(Json::Value const& params);
275 
290 unsigned int
291 getAPIVersionNumber(const Json::Value& value, bool betaEnabled);
292 
297 
304 getSubmitSyncMode(Json::Value const& params);
305 
306 } // namespace RPC
307 } // namespace ripple
308 
309 #endif
ripple::RPC::apiInvalidVersion
constexpr unsigned int apiInvalidVersion
API version numbers used in later API versions.
Definition: RPCHelpers.h:243
ripple::Application
Definition: Application.h:116
ripple::RPC::apiVersionIfUnspecified
constexpr unsigned int apiVersionIfUnspecified
Definition: RPCHelpers.h:244
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::RPC::CURRENT
@ CURRENT
Definition: RPCHelpers.h:131
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:217
ripple::RPC::goodVersion
const beast::SemanticVersion goodVersion("1.0.0")
Definition: RPCHelpers.h:218
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:728
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:131
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:152
ripple::RPC::getAPIVersionNumber
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Definition: RPCHelpers.cpp:1039
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:753
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:1060
ripple::RPC::apiBetaVersion
constexpr unsigned int apiBetaVersion
Definition: RPCHelpers.h:247
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:676
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:772
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:29
ripple::Expected
Definition: Expected.h:132
ripple::RPC::accountFromStringWithCode
error_code_i accountFromStringWithCode(AccountID &result, std::string const &strIdent, bool bStrict)
Decode account ID from string.
Definition: RPCHelpers.cpp:59
ripple::RPC::VALIDATED
@ VALIDATED
Definition: RPCHelpers.h:131
ripple::RPC::CLOSED
@ CLOSED
Definition: RPCHelpers.h:131
std::uint64_t
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:45
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:54
ripple::RPC::apiMinimumSupportedVersion
constexpr unsigned int apiMinimumSupportedVersion
Definition: RPCHelpers.h:245
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:604
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:480
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:980
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:97
ripple::RPC::keypairForSignature
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:850
ripple::RPC::getSeedFromRPC
std::optional< Seed > getSeedFromRPC(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:791
ripple::RPC::getSubmitSyncMode
ripple::Expected< RPC::SubmitSync, Json::Value > getSubmitSyncMode(Json::Value const &params)
Helper to parse submit_mode parameter to RPC submit.
Definition: RPCHelpers.cpp:1177
ripple::RPC::apiMaximumSupportedVersion
constexpr unsigned int apiMaximumSupportedVersion
Definition: RPCHelpers.h:246
ripple::RPC::ledgerFromSpecifier
Status ledgerFromSpecifier(T &ledger, org::xrpl::rpc::v1::LedgerSpecifier const &specifier, Context &context)
Definition: RPCHelpers.cpp:421
optional
ripple::RPC::parseAccountIds
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:712
ripple::RPC::accountFromStringStrict
std::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
Definition: RPCHelpers.cpp:43
ripple::RPC::lastVersion
const beast::SemanticVersion lastVersion("1.0.0")
Definition: RPCHelpers.h:219
ripple::RPC::ledgerFromRequest
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Definition: RPCHelpers.cpp:395
ripple::RPC::accountFromString
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:87
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:114
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:255
variant