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/ledger/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 <boost/optional.hpp>
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 
49 boost::optional<AccountID>
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 
83 bool
85  ReadView const& ledger,
86  AccountID const& account,
87  boost::optional<std::vector<LedgerEntryType>> const& typeFilter,
88  uint256 dirIndex,
89  uint256 const& entryIndex,
90  std::uint32_t const limit,
91  Json::Value& jvResult);
92 
97 Status
98 getLedger(
100  uint256 const& ledgerHash,
101  Context& context);
102 
107 template <class T>
108 Status
109 getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
110 
116 template <class T>
117 Status
118 getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
119 
128 
134 Status
137  JsonContext&,
138  Json::Value& result);
139 
140 template <class T>
141 Status
143  T& ledger,
144  GRPCContext<org::xrpl::rpc::v1::GetAccountInfoRequest>& context);
145 
146 bool
148  LedgerMaster& ledgerMaster,
149  ReadView const& ledger,
150  Application& app);
151 
153 parseAccountIds(Json::Value const& jvArray);
154 
163 void
164 injectSLE(Json::Value& jv, SLE const& sle);
165 
171 boost::optional<Json::Value>
173  unsigned int& limit,
174  Tuning::LimitRange const&,
175  JsonContext const&);
176 
177 boost::optional<Seed>
178 getSeedFromRPC(Json::Value const& params, Json::Value& error);
179 
180 boost::optional<Seed>
181 parseRippleLibSeed(Json::Value const& params);
182 
184 keypairForSignature(Json::Value const& params, Json::Value& error);
185 
192 
211 constexpr unsigned int APIInvalidVersion = 0;
212 constexpr unsigned int APIVersionIfUnspecified = 1;
213 constexpr unsigned int ApiMinimumSupportedVersion = 1;
214 constexpr unsigned int ApiMaximumSupportedVersion = 1;
215 constexpr unsigned int APINumberVersionSupported =
217 
220 
221 template <class Object>
222 void
223 setVersion(Object& parent)
224 {
225  auto&& object = addObject(parent, jss::version);
226  object[jss::first] = firstVersion.print();
227  object[jss::good] = goodVersion.print();
228  object[jss::last] = lastVersion.print();
229 }
230 
232 chooseLedgerEntryType(Json::Value const& params);
233 
247 unsigned int
248 getAPIVersionNumber(const Json::Value& value);
249 
250 } // namespace RPC
251 } // namespace ripple
252 
253 #endif
ripple::Application
Definition: Application.h:97
ripple::RPC::getLedger
Status getLedger(std::shared_ptr< ReadView const > &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:307
ripple::RPC::CURRENT
@ CURRENT
Definition: RPCHelpers.h:111
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:189
ripple::RPC::goodVersion
const beast::SemanticVersion goodVersion("1.0.0")
Definition: RPCHelpers.h:190
std::string
STL class.
std::shared_ptr
STL class.
ripple::RPC::getAPIVersionNumber
unsigned int getAPIVersionNumber(Json::Value const &jv)
Retrieve the api version number from the json value.
Definition: RPCHelpers.cpp:839
std::unordered_set
STL class.
ripple::RPC::injectSLE
void injectSLE(Json::Value &jv, SLE const &sle)
Inject JSON describing ledger entry.
Definition: RPCHelpers.cpp:539
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:111
ripple::LedgerMaster
Definition: LedgerMaster.h:54
std::vector
STL class.
ripple::RPC::parseRippleLibSeed
boost::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Definition: RPCHelpers.cpp:583
beast::SemanticVersion::print
std::string print() const
Produce a string from semantic version components.
Definition: SemanticVersion.cpp:236
ripple::RPC::APINumberVersionSupported
constexpr unsigned int APINumberVersionSupported
Definition: RPCHelpers.h:215
ripple::RPC::getAccountObjects
bool getAccountObjects(ReadView const &ledger, AccountID const &account, boost::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:92
ripple::RPC::APIVersionIfUnspecified
constexpr unsigned int APIVersionIfUnspecified
Definition: RPCHelpers.h:212
beast::SemanticVersion
A Semantic Version number.
Definition: SemanticVersion.h:35
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:487
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:457
ripple::RPC::readLimitField
boost::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:564
ripple::RPC::ApiMinimumSupportedVersion
constexpr unsigned int ApiMinimumSupportedVersion
Definition: RPCHelpers.h:213
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:26
ripple::RPC::accountFromStringWithCode
error_code_i accountFromStringWithCode(AccountID &result, std::string const &strIdent, bool bStrict)
Decode account ID from string.
Definition: RPCHelpers.cpp:54
ripple::RPC::VALIDATED
@ VALIDATED
Definition: RPCHelpers.h:111
ripple::RPC::ApiMaximumSupportedVersion
constexpr unsigned int ApiMaximumSupportedVersion
Definition: RPCHelpers.h:214
ripple::RPC::accountFromStringStrict
boost::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
Definition: RPCHelpers.cpp:38
ripple::RPC::CLOSED
@ CLOSED
Definition: RPCHelpers.h:111
std::uint32_t
ripple::RPC::APIInvalidVersion
constexpr unsigned int APIInvalidVersion
API version numbers used in later API versions.
Definition: RPCHelpers.h:211
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
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:419
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:787
ripple::RPC::keypairForSignature
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:660
ripple::RPC::setVersion
void setVersion(Object &parent)
Definition: RPCHelpers.h:223
ripple::RPC::parseAccountIds
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:523
ripple::RPC::lastVersion
const beast::SemanticVersion lastVersion("1.0.0")
Definition: RPCHelpers.h:191
ripple::RPC::accountFromString
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Definition: RPCHelpers.cpp:82
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::RPC::getSeedFromRPC
boost::optional< Seed > getSeedFromRPC(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:602
ripple::RPC::ledgerFromRequest
Status ledgerFromRequest(T &ledger, GRPCContext< org::xrpl::rpc::v1::GetAccountInfoRequest > &context)
Definition: RPCHelpers.cpp:250