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 template <class T>
98 Status
99 getLedger(T& ledger, uint256 const& ledgerHash, Context& context);
100 
105 template <class T>
106 Status
107 getLedger(T& ledger, uint32_t ledgerIndex, Context& context);
108 
114 template <class T>
115 Status
116 getLedger(T& ledger, LedgerShortcut shortcut, Context& context);
117 
126 
132 Status
135  JsonContext&,
136  Json::Value& result);
137 
138 template <class T, class R>
139 Status
140 ledgerFromRequest(T& ledger, GRPCContext<R>& context);
141 
142 template <class T>
143 Status
145  T& ledger,
146  org::xrpl::rpc::v1::LedgerSpecifier const& specifier,
147  Context& context);
148 
149 bool
151  LedgerMaster& ledgerMaster,
152  ReadView const& ledger,
153  Application& app);
154 
156 parseAccountIds(Json::Value const& jvArray);
157 
158 bool
159 isHexTxID(std::string const& txid);
160 
169 void
170 injectSLE(Json::Value& jv, SLE const& sle);
171 
177 boost::optional<Json::Value>
179  unsigned int& limit,
180  Tuning::LimitRange const&,
181  JsonContext const&);
182 
183 boost::optional<Seed>
184 getSeedFromRPC(Json::Value const& params, Json::Value& error);
185 
186 boost::optional<Seed>
187 parseRippleLibSeed(Json::Value const& params);
188 
190 keypairForSignature(Json::Value const& params, Json::Value& error);
191 
198 
217 constexpr unsigned int APIInvalidVersion = 0;
218 constexpr unsigned int APIVersionIfUnspecified = 1;
219 constexpr unsigned int ApiMinimumSupportedVersion = 1;
220 constexpr unsigned int ApiMaximumSupportedVersion = 1;
221 constexpr unsigned int APINumberVersionSupported =
223 
226 
227 template <class Object>
228 void
229 setVersion(Object& parent)
230 {
231  auto&& object = addObject(parent, jss::version);
232  object[jss::first] = firstVersion.print();
233  object[jss::good] = goodVersion.print();
234  object[jss::last] = lastVersion.print();
235 }
236 
238 chooseLedgerEntryType(Json::Value const& params);
239 
253 unsigned int
254 getAPIVersionNumber(const Json::Value& value);
255 
256 } // namespace RPC
257 } // namespace ripple
258 
259 #endif
ripple::Application
Definition: Application.h:101
ripple::RPC::CURRENT
@ CURRENT
Definition: RPCHelpers.h:109
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:195
ripple::RPC::goodVersion
const beast::SemanticVersion goodVersion("1.0.0")
Definition: RPCHelpers.h:196
std::string
STL class.
std::shared_ptr
STL class.
ripple::RPC::isHexTxID
bool isHexTxID(std::string const &txid)
ripple::RPC::getAPIVersionNumber
unsigned int getAPIVersionNumber(Json::Value const &jv)
Retrieve the api version number from the json value.
Definition: RPCHelpers.cpp:887
std::unordered_set
STL class.
ripple::RPC::injectSLE
void injectSLE(Json::Value &jv, SLE const &sle)
Inject JSON describing ledger entry.
Definition: RPCHelpers.cpp:587
std::pair
ripple::RPC::LedgerShortcut
LedgerShortcut
Definition: RPCHelpers.h:109
ripple::LedgerMaster
Definition: LedgerMaster.h:72
std::vector
STL class.
ripple::RPC::parseRippleLibSeed
boost::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Definition: RPCHelpers.cpp:631
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:221
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:218
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:535
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:612
ripple::RPC::ApiMinimumSupportedVersion
constexpr unsigned int ApiMinimumSupportedVersion
Definition: RPCHelpers.h:219
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:54
ripple::RPC::VALIDATED
@ VALIDATED
Definition: RPCHelpers.h:109
ripple::RPC::ApiMaximumSupportedVersion
constexpr unsigned int ApiMaximumSupportedVersion
Definition: RPCHelpers.h:220
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:109
std::uint32_t
ripple::RPC::APIInvalidVersion
constexpr unsigned int APIInvalidVersion
API version numbers used in later API versions.
Definition: RPCHelpers.h:217
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:464
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:340
ripple::RPC::chooseLedgerEntryType
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const &params)
Definition: RPCHelpers.cpp:835
ripple::RPC::keypairForSignature
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const &params, Json::Value &error)
Definition: RPCHelpers.cpp:708
ripple::RPC::ledgerFromSpecifier
Status ledgerFromSpecifier(T &ledger, org::xrpl::rpc::v1::LedgerSpecifier const &specifier, Context &context)
Definition: RPCHelpers.cpp:284
ripple::RPC::setVersion
void setVersion(Object &parent)
Definition: RPCHelpers.h:229
ripple::RPC::parseAccountIds
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Definition: RPCHelpers.cpp:571
ripple::RPC::lastVersion
const beast::SemanticVersion lastVersion("1.0.0")
Definition: RPCHelpers.h:197
ripple::RPC::ledgerFromRequest
Status ledgerFromRequest(T &ledger, GRPCContext< R > &context)
Definition: RPCHelpers.cpp:252
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:650