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 
35 namespace Json {
36 class Value;
37 }
38 
39 namespace ripple {
40 
41 class ReadView;
42 class Transaction;
43 
44 namespace RPC {
45 
46 struct JsonContext;
47 
51 
52 // --> strIdent: public key, account ID, or regular seed.
53 // --> bStrict: Only allow account id or public key.
54 //
55 // Returns a Json::objectValue, containing error information if there was one.
58  AccountID& result,
59  std::string const& strIdent,
60  bool bStrict = false);
61 
70  AccountID& result,
71  std::string const& strIdent,
72  bool bStrict = false);
73 
79 getStartHint(std::shared_ptr<SLE const> const& sle, AccountID const& accountID);
80 
87 bool
89  ReadView const& ledger,
90  std::shared_ptr<SLE const> const& sle,
91  AccountID const& accountID);
92 
102 bool
104  ReadView const& ledger,
105  AccountID const& account,
106  std::optional<std::vector<LedgerEntryType>> const& typeFilter,
107  uint256 dirIndex,
108  uint256 const& entryIndex,
109  std::uint32_t const limit,
110  Json::Value& jvResult);
111 
116 template <class T>
117 Status
118 getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
119 
124 template <class T>
125 Status
126 getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
127 
133 template <class T>
134 Status
135 getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
136 
145 
151 Status
154  JsonContext&,
155  Json::Value& result);
156 
157 template <class T, class R>
158 Status
159 ledgerFromRequest(T& ledger, GRPCContext<R>& context);
160 
161 template <class T>
162 Status
164  T& ledger,
165  org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
166  Context& context);
167 
168 bool
170  LedgerMaster& ledgerMaster,
171  ReadView const& ledger,
172  Application& app);
173 
175 parseAccountIds(Json::Value const& jvArray);
176 
177 bool
178 isHexTxID(std::string const& txid);
179 
188 void
189 injectSLE(Json::Value& jv, SLE const& sle);
190 
198  unsigned int& limit,
199  Tuning::LimitRange const&,
200  JsonContext const&);
201 
203 getSeedFromRPC(Json::Value const& params, Json::Value& error);
204 
206 parseRippleLibSeed(Json::Value const& params);
207 
209 keypairForSignature(Json::Value const& params, Json::Value& error);
210 
217 
240 constexpr unsigned int apiInvalidVersion = 0;
241 constexpr unsigned int apiVersionIfUnspecified = 1;
242 constexpr unsigned int apiMinimumSupportedVersion = 1;
243 constexpr unsigned int apiMaximumSupportedVersion = 1;
244 constexpr unsigned int apiBetaVersion = 2;
245 
249 
250 template <class Object>
251 void
252 setVersion(Object& parent, unsigned int apiVersion, bool betaEnabled)
253 {
254  assert(apiVersion != apiInvalidVersion);
255  auto&& object = addObject(parent, jss::version);
256  if (apiVersion == apiVersionIfUnspecified)
257  {
258  object[jss::first] = firstVersion.print();
259  object[jss::good] = goodVersion.print();
260  object[jss::last] = lastVersion.print();
261  }
262  else
263  {
264  object[jss::first] = apiMinimumSupportedVersion;
265  object[jss::last] =
267  }
268 }
269 
271 chooseLedgerEntryType(Json::Value const& params);
272 
287 unsigned int
288 getAPIVersionNumber(const Json::Value& value, bool betaEnabled);
289 
290 } // namespace RPC
291 } // namespace ripple
292 
293 #endif
ripple::RPC::apiInvalidVersion
constexpr unsigned int apiInvalidVersion
API version numbers used in later API versions.
Definition: RPCHelpers.h:240
ripple::Application
Definition: Application.h:115
ripple::RPC::apiVersionIfUnspecified
constexpr unsigned int apiVersionIfUnspecified
Definition: RPCHelpers.h:241
ripple::RPC::CURRENT
@ CURRENT
Definition: RPCHelpers.h:128
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:214
ripple::RPC::goodVersion
const beast::SemanticVersion goodVersion("1.0.0")
Definition: RPCHelpers.h:215
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:634
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:128
ripple::LedgerMaster
Definition: LedgerMaster.h:70
ripple::RPC::getAPIVersionNumber
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Definition: RPCHelpers.cpp:934
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:659
beast::SemanticVersion
A Semantic Version number.
Definition: SemanticVersion.h:35
ripple::RPC::apiBetaVersion
constexpr unsigned int apiBetaVersion
Definition: RPCHelpers.h:244
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:582
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::RPC::parseRippleLibSeed
std::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Definition: RPCHelpers.cpp:678
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:56
ripple::RPC::VALIDATED
@ VALIDATED
Definition: RPCHelpers.h:128
ripple::RPC::isOwnedByAccount
bool isOwnedByAccount(ReadView const &ledger, std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Tests if a SLE is owned by accountID.
Definition: RPCHelpers.cpp:111
ripple::RPC::CLOSED
@ CLOSED
Definition: RPCHelpers.h:128
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:192
ripple::RPC::apiMinimumSupportedVersion
constexpr unsigned int apiMinimumSupportedVersion
Definition: RPCHelpers.h:242
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:510
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:386
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:882
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:94
ripple::RPC::keypairForSignature
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:755
ripple::RPC::getSeedFromRPC
std::optional< Seed > getSeedFromRPC(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:697
ripple::RPC::apiMaximumSupportedVersion
constexpr unsigned int apiMaximumSupportedVersion
Definition: RPCHelpers.h:243
ripple::RPC::ledgerFromSpecifier
Status ledgerFromSpecifier(T &ledger, org::xrpl::rpc::v1::LedgerSpecifier const &specifier, Context &context)
Definition: RPCHelpers.cpp:327
optional
ripple::RPC::parseAccountIds
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:618
ripple::RPC::accountFromStringStrict
std::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
Definition: RPCHelpers.cpp:40
ripple::RPC::lastVersion
const beast::SemanticVersion lastVersion("1.0.0")
Definition: RPCHelpers.h:216
ripple::RPC::ledgerFromRequest
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Definition: RPCHelpers.cpp:295
ripple::RPC::accountFromString
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:84
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::RPC::getAccountObjects
bool getAccountObjects(ReadView const &ledger, AccountID const &account, std::optional< std::vector< LedgerEntryType >> const &typeFilter, uint256 dirIndex, uint256 const &entryIndex, std::uint32_t const limit, Json::Value &jvResult)
Gathers all objects for an account in a ledger.
Definition: RPCHelpers.cpp:135
ripple::RPC::setVersion
void setVersion(Object &parent, unsigned int apiVersion, bool betaEnabled)
Definition: RPCHelpers.h:252