1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/app/misc/NetworkOPs.h>
4#include <xrpld/rpc/Context.h>
5#include <xrpld/rpc/RPCSub.h>
6#include <xrpld/rpc/Role.h>
7#include <xrpld/rpc/detail/RPCHelpers.h>
9#include <xrpl/basics/Log.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/RPCErr.h>
13#include <xrpl/protocol/jss.h>
14#include <xrpl/resource/Fees.h>
27 JLOG(context.
j.
info()) <<
"doSubscribe: RPC subscribe requires a url";
53 JLOG(context.
j.
debug()) <<
"doSubscribe: building: " << strUrl;
73 JLOG(context.
j.
trace()) <<
"doSubscribe: reusing: " << strUrl;
81 rpcSub->setUsername(strUsername);
84 rpcSub->setPassword(strPassword);
98 JLOG(context.
j.
info()) <<
"doSubscribe: streams requires an array.";
102 for (
auto const& it : context.
params[jss::streams])
108 if (streamName ==
"server")
112 else if (streamName ==
"ledger")
116 else if (streamName ==
"book_changes")
120 else if (streamName ==
"manifests")
124 else if (streamName ==
"transactions")
128 else if (streamName ==
"transactions_proposed" || streamName ==
"rt_transactions")
132 else if (streamName ==
"validations")
136 else if (streamName ==
"peer_status")
142 else if (streamName ==
"consensus")
153 auto accountsProposed =
154 context.
params.
isMember(jss::accounts_proposed) ? jss::accounts_proposed : jss::rt_accounts;
175 JLOG(context.
j.
debug()) <<
"doSubscribe: accounts: " << ids.size();
184 auto const& req = context.
params[jss::account_history_tx_stream];
185 if (!req.isMember(jss::account) || !req[jss::account].isString())
188 auto const id = parseBase58<AccountID>(req[jss::account].asString());
197 jvResult[jss::warning] =
198 "account_history_tx_stream is an experimental feature and likely "
199 "to be removed in the future";
200 JLOG(context.
j.
debug()) <<
"doSubscribe: account_history_tx_stream: " <<
toBase58(*
id);
208 for (
auto& j : context.
params[jss::books])
210 if (!j.isObject() || !j.isMember(jss::taker_pays) || !j.isMember(jss::taker_gets) ||
211 !j[jss::taker_pays].isObjectOrNull() || !j[jss::taker_gets].isObjectOrNull())
219 if (!taker_pays.
isMember(jss::currency) ||
222 JLOG(context.
j.
info()) <<
"Bad taker_pays currency.";
227 if (((taker_pays.
isMember(jss::issuer)) &&
228 (!taker_pays[jss::issuer].
isString() ||
233 JLOG(context.
j.
info()) <<
"Bad taker_pays issuer.";
238 if (!taker_gets.
isMember(jss::currency) ||
241 JLOG(context.
j.
info()) <<
"Bad taker_gets currency.";
246 if (((taker_gets.
isMember(jss::issuer)) &&
247 (!taker_gets[jss::issuer].
isString() ||
252 JLOG(context.
j.
info()) <<
"Bad taker_gets issuer.";
258 JLOG(context.
j.
info()) <<
"taker_gets same as taker_pays.";
264 if (j.isMember(jss::taker))
266 takerID = parseBase58<AccountID>(j[jss::taker].asString());
271 if (j.isMember(jss::domain))
274 if (!j[jss::domain].isString() || !domain.
parseHex(j[jss::domain].asString()))
286 JLOG(context.
j.
warn()) <<
"Bad market: " << book;
293 bool const both = (j.isMember(jss::both) && j[jss::both].asBool()) ||
294 (j.isMember(jss::both_sides) && j[jss::both_sides].asBool());
300 if ((j.isMember(jss::snapshot) && j[jss::snapshot].asBool()) ||
301 (j.isMember(jss::state_now) && j[jss::state_now].asBool()))
313 field == jss::asks ?
reversed(book) : book,
323 for (
auto const& e : jvOffers[jss::offers])
328 jvResult[field] = jvOffers[jss::offers];
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.
Stream trace() const
Severity stream access functions.
virtual Config & config()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual boost::asio::io_context & getIOContext()=0
virtual JobQueue & getJobQueue()=0
virtual NetworkOPs & getOPs()=0
std::optional< uint256 > domain
virtual bool subTransactions(ref ispListener)=0
virtual error_code_i subAccountHistory(ref ispListener, AccountID const &account)=0
subscribe an account's new transactions and retrieve the account's historical transactions
virtual bool subPeerStatus(ref ispListener)=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 subBookChanges(ref ispListener)=0
virtual pointer addRpcSub(std::string const &strUrl, ref rspEntry)=0
virtual bool subServer(ref ispListener, Json::Value &jvResult, bool admin)=0
virtual bool subManifests(ref ispListener)=0
virtual bool subLedger(ref ispListener, Json::Value &jvResult)=0
virtual pointer findRpcSub(std::string const &strUrl)=0
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
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
@ objectValue
object value (collection of name/value pairs).
static LimitRange constexpr bookOffers
Limits for the book_offers command.
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Parses an array of account IDs from a JSON value.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Charge const feeMediumBurdenRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isConsistent(Book const &book)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Json::Value doSubscribe(RPC::JsonContext &)
std::shared_ptr< RPCSub > make_RPCSub(InfoSub::Source &source, boost::asio::io_context &io_context, JobQueue &jobQueue, std::string const &strUrl, std::string const &strUsername, std::string const &strPassword, Logs &logs)
Book reversed(Book const &book)
Json::Value rpcError(error_code_i iError)
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
AccountID const & noAccount()
A placeholder for empty accounts.
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Resource::Charge & loadType