1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/rpc/Context.h>
4#include <xrpld/rpc/RPCSub.h>
5#include <xrpld/rpc/Role.h>
6#include <xrpld/rpc/detail/RPCHelpers.h>
7#include <xrpld/rpc/detail/Tuning.h>
9#include <xrpl/basics/Log.h>
10#include <xrpl/basics/base_uint.h>
11#include <xrpl/json/json_value.h>
12#include <xrpl/ledger/ReadView.h>
13#include <xrpl/protocol/AccountID.h>
14#include <xrpl/protocol/Book.h>
15#include <xrpl/protocol/ErrorCodes.h>
16#include <xrpl/protocol/RPCErr.h>
17#include <xrpl/protocol/jss.h>
18#include <xrpl/resource/Fees.h>
19#include <xrpl/server/InfoSub.h>
20#include <xrpl/server/NetworkOPs.h>
38 JLOG(context.
j.
info()) <<
"doSubscribe: RPC subscribe requires a url";
66 JLOG(context.
j.
debug()) <<
"doSubscribe: building: " << strUrl;
87 JLOG(context.
j.
trace()) <<
"doSubscribe: reusing: " << strUrl;
95 rpcSub->setUsername(strUsername);
98 rpcSub->setPassword(strPassword);
112 JLOG(context.
j.
info()) <<
"doSubscribe: streams requires an array.";
116 for (
auto const& it : context.
params[jss::streams])
122 if (streamName ==
"server")
126 else if (streamName ==
"ledger")
130 else if (streamName ==
"book_changes")
134 else if (streamName ==
"manifests")
138 else if (streamName ==
"transactions")
143 streamName ==
"transactions_proposed" ||
144 streamName ==
"rt_transactions")
148 else if (streamName ==
"validations")
152 else if (streamName ==
"peer_status")
158 else if (streamName ==
"consensus")
169 auto accountsProposed = context.
params.
isMember(jss::accounts_proposed)
170 ? jss::accounts_proposed
192 JLOG(context.
j.
debug()) <<
"doSubscribe: accounts: " << ids.size();
201 auto const& req = context.
params[jss::account_history_tx_stream];
202 if (!req.isMember(jss::account) || !req[jss::account].isString())
214 jvResult[jss::warning] =
215 "account_history_tx_stream is an experimental feature and likely "
216 "to be removed in the future";
217 JLOG(context.
j.
debug()) <<
"doSubscribe: account_history_tx_stream: " <<
toBase58(*
id);
225 for (
auto& j : context.
params[jss::books])
227 if (!j.isObject() || !j.isMember(jss::taker_pays) || !j.isMember(jss::taker_gets) ||
228 !j[jss::taker_pays].isObjectOrNull() || !j[jss::taker_gets].isObjectOrNull())
241 if (book.in == book.out)
243 JLOG(context.
j.
info()) <<
"taker_gets same as taker_pays.";
249 if (j.isMember(jss::taker))
251 if (!j[jss::taker].isString())
258 if (j.isMember(jss::domain))
261 if (!j[jss::domain].isString() || !domain.
parseHex(j[jss::domain].asString()))
266 book.domain = domain;
271 JLOG(context.
j.
warn()) <<
"Bad market: " << book;
278 bool const both = (j.isMember(jss::both) && j[jss::both].asBool()) ||
279 (j.isMember(jss::both_sides) && j[jss::both_sides].asBool());
285 if ((j.isMember(jss::snapshot) && j[jss::snapshot].asBool()) ||
286 (j.isMember(jss::state_now) && j[jss::state_now].asBool()))
299 field == jss::asks ?
reversed(book) : book,
309 for (
auto const& e : jvOffers[jss::offers])
314 jvResult[field] = jvOffers[jss::offers];
Stream trace() const
Severity stream access functions.
Lightweight wrapper to tag static string.
Value & append(Value const &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual Config & config()=0
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
virtual ErrorCodeI subAccountHistory(ref ispListener, AccountID const &account)=0
subscribe an account's new transactions and retrieve the account's historical transactions
virtual bool subTransactions(ref ispListener)=0
virtual bool subPeerStatus(ref ispListener)=0
virtual bool subServer(ref ispListener, json::Value &jvResult, bool admin)=0
virtual bool subConsensus(ref ispListener)=0
virtual void subAccount(ref ispListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
virtual bool subBook(ref ispListener, Book const &)=0
virtual bool subValidations(ref ispListener)=0
virtual bool subRTTransactions(ref ispListener)=0
virtual bool subLedger(ref ispListener, json::Value &jvResult)=0
virtual bool subBookChanges(ref ispListener)=0
virtual pointer addRpcSub(std::string const &strUrl, ref rspEntry)=0
virtual bool subManifests(ref ispListener)=0
virtual pointer findRpcSub(std::string const &strUrl)=0
std::shared_ptr< InfoSub > pointer
void setApiVersion(unsigned int apiVersion)
std::shared_ptr< ReadView const > getPublishedLedger()
virtual void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &book, AccountID const &uTakerID, bool const bProof, unsigned int iLimit, json::Value const &jvMarker, json::Value &jvResult)=0
virtual JobQueue & getJobQueue()=0
virtual NetworkOPs & getOPs()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual boost::asio::io_context & getIOContext()=0
@ Object
object value (collection of name/value pairs).
static constexpr LimitRange kBookOffers
Limits for the book_offers command.
hash_set< AccountID > parseAccountIds(json::Value const &jvArray)
Parses an array of account IDs from a JSON value.
ErrorCodeI parseSubUnsubJson(Asset &asset, json::Value const ¶ms, json::StaticString const &name, beast::Journal j)
Parse subscribe/unsubscribe parameters.
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
Charge const kFeeMediumBurdenRpc
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::shared_ptr< RPCSub > makeRPCSub(InfoSub::Source &source, boost::asio::io_context &ioContext, JobQueue &jobQueue, std::string const &strUrl, std::string const &strUsername, std::string const &strPassword, ServiceRegistry ®istry)
json::Value rpcError(ErrorCodeI iError)
Book reversed(Book const &book)
json::Value doSubscribe(RPC::JsonContext &)
AccountID const & noAccount()
A placeholder for empty accounts.
bool isConsistent(Asset const &asset)
T dynamic_pointer_cast(T... args)
Resource::Charge & loadType