xrpld
Loading...
Searching...
No Matches
RPCCall.cpp
1#include <xrpld/rpc/RPCCall.h>
2
3#include <xrpld/core/Config.h>
4#include <xrpld/rpc/MethodNames.h>
5#include <xrpld/rpc/ServerHandler.h>
6
7#include <xrpl/basics/ByteUtilities.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/Slice.h>
10#include <xrpl/basics/StringUtilities.h>
11#include <xrpl/basics/base64.h>
12#include <xrpl/basics/base_uint.h>
13#include <xrpl/basics/contract.h>
14#include <xrpl/beast/core/LexicalCast.h>
15#include <xrpl/beast/utility/Journal.h>
16#include <xrpl/beast/utility/Zero.h>
17#include <xrpl/beast/utility/instrumentation.h>
18#include <xrpl/json/json_forwards.h>
19#include <xrpl/json/json_reader.h>
20#include <xrpl/json/json_value.h>
21#include <xrpl/json/to_string.h>
22#include <xrpl/net/HTTPClient.h>
23#include <xrpl/protocol/AccountID.h>
24#include <xrpl/protocol/ApiVersion.h>
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/JsonRpc.h>
27#include <xrpl/protocol/KeyType.h>
28#include <xrpl/protocol/PublicKey.h>
29#include <xrpl/protocol/RPCErr.h>
30#include <xrpl/protocol/SystemParameters.h>
31#include <xrpl/protocol/jss.h>
32#include <xrpl/protocol/tokens.h>
33
34#include <boost/algorithm/string/predicate.hpp>
35#include <boost/asio/io_context.hpp>
36#include <boost/asio/streambuf.hpp>
37#include <boost/regex/v5/regex.hpp>
38#include <boost/regex/v5/regex_match.hpp>
39#include <boost/system/detail/error_code.hpp>
40
41#include <algorithm>
42#include <array>
43#include <chrono>
44#include <cstddef>
45#include <cstdint>
46#include <exception>
47#include <functional>
48#include <iostream>
49#include <limits>
50#include <optional>
51#include <span>
52#include <sstream>
53#include <stdexcept>
54#include <string>
55#include <string_view>
56#include <unordered_map>
57#include <utility>
58#include <vector>
59
60namespace xrpl {
61
62class RPCParser;
63
64namespace {
65
77class Parse
78{
79public:
80 using Function = json::Value (RPCParser::*)(json::Value const& jvParams);
81
88 template <Function Fn>
89 static constexpr Parse
90 of() noexcept
91 {
92 return Parse{Fn};
93 }
94
105 json::Value
106 operator()(RPCParser& parser, json::Value const& jvParams) const;
107
108private:
109 constexpr explicit Parse(Function fn) noexcept : fn_(fn)
110 {
111 }
112
113 Function fn_;
114};
115
116// One command the command line accepts: the method it names, the parser that
117// turns arguments into a request, and how many arguments that parser needs.
118//
119// Declared out here, rather than nested in RPCParser, so that the defaults
120// below can be used: a default member initializer is not available while the
121// enclosing class is still incomplete, which is when the table is built.
122struct Command
123{
124 // For a command that accepts any number of parameters.
125 static constexpr unsigned kUnlimitedParams = std::numeric_limits<unsigned>::max();
126
127 std::string_view name;
128 Parse parse;
129 unsigned minParams = 0;
130 unsigned maxParams = kUnlimitedParams;
131};
132
133} // namespace
134
135//
136// HTTP protocol
137//
138// This ain't Apache. We're just using HTTP header for the length field
139// and to be compatible with other JSON-RPC implementations.
140//
141
142std::string
144 std::string const& strHost,
145 std::string const& strPath,
146 std::string const& strMsg,
147 std::unordered_map<std::string, std::string> const& mapRequestHeaders)
148{
150
151 // CHECKME this uses a different version than the replies below use. Is
152 // this by design or an accident or should it be using
153 // build_info::getFullVersionString () as well?
154
155 s << "POST " << (strPath.empty() ? "/" : strPath) << " HTTP/1.0\r\n"
156 << "User-Agent: " << systemName() << "-json-rpc/v1\r\n"
157 << "Host: " << strHost << "\r\n"
158 << "Content-Type: application/json\r\n"
159 << "Content-Length: " << strMsg.size() << "\r\n"
160 << "Accept: application/json\r\n";
161
162 for (auto const& [k, v] : mapRequestHeaders)
163 s << k << ": " << v << "\r\n";
164
165 s << "\r\n" << strMsg;
166
167 return s.str();
168}
169
171{
172private:
173 unsigned const apiVersion_;
175
176 // TODO New routine for parsing ledger parameters, other routines should
177 // standardize on this.
178 static bool
179 jvParseLedger(json::Value& jvRequest, std::string const& strLedger)
180 {
181 if (strLedger == "current" || strLedger == "closed" || strLedger == "validated")
182 {
183 jvRequest[jss::ledger_index] = strLedger;
184 }
185 else if (strLedger.length() == 64)
186 {
187 // YYY Could confirm this is a UInt256.
188 jvRequest[jss::ledger_hash] = strLedger;
189 }
190 else
191 {
192 jvRequest[jss::ledger_index] = beast::lexicalCast<std::uint32_t>(strLedger);
193 }
194
195 return true;
196 }
197
198 // Build a object { "currency" : "XYZ", "issuer" : "rXYX" }
199 static json::Value
200 jvParseCurrencyIssuer(std::string const& strCurrencyIssuer)
201 {
202 // Matches a sequence of 3 characters from
203 // `xrpl::detail::isoCharSet` (the currency),
204 // optionally followed by a forward slash and some other characters
205 // (the issuer).
206 // https://www.boost.org/doc/libs/1_82_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
207 static boost::regex const kReCurIss("\\`([][:alnum:]<>(){}[|?!@#$%^&*]{3})(?:/(.+))?\\'");
208
209 boost::smatch smMatch;
210
211 if (boost::regex_match(strCurrencyIssuer, smMatch, kReCurIss))
212 {
214 std::string const strCurrency = smMatch[1];
215 std::string const strIssuer = smMatch[2];
216
217 jvResult[jss::currency] = strCurrency;
218
219 if (!strIssuer.empty())
220 {
221 // Could confirm issuer is a valid XRPL address.
222 jvResult[jss::issuer] = strIssuer;
223 }
224
225 return jvResult;
226 }
227
228 return rpc::makeParamError(
229 std::string("Invalid currency/issuer '") + strCurrencyIssuer + "'");
230 }
231
232 static bool
234 {
235 if (parseBase58<xrpl::PublicKey>(type, strPk))
236 return true;
237
238 auto pkHex = strUnHex(strPk);
239 if (!pkHex)
240 return false;
241
242 if (!publicKeyType(makeSlice(*pkHex)))
243 return false;
244
245 return true;
246 }
247
248private:
249 using ParseFuncPtr = json::Value (RPCParser::*)(json::Value const& jvParams);
250
252 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
253 parseAsIs(json::Value const& jvParams)
254 {
256
257 if (jvParams.isArray() && (jvParams.size() > 0))
258 v[jss::params] = jvParams;
259
260 return v;
261 }
262
264 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
265 parseInternal(json::Value const& jvParams)
266 {
268 v[jss::internal_command] = jvParams[0u];
269
271
272 for (unsigned i = 1; i < jvParams.size(); ++i)
273 params.append(jvParams[i]);
274
275 v[jss::params] = params;
276
277 return v;
278 }
279
281 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
282 parseManifest(json::Value const& jvParams)
283 {
284 if (jvParams.size() == 1)
285 {
287
288 std::string const strPk = jvParams[0u].asString();
291
292 jvRequest[jss::public_key] = strPk;
293
294 return jvRequest;
295 }
296
298 }
299
300 // fetch_info [clear]
302 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
304 {
306 unsigned int const iParams = jvParams.size();
307
308 if (iParams != 0)
309 jvRequest[jvParams[0u].asString()] = true;
310
311 return jvRequest;
312 }
313
314 // account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary]
315 // [count] [descending]
317 // NOLINTNEXTLINE(readability-make-member-function-const)
319 {
321 unsigned int iParams = jvParams.size();
322
323 auto const account = parseBase58<AccountID>(jvParams[0u].asString());
324 if (!account)
326
327 jvRequest[jss::account] = toBase58(*account);
328
329 bool bDone = false;
330
331 while (!bDone && iParams >= 2)
332 {
333 // VFALCO Why is json::StaticString appearing on the right side?
334 if (jvParams[iParams - 1].asString() == jss::binary)
335 {
336 jvRequest[jss::binary] = true;
337 --iParams;
338 }
339 else if (jvParams[iParams - 1].asString() == jss::count)
340 {
341 jvRequest[jss::count] = true;
342 --iParams;
343 }
344 else if (jvParams[iParams - 1].asString() == jss::descending)
345 {
346 jvRequest[jss::descending] = true;
347 --iParams;
348 }
349 else
350 {
351 bDone = true;
352 }
353 }
354
355 if (1 == iParams)
356 {
357 }
358 else if (2 == iParams)
359 {
360 if (!jvParseLedger(jvRequest, jvParams[1u].asString()))
361 return jvRequest;
362 }
363 else
364 {
365 std::int64_t const uLedgerMin = jvParams[1u].asInt();
366 std::int64_t const uLedgerMax = jvParams[2u].asInt();
367
368 if (uLedgerMax != -1 && uLedgerMax < uLedgerMin)
369 {
370 if (apiVersion_ == 1)
372 return rpcError(RpcNotSynced);
373 }
374
375 jvRequest[jss::ledger_index_min] = jvParams[1u].asInt();
376 jvRequest[jss::ledger_index_max] = jvParams[2u].asInt();
377
378 if (iParams >= 4)
379 jvRequest[jss::limit] = jvParams[3u].asInt();
380
381 if (iParams >= 5)
382 jvRequest[jss::offset] = jvParams[4u].asInt();
383 }
384
385 return jvRequest;
386 }
387
388 // book_offers <taker_pays> <taker_gets> [<taker> [<ledger> [<limit>
389 // [<proof> [<marker>]]]]] limit: 0 = no limit proof: 0 or 1
390 //
391 // Mnemonic: taker pays --> offer --> taker gets
393 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
395 {
397
398 json::Value jvTakerPays = jvParseCurrencyIssuer(jvParams[0u].asString());
399 json::Value jvTakerGets = jvParseCurrencyIssuer(jvParams[1u].asString());
400
401 if (isRpcError(jvTakerPays))
402 {
403 return jvTakerPays;
404 }
405
406 jvRequest[jss::taker_pays] = jvTakerPays;
407
408 if (isRpcError(jvTakerGets))
409 {
410 return jvTakerGets;
411 }
412
413 jvRequest[jss::taker_gets] = jvTakerGets;
414
415 if (jvParams.size() >= 3)
416 {
417 jvRequest[jss::issuer] = jvParams[2u].asString();
418 }
419
420 if (jvParams.size() >= 4 && !jvParseLedger(jvRequest, jvParams[3u].asString()))
421 return jvRequest;
422
423 if (jvParams.size() >= 5)
424 {
425 try
426 {
427 int const iLimit = jvParams[4u].asInt();
428
429 if (iLimit > 0)
430 jvRequest[jss::limit] = iLimit;
431 }
432 catch (std::exception const&)
433 {
434 return rpc::invalidFieldError(jss::limit);
435 }
436 }
437
438 if (jvParams.size() >= 6)
439 {
440 try
441 {
442 int const bProof = jvParams[5u].asInt();
443 if (bProof != 0)
444 jvRequest[jss::proof] = true;
445 }
446 catch (std::exception const&)
447 {
448 return rpc::invalidFieldError(jss::proof);
449 }
450 }
451
452 if (jvParams.size() == 7)
453 jvRequest[jss::marker] = jvParams[6u];
454
455 return jvRequest;
456 }
457
458 // can_delete [<ledgerid>|<ledgerhash>|now|always|never]
460 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
462 {
464
465 if (jvParams.size() == 0u)
466 return jvRequest;
467
468 std::string const input = jvParams[0u].asString();
469 if (input.find_first_not_of("0123456789") == std::string::npos)
470 {
471 jvRequest["can_delete"] = jvParams[0u].asUInt();
472 }
473 else
474 {
475 jvRequest["can_delete"] = input;
476 }
477
478 return jvRequest;
479 }
480
481 // connect <ip[:port]> [port]
483 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
484 parseConnect(json::Value const& jvParams)
485 {
487 std::string ip = jvParams[0u].asString();
488 if (jvParams.size() == 2)
489 {
490 jvRequest[jss::ip] = ip;
491 jvRequest[jss::port] = jvParams[1u].asUInt();
492 return jvRequest;
493 }
494
495 // handle case where there is one argument of the form ip:port
496 if (std::count(ip.begin(), ip.end(), ':') == 1)
497 {
498 std::size_t const colon = ip.find_last_of(':');
499 jvRequest[jss::ip] = std::string{ip, 0, colon};
500 jvRequest[jss::port] = json::Value{std::string{ip, colon + 1}}.asUInt();
501 return jvRequest;
502 }
503
504 // default case, no port
505 jvRequest[jss::ip] = ip;
506 return jvRequest;
507 }
508
509 // deposit_authorized <source_account> <destination_account>
510 // [<ledger> [<credentials>, ...]]
512 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
514 {
516 jvRequest[jss::source_account] = jvParams[0u].asString();
517 jvRequest[jss::destination_account] = jvParams[1u].asString();
518
519 if (jvParams.size() >= 3)
520 jvParseLedger(jvRequest, jvParams[2u].asString());
521
522 // 8 credentials max
523 if ((jvParams.size() >= 4) && (jvParams.size() <= 11))
524 {
525 jvRequest[jss::credentials] = json::Value(json::ValueType::Array);
526 for (uint32_t i = 3; i < jvParams.size(); ++i)
527 jvRequest[jss::credentials].append(jvParams[i].asString());
528 }
529
530 return jvRequest;
531 }
532
533 // Return an error for attempting to subscribe/unsubscribe via RPC.
535 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
536 parseEvented(json::Value const& jvParams)
537 {
538 return rpcError(RpcNoEvents);
539 }
540
541 // feature [<feature>] [accept|reject]
543 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
544 parseFeature(json::Value const& jvParams)
545 {
547
548 if (jvParams.size() > 0)
549 jvRequest[jss::feature] = jvParams[0u].asString();
550
551 if (jvParams.size() > 1)
552 {
553 auto const action = jvParams[1u].asString();
554
555 // This may look reversed, but it's intentional: jss::vetoed
556 // determines whether an amendment is vetoed - so "reject" means
557 // that jss::vetoed is true.
558 if (boost::iequals(action, "reject"))
559 {
560 jvRequest[jss::vetoed] = json::Value(true);
561 }
562 else if (boost::iequals(action, "accept"))
563 {
564 jvRequest[jss::vetoed] = json::Value(false);
565 }
566 else
567 {
569 }
570 }
571
572 return jvRequest;
573 }
574
575 // get_counts [<min_count>]
577 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
579 {
581
582 if (jvParams.size() != 0u)
583 jvRequest[jss::min_count] = jvParams[0u].asUInt();
584
585 return jvRequest;
586 }
587
588 // sign_for <account> <secret> <json> offline
589 // sign_for <account> <secret> <json>
591 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
592 parseSignFor(json::Value const& jvParams)
593 {
594 bool const bOffline = 4 == jvParams.size() && jvParams[3u].asString() == "offline";
595
596 if (3 == jvParams.size() || bOffline)
597 {
598 json::Value txJSON;
599 json::Reader reader;
600 if (reader.parse(jvParams[2u].asString(), txJSON))
601 {
602 // sign_for txJSON.
604
605 jvRequest[jss::account] = jvParams[0u].asString();
606 jvRequest[jss::secret] = jvParams[1u].asString();
607 jvRequest[jss::tx_json] = txJSON;
608
609 if (bOffline)
610 jvRequest[jss::offline] = true;
611
612 return jvRequest;
613 }
614 }
616 }
617
618 // json <command> <json>
620 parseJson(json::Value const& jvParams)
621 {
622 json::Reader reader;
623 json::Value jvRequest;
624
625 JLOG(j_.trace()) << "RPC method: " << jvParams[0u];
626 JLOG(j_.trace()) << "RPC json: " << jvParams[1u];
627
628 if (reader.parse(jvParams[1u].asString(), jvRequest))
629 {
630 if (!jvRequest.isObjectOrNull())
632
633 jvRequest[jss::method] = jvParams[0u];
634
635 return jvRequest;
636 }
637
639 }
640
651 bool
653 {
654 if (jv.isArray())
655 {
656 if (jv.size() == 0)
657 return false;
658 // json::Value is not a std::ranges range, so the iterator form is used.
659 // NOLINTNEXTLINE(modernize-use-ranges)
660 return std::all_of(
661 jv.begin(), jv.end(), [this](auto const& j) { return isValidJson2(j); });
662 }
663 if (jv.isObject())
664 {
665 if (jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] == rpc::kJsonRpcVersion &&
666 jv.isMember(jss::ripplerpc) && jv[jss::ripplerpc] == rpc::kRippleRpcVersion2 &&
667 jv.isMember(jss::id) && jv.isMember(jss::method))
668 {
669 return !jv.isMember(jss::params) ||
670 (jv[jss::params].isNull() || jv[jss::params].isArray() ||
671 jv[jss::params].isObject());
672 }
673 }
674 return false;
675 }
676
678 parseJson2(json::Value const& jvParams)
679 {
680 json::Reader reader;
681 json::Value jv;
682 bool const validParse = reader.parse(jvParams[0u].asString(), jv);
683 if (validParse && isValidJson2(jv))
684 {
685 if (jv.isObject())
686 {
688 if (jv.isMember(jss::params))
689 {
690 auto const& params = jv[jss::params];
691 for (auto i = params.begin(); i != params.end(); ++i)
692 jv1[i.key().asString()] = *i;
693 }
694 jv1[jss::jsonrpc] = jv[jss::jsonrpc];
695 jv1[jss::ripplerpc] = jv[jss::ripplerpc];
696 jv1[jss::id] = jv[jss::id];
697 jv1[jss::method] = jv[jss::method];
698 return jv1;
699 }
700 // else jv.isArray()
702 for (json::UInt j = 0; j < jv.size(); ++j)
703 {
704 if (jv[j].isMember(jss::params))
705 {
706 auto const& params = jv[j][jss::params];
707 for (auto i = params.begin(); i != params.end(); ++i)
708 jv1[j][i.key().asString()] = *i;
709 }
710 jv1[j][jss::jsonrpc] = jv[j][jss::jsonrpc];
711 jv1[j][jss::ripplerpc] = jv[j][jss::ripplerpc];
712 jv1[j][jss::id] = jv[j][jss::id];
713 jv1[j][jss::method] = jv[j][jss::method];
714 }
715 return jv1;
716 }
717 auto jvError = rpcError(RpcInvalidParams);
718 if (jv.isMember(jss::jsonrpc))
719 jvError[jss::jsonrpc] = jv[jss::jsonrpc];
720 if (jv.isMember(jss::ripplerpc))
721 jvError[jss::ripplerpc] = jv[jss::ripplerpc];
722 if (jv.isMember(jss::id))
723 jvError[jss::id] = jv[jss::id];
724 return jvError;
725 }
726
727 // ledger [id|index|current|closed|validated] [full|tx]
729 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
730 parseLedger(json::Value const& jvParams)
731 {
733
734 if (jvParams.size() == 0u)
735 {
736 return jvRequest;
737 }
738
739 jvParseLedger(jvRequest, jvParams[0u].asString());
740
741 if (2 == jvParams.size())
742 {
743 if (jvParams[1u].asString() == "full")
744 {
745 jvRequest[jss::full] = true;
746 }
747 else if (jvParams[1u].asString() == "tx")
748 {
749 jvRequest[jss::transactions] = true;
750 jvRequest[jss::expand] = true;
751 }
752 }
753
754 return jvRequest;
755 }
756
757 // ledger_header <id>|<index>
759 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
760 parseLedgerId(json::Value const& jvParams)
761 {
763
764 std::string const strLedger = jvParams[0u].asString();
765
766 if (strLedger.length() == 64)
767 {
768 jvRequest[jss::ledger_hash] = strLedger;
769 }
770 else
771 {
772 jvRequest[jss::ledger_index] = beast::lexicalCast<std::uint32_t>(strLedger);
773 }
774
775 return jvRequest;
776 }
777
778 // ledger_entry [id] [<index>]
780 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
782 {
784
785 jvRequest[jss::index] = jvParams[0u].asString();
786
787 if (jvParams.size() == 2 && !jvParseLedger(jvRequest, jvParams[1u].asString()))
789
790 return jvRequest;
791 }
792
793 // log_level: Get log levels
794 // log_level <severity>: Set master log level to the
795 // specified severity log_level <partition> <severity>: Set specified
796 // partition to specified severity
798 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
799 parseLogLevel(json::Value const& jvParams)
800 {
802
803 if (jvParams.size() == 1)
804 {
805 jvRequest[jss::severity] = jvParams[0u].asString();
806 }
807 else if (jvParams.size() == 2)
808 {
809 jvRequest[jss::partition] = jvParams[0u].asString();
810 jvRequest[jss::severity] = jvParams[1u].asString();
811 }
812
813 return jvRequest;
814 }
815
816 // owner_info <account>
817 // account_info <account> [<ledger>]
818 // account_offers <account> [<ledger>]
821 {
822 return parseAccountRaw1(jvParams);
823 }
824
827 {
828 return parseAccountRaw1(jvParams);
829 }
830
831 // account_lines <account> <account>|"" [<ledger>]
834 {
835 return parseAccountRaw2(jvParams, jss::peer);
836 }
837
838 // account_channels <account> <account>|"" [<ledger>]
841 {
842 return parseAccountRaw2(jvParams, jss::destination_account);
843 }
844
845 // channel_authorize: <private_key> [<key_type>] <channel_id> <drops>
847 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
849 {
851
852 unsigned int index = 0;
853
854 if (jvParams.size() == 4)
855 {
856 jvRequest[jss::passphrase] = jvParams[index];
857 index++;
858
859 if (!keyTypeFromString(jvParams[index].asString()))
860 return rpcError(RpcBadKeyType);
861 jvRequest[jss::key_type] = jvParams[index];
862 index++;
863 }
864 else
865 {
866 jvRequest[jss::secret] = jvParams[index];
867 index++;
868 }
869
870 {
871 // verify the channel id is a valid 256 bit number
872 UInt256 channelId;
873 if (!channelId.parseHex(jvParams[index].asString()))
875 jvRequest[jss::channel_id] = to_string(channelId);
876 index++;
877 }
878
879 if (!jvParams[index].isString() || !toUInt64(jvParams[index].asString()))
881 jvRequest[jss::amount] = jvParams[index];
882
883 // If additional parameters are appended, be sure to increment index
884 // here
885
886 return jvRequest;
887 }
888
889 // channel_verify <public_key> <channel_id> <drops> <signature>
891 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
893 {
894 std::string const strPk = jvParams[0u].asString();
895
896 if (!validPublicKey(strPk))
898
900
901 jvRequest[jss::public_key] = strPk;
902 {
903 // verify the channel id is a valid 256 bit number
904 UInt256 channelId;
905 if (!channelId.parseHex(jvParams[1u].asString()))
907 }
908 jvRequest[jss::channel_id] = jvParams[1u].asString();
909
910 if (!jvParams[2u].isString() || !toUInt64(jvParams[2u].asString()))
912 jvRequest[jss::amount] = jvParams[2u];
913
914 jvRequest[jss::signature] = jvParams[3u].asString();
915
916 return jvRequest;
917 }
918
920 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
921 parseAccountRaw2(json::Value const& jvParams, char const* const acc2Field)
922 {
923 std::array<char const* const, 2> accFields{{jss::account, acc2Field}};
924 auto const nParams = jvParams.size();
926 for (auto i = 0; i < nParams; ++i)
927 {
928 // This was non-const. see comment below
929 std::string const strParam = jvParams[i].asString();
930
931 if (i == 1 && strParam.empty())
932 continue;
933
934 // Parameters 0 and 1 are accounts
935 if (i < 2)
936 {
937 if (parseBase58<AccountID>(strParam))
938 {
939 // TODO: this was std::move'd before but it does not work in practice.
940 // We would need a Value(std::string&&) for it to work.
941 // See https://github.com/XRPLF/rippled/issues/6677
942 jvRequest[accFields[i]] = strParam;
943 }
944 else
945 {
947 }
948 }
949 else
950 {
951 if (jvParseLedger(jvRequest, strParam))
952 return jvRequest;
954 }
955 }
956
957 return jvRequest;
958 }
959
960 // TODO: Get index from an alternate syntax: rXYZ:<index>
962 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
964 {
965 std::string const strIdent = jvParams[0u].asString();
966 unsigned int const iCursor = jvParams.size();
967
968 if (!parseBase58<AccountID>(strIdent))
970
971 // Get info on account.
973
974 jvRequest[jss::account] = strIdent;
975
976 if (iCursor == 2 && !jvParseLedger(jvRequest, jvParams[1u].asString()))
978
979 return jvRequest;
980 }
981
983 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
984 parseVault(json::Value const& jvParams)
985 {
986 std::string const strVaultID = jvParams[0u].asString();
988 if (!id.parseHex(strVaultID))
990
992 jvRequest[jss::vault_id] = strVaultID;
993
994 if (jvParams.size() > 1)
995 jvParseLedger(jvRequest, jvParams[1u].asString());
996
997 return jvRequest;
998 }
999
1000 // peer_reservations_add <public_key> [<name>]
1002 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1004 {
1005 json::Value jvRequest;
1006 jvRequest[jss::public_key] = jvParams[0u].asString();
1007 if (jvParams.size() > 1)
1008 {
1009 jvRequest[jss::description] = jvParams[1u].asString();
1010 }
1011 return jvRequest;
1012 }
1013
1014 // peer_reservations_del <public_key>
1016 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1018 {
1019 json::Value jvRequest;
1020 jvRequest[jss::public_key] = jvParams[0u].asString();
1021 return jvRequest;
1022 }
1023
1024 // ripple_path_find <json> [<ledger>]
1027 {
1028 json::Reader reader;
1030 bool const bLedger = 2 == jvParams.size();
1031
1032 JLOG(j_.trace()) << "RPC json: " << jvParams[0u];
1033
1034 if (reader.parse(jvParams[0u].asString(), jvRequest))
1035 {
1036 if (bLedger)
1037 {
1038 jvParseLedger(jvRequest, jvParams[1u].asString());
1039 }
1040
1041 return jvRequest;
1042 }
1043
1044 return rpcError(RpcInvalidParams);
1045 }
1046
1047 // simulate any transaction on the network
1048 //
1049 // simulate <tx_blob> [binary]
1050 // simulate <tx_json> [binary]
1052 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1054 {
1055 json::Value txJSON;
1056 json::Reader reader;
1058
1059 if (reader.parse(jvParams[0u].asString(), txJSON))
1060 {
1061 jvRequest[jss::tx_json] = txJSON;
1062 }
1063 else
1064 {
1065 jvRequest[jss::tx_blob] = jvParams[0u].asString();
1066 }
1067
1068 if (jvParams.size() == 2)
1069 {
1070 if (!jvParams[1u].isString() || jvParams[1u].asString() != "binary")
1071 return rpcError(RpcInvalidParams);
1072 jvRequest[jss::binary] = true;
1073 }
1074
1075 return jvRequest;
1076 }
1077
1078 // sign/submit any transaction to the network
1079 //
1080 // sign <private_key> <json> offline
1081 // submit <private_key> <json>
1082 // submit <tx_blob>
1084 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1086 {
1087 json::Value txJSON;
1088 json::Reader reader;
1089 bool const bOffline = jvParams.size() >= 3 && jvParams[2u].asString() == "offline";
1090 std::optional<std::string> const field = [&jvParams,
1091 bOffline] -> std::optional<std::string> {
1092 if (jvParams.size() < 3)
1093 return std::nullopt;
1094 if (jvParams.size() < 4 && bOffline)
1095 return std::nullopt;
1096 json::UInt const index = bOffline ? 3u : 2u;
1097 return jvParams[index].asString();
1098 }();
1099
1100 if (1 == jvParams.size())
1101 {
1102 // Submitting tx_blob
1103
1105
1106 jvRequest[jss::tx_blob] = jvParams[0u].asString();
1107
1108 return jvRequest;
1109 }
1110 if ((jvParams.size() >= 2 || bOffline) && reader.parse(jvParams[1u].asString(), txJSON))
1111 {
1112 // Signing or submitting tx_json.
1114
1115 jvRequest[jss::secret] = jvParams[0u].asString();
1116 jvRequest[jss::tx_json] = txJSON;
1117
1118 if (bOffline)
1119 jvRequest[jss::offline] = true;
1120
1121 if (field)
1122 jvRequest[jss::signature_target] = *field;
1123
1124 return jvRequest;
1125 }
1126
1127 return rpcError(RpcInvalidParams);
1128 }
1129
1130 // submit any multisigned transaction to the network
1131 //
1132 // submit_multisigned <json>
1134 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1136 {
1137 if (1 == jvParams.size())
1138 {
1139 json::Value txJSON;
1140 json::Reader reader;
1141 if (reader.parse(jvParams[0u].asString(), txJSON))
1142 {
1144 jvRequest[jss::tx_json] = txJSON;
1145 return jvRequest;
1146 }
1147 }
1148
1149 return rpcError(RpcInvalidParams);
1150 }
1151
1152 // transaction_entry <tx_hash> <ledger_hash/ledger_index>
1154 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1156 {
1157 // Parameter count should have already been verified.
1158 XRPL_ASSERT(
1159 jvParams.size() == 2, "xrpl::RPCParser::parseTransactionEntry : valid parameter count");
1160
1161 std::string const txHash = jvParams[0u].asString();
1162 if (txHash.length() != 64)
1163 return rpcError(RpcInvalidParams);
1164
1166 jvRequest[jss::tx_hash] = txHash;
1167
1168 jvParseLedger(jvRequest, jvParams[1u].asString());
1169
1170 // jvParseLedger inserts a "ledger_index" of 0 if it doesn't
1171 // find a match.
1172 if (jvRequest.isMember(jss::ledger_index) && jvRequest[jss::ledger_index] == 0)
1173 return rpcError(RpcInvalidParams);
1174
1175 return jvRequest;
1176 }
1177
1178 // tx <transaction_id>
1180 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1181 parseTx(json::Value const& jvParams)
1182 {
1184
1185 if (jvParams.size() == 2 || jvParams.size() == 4)
1186 {
1187 if (jvParams[1u].asString() == jss::binary)
1188 jvRequest[jss::binary] = true;
1189 }
1190
1191 if (jvParams.size() >= 3)
1192 {
1193 auto const offset = jvParams.size() == 3 ? 0 : 1;
1194
1195 jvRequest[jss::min_ledger] = jvParams[1u + offset].asString();
1196 jvRequest[jss::max_ledger] = jvParams[2u + offset].asString();
1197 }
1198
1199 if (jvParams[0u].asString().length() == 16)
1200 {
1201 jvRequest[jss::ctid] = jvParams[0u].asString();
1202 }
1203 else
1204 {
1205 jvRequest[jss::transaction] = jvParams[0u].asString();
1206 }
1207
1208 return jvRequest;
1209 }
1210
1211 // tx_history <index>
1213 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1215 {
1217
1218 jvRequest[jss::start] = jvParams[0u].asUInt();
1219
1220 return jvRequest;
1221 }
1222
1223 // validation_create [<pass_phrase>|<seed>|<seed_key>]
1224 //
1225 // NOTE: It is poor security to specify secret information on the command
1226 // line. This information might be saved in the command shell history file
1227 // (e.g. .bash_history) and it may be leaked via the process status command
1228 // (i.e. ps).
1230 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1232 {
1234
1235 if (jvParams.size() != 0u)
1236 jvRequest[jss::secret] = jvParams[0u].asString();
1237
1238 return jvRequest;
1239 }
1240
1241 // wallet_propose [<passphrase>]
1242 // <passphrase> is only for testing. Master seeds should only be generated
1243 // randomly.
1245 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1247 {
1249
1250 if (jvParams.size() != 0u)
1251 jvRequest[jss::passphrase] = jvParams[0u].asString();
1252
1253 return jvRequest;
1254 }
1255
1256 // parse gateway balances
1257 // gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ <hotwallet>
1258 // ]]
1259
1261 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1263 {
1264 unsigned int index = 0;
1265 unsigned int const size = jvParams.size();
1266
1268
1269 std::string param = jvParams[index++].asString();
1270 if (param.empty())
1271 return rpc::makeParamError("Invalid first parameter");
1272
1273 if (param[0] != 'r')
1274 {
1275 if (param.size() == 64)
1276 {
1277 jvRequest[jss::ledger_hash] = param;
1278 }
1279 else
1280 {
1281 jvRequest[jss::ledger_index] = param;
1282 }
1283
1284 if (size <= index)
1285 return rpc::makeParamError("Invalid hotwallet");
1286
1287 param = jvParams[index++].asString();
1288 }
1289
1290 jvRequest[jss::account] = param;
1291
1292 if (index < size)
1293 {
1294 json::Value& hotWallets = (jvRequest["hotwallet"] = json::ValueType::Array);
1295 while (index < size)
1296 hotWallets.append(jvParams[index++].asString());
1297 }
1298
1299 return jvRequest;
1300 }
1301
1302 // server_definitions [hash]
1304 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1306 {
1308
1309 if (jvParams.size() == 1)
1310 {
1311 jvRequest[jss::hash] = jvParams[0u].asString();
1312 }
1313
1314 return jvRequest;
1315 }
1316
1317 // server_info [counters]
1319 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1321 {
1323 if (jvParams.size() == 1 && jvParams[0u].asString() == "counters")
1324 jvRequest[jss::counters] = true;
1325 return jvRequest;
1326 }
1327
1328 // An omitted minParams means the command takes no arguments; an omitted
1329 // maxParams means it takes any number. See Command.
1330 //
1331 // The commands. The order is free: parseCommand() searches kSortedCommands
1332 // below.
1333 static constexpr auto kCommandArray = std::to_array<Command>({
1334 // Request-response methods
1335 // - Returns an error, or the request.
1336 // - To modify the method, provide a new method in the request.
1337 {
1339 .parse = Parse::of<&RPCParser::parseAccountCurrencies>(),
1340 .minParams = 1,
1341 .maxParams = 3,
1342 },
1343 {
1345 .parse = Parse::of<&RPCParser::parseAccountItems>(),
1346 .minParams = 1,
1347 .maxParams = 3,
1348 },
1349 {
1351 .parse = Parse::of<&RPCParser::parseAccountLines>(),
1352 .minParams = 1,
1353 .maxParams = 5,
1354 },
1355 {
1357 .parse = Parse::of<&RPCParser::parseAccountChannels>(),
1358 .minParams = 1,
1359 .maxParams = 3,
1360 },
1361 {
1363 .parse = Parse::of<&RPCParser::parseAccountItems>(),
1364 .minParams = 1,
1365 .maxParams = 5,
1366 },
1367 {
1369 .parse = Parse::of<&RPCParser::parseAccountItems>(),
1370 .minParams = 1,
1371 .maxParams = 5,
1372 },
1373 {
1375 .parse = Parse::of<&RPCParser::parseAccountItems>(),
1376 .minParams = 1,
1377 .maxParams = 4,
1378 },
1379 {
1381 .parse = Parse::of<&RPCParser::parseAccountTransactions>(),
1382 .minParams = 1,
1383 .maxParams = 8,
1384 },
1385 {
1386 .name = rpc::method::kAmmInfo,
1387 .parse = Parse::of<&RPCParser::parseAsIs>(),
1388 .minParams = 1,
1389 .maxParams = 2,
1390 },
1391 {
1393 .parse = Parse::of<&RPCParser::parseVault>(),
1394 .minParams = 1,
1395 .maxParams = 2,
1396 },
1397 {
1399 .parse = Parse::of<&RPCParser::parseLedgerId>(),
1400 .minParams = 1,
1401 .maxParams = 1,
1402 },
1403 {
1405 .parse = Parse::of<&RPCParser::parseBookOffers>(),
1406 .minParams = 2,
1407 .maxParams = 7,
1408 },
1409 {
1411 .parse = Parse::of<&RPCParser::parseCanDelete>(),
1412 .maxParams = 1,
1413 },
1414 {
1416 .parse = Parse::of<&RPCParser::parseChannelAuthorize>(),
1417 .minParams = 3,
1418 .maxParams = 4,
1419 },
1420 {
1422 .parse = Parse::of<&RPCParser::parseChannelVerify>(),
1423 .minParams = 4,
1424 .maxParams = 4,
1425 },
1426 {
1427 .name = rpc::method::kConnect,
1428 .parse = Parse::of<&RPCParser::parseConnect>(),
1429 .minParams = 1,
1430 .maxParams = 2,
1431 },
1432 {
1434 .parse = Parse::of<&RPCParser::parseAsIs>(),
1435 .maxParams = 0,
1436 },
1437 {
1439 .parse = Parse::of<&RPCParser::parseDepositAuthorized>(),
1440 .minParams = 2,
1441 .maxParams = 11,
1442 },
1443 {
1444 .name = rpc::method::kFeature,
1445 .parse = Parse::of<&RPCParser::parseFeature>(),
1446 .maxParams = 2,
1447 },
1448 {
1450 .parse = Parse::of<&RPCParser::parseFetchInfo>(),
1451 .maxParams = 1,
1452 },
1453 {
1455 .parse = Parse::of<&RPCParser::parseGatewayBalances>(),
1456 .minParams = 1,
1457 },
1458 {
1460 .parse = Parse::of<&RPCParser::parseGetCounts>(),
1461 .maxParams = 1,
1462 },
1463 {
1464 .name = rpc::method::kJson,
1465 .parse = Parse::of<&RPCParser::parseJson>(),
1466 .minParams = 2,
1467 .maxParams = 2,
1468 },
1469 {
1470 .name = rpc::method::kJson2,
1471 .parse = Parse::of<&RPCParser::parseJson2>(),
1472 .minParams = 1,
1473 .maxParams = 1,
1474 },
1475 {
1476 .name = rpc::method::kLedger,
1477 .parse = Parse::of<&RPCParser::parseLedger>(),
1478 .maxParams = 2,
1479 },
1480 {
1482 .parse = Parse::of<&RPCParser::parseAsIs>(),
1483 .maxParams = 0,
1484 },
1485 {
1487 .parse = Parse::of<&RPCParser::parseAsIs>(),
1488 .maxParams = 0,
1489 },
1490 {
1492 .parse = Parse::of<&RPCParser::parseAsIs>(),
1493 .maxParams = 0,
1494 },
1495 {
1497 .parse = Parse::of<&RPCParser::parseLedgerEntry>(),
1498 .minParams = 1,
1499 .maxParams = 2,
1500 },
1501 {
1503 .parse = Parse::of<&RPCParser::parseLedgerId>(),
1504 .minParams = 1,
1505 .maxParams = 1,
1506 },
1507 {
1509 .parse = Parse::of<&RPCParser::parseLedgerId>(),
1510 .minParams = 1,
1511 .maxParams = 1,
1512 },
1513 {
1514 .name = rpc::method::kLogLevel,
1515 .parse = Parse::of<&RPCParser::parseLogLevel>(),
1516 .maxParams = 2,
1517 },
1518 {
1520 .parse = Parse::of<&RPCParser::parseAsIs>(),
1521 .maxParams = 0,
1522 },
1523 {
1524 .name = rpc::method::kManifest,
1525 .parse = Parse::of<&RPCParser::parseManifest>(),
1526 .minParams = 1,
1527 .maxParams = 1,
1528 },
1529 {
1531 .parse = Parse::of<&RPCParser::parseAccountItems>(),
1532 .minParams = 1,
1533 .maxParams = 3,
1534 },
1535 {
1536 .name = rpc::method::kPeers,
1537 .parse = Parse::of<&RPCParser::parseAsIs>(),
1538 .maxParams = 0,
1539 },
1540 {
1541 .name = rpc::method::kPing,
1542 .parse = Parse::of<&RPCParser::parseAsIs>(),
1543 .maxParams = 0,
1544 },
1545 {
1546 .name = rpc::method::kPrint,
1547 .parse = Parse::of<&RPCParser::parseAsIs>(),
1548 .maxParams = 1,
1549 },
1550 {
1551 .name = rpc::method::kRandom,
1552 .parse = Parse::of<&RPCParser::parseAsIs>(),
1553 .maxParams = 0,
1554 },
1555 {
1557 .parse = Parse::of<&RPCParser::parsePeerReservationsAdd>(),
1558 .minParams = 1,
1559 .maxParams = 2,
1560 },
1561 {
1563 .parse = Parse::of<&RPCParser::parsePeerReservationsDel>(),
1564 .minParams = 1,
1565 .maxParams = 1,
1566 },
1567 {
1569 .parse = Parse::of<&RPCParser::parseAsIs>(),
1570 .maxParams = 0,
1571 },
1572 {
1574 .parse = Parse::of<&RPCParser::parseRipplePathFind>(),
1575 .minParams = 1,
1576 .maxParams = 2,
1577 },
1578 {
1580 .parse = Parse::of<&RPCParser::parseServerDefinitions>(),
1581 .maxParams = 1,
1582 },
1583 {
1585 .parse = Parse::of<&RPCParser::parseServerInfo>(),
1586 .maxParams = 1,
1587 },
1588 {
1590 .parse = Parse::of<&RPCParser::parseServerInfo>(),
1591 .maxParams = 1,
1592 },
1593 {
1594 .name = rpc::method::kSign,
1595 .parse = Parse::of<&RPCParser::parseSignSubmit>(),
1596 .minParams = 2,
1597 .maxParams = 4,
1598 },
1599 {
1600 .name = rpc::method::kSignFor,
1601 .parse = Parse::of<&RPCParser::parseSignFor>(),
1602 .minParams = 3,
1603 .maxParams = 4,
1604 },
1605 {
1606 .name = rpc::method::kStop,
1607 .parse = Parse::of<&RPCParser::parseAsIs>(),
1608 .maxParams = 0,
1609 },
1610 {
1611 .name = rpc::method::kSimulate,
1612 .parse = Parse::of<&RPCParser::parseSimulate>(),
1613 .minParams = 1,
1614 .maxParams = 2,
1615 },
1616 {
1617 .name = rpc::method::kSubmit,
1618 .parse = Parse::of<&RPCParser::parseSignSubmit>(),
1619 .minParams = 1,
1620 .maxParams = 4,
1621 },
1622 {
1624 .parse = Parse::of<&RPCParser::parseSubmitMultiSigned>(),
1625 .minParams = 1,
1626 .maxParams = 1,
1627 },
1628 {
1630 .parse = Parse::of<&RPCParser::parseTransactionEntry>(),
1631 .minParams = 2,
1632 .maxParams = 2,
1633 },
1634 {
1635 .name = rpc::method::kTx,
1636 .parse = Parse::of<&RPCParser::parseTx>(),
1637 .minParams = 1,
1638 .maxParams = 4,
1639 },
1640 {
1642 .parse = Parse::of<&RPCParser::parseTxHistory>(),
1643 .minParams = 1,
1644 .maxParams = 1,
1645 },
1646 {
1647 .name = rpc::method::kUnlList,
1648 .parse = Parse::of<&RPCParser::parseAsIs>(),
1649 .maxParams = 0,
1650 },
1651 {
1653 .parse = Parse::of<&RPCParser::parseValidationCreate>(),
1654 .maxParams = 1,
1655 },
1656 {
1658 .parse = Parse::of<&RPCParser::parseAsIs>(),
1659 .maxParams = 0,
1660 },
1661 {
1662 .name = rpc::method::kVersion,
1663 .parse = Parse::of<&RPCParser::parseAsIs>(),
1664 .maxParams = 0,
1665 },
1666 {
1668 .parse = Parse::of<&RPCParser::parseWalletPropose>(),
1669 .maxParams = 1,
1670 },
1671 {
1672 .name = rpc::method::kInternal,
1673 .parse = Parse::of<&RPCParser::parseInternal>(),
1674 .minParams = 1,
1675 },
1676
1677 // Event methods, rejected below, so the parameter range is unconstrained
1678 {
1679 .name = rpc::method::kPathFind,
1680 .parse = Parse::of<&RPCParser::parseEvented>(),
1681 },
1682 {
1684 .parse = Parse::of<&RPCParser::parseEvented>(),
1685 },
1686 {
1688 .parse = Parse::of<&RPCParser::parseEvented>(),
1689 },
1690 });
1691
1692 // kCommandArray sorted by name, so a command can be found by binary search.
1693 static constexpr auto kSortedCommands = [] {
1694 auto commands = kCommandArray;
1695 std::ranges::sort(commands, {}, &Command::name);
1696 return commands;
1697 }();
1698
1699 // parseCommand() relies on this being sorted to binary search it, and
1700 // kCommandNames below inherits the order.
1701 static_assert(
1702 std::ranges::is_sorted(kSortedCommands, {}, &Command::name),
1703 "xrpl::RPCParser : kSortedCommands must be sorted");
1704
1705 // The command names, which are already distinct and sorted.
1706 static constexpr auto kCommandNames = [] {
1708 std::ranges::transform(kSortedCommands, names.begin(), &Command::name);
1709 return names;
1710 }();
1711
1712public:
1718 {
1719 return kCommandNames;
1720 }
1721
1737 static constexpr bool
1739 {
1740 for (std::size_t i = 0; i < kSortedCommands.size(); ++i)
1741 {
1742 auto const& command = kSortedCommands[i];
1743 if (command.name.empty() || command.minParams > command.maxParams)
1744 return false;
1745 if (i > 0 && kSortedCommands[i - 1].name == command.name)
1746 return false;
1747 }
1748 return true;
1749 }
1750
1751 //--------------------------------------------------------------------------
1752
1753 explicit RPCParser(unsigned apiVersion, beast::Journal j) : apiVersion_(apiVersion), j_(j)
1754 {
1755 }
1756
1757 //--------------------------------------------------------------------------
1758
1759 // Convert a rpc method and params to a request.
1760 // <-- { method: xyz, params: [... ] } or { error: ..., ... }
1762 parseCommand(std::string_view strMethod, json::Value const& jvParams, bool allowAnyCommand)
1763 {
1764 if (auto const stream = j_.trace())
1765 {
1766 stream << "Method: '" << strMethod << "'";
1767 stream << "Params: " << jvParams;
1768 }
1769
1770 auto const found = std::ranges::lower_bound(kSortedCommands, strMethod, {}, &Command::name);
1771
1772 if (found == kSortedCommands.end() || found->name != strMethod)
1773 {
1774 // The command could not be found
1775 if (!allowAnyCommand)
1777
1778 return parseAsIs(jvParams);
1779 }
1780
1781 auto const count = jvParams.size();
1782 if (count < found->minParams || count > found->maxParams)
1783 {
1784 JLOG(j_.debug()) << "Wrong number of parameters for " << found->name
1785 << " minimum=" << found->minParams << " maximum=" << found->maxParams
1786 << " actual=" << count;
1787
1788 return rpcError(RpcBadSyntax);
1789 }
1790
1791 return found->parse(*this, jvParams);
1792 }
1793};
1794
1795namespace {
1796
1797// Out of line because RPCParser is incomplete where Parse is declared.
1799Parse::operator()(RPCParser& parser, json::Value const& jvParams) const
1800{
1801 return (parser.*fn_)(jvParams);
1802}
1803
1804} // namespace
1805
1806// See the comment on commandsValid() for why this is out here.
1807static_assert(
1809 "xrpl::RPCParser : every command needs a unique name and a valid parameter "
1810 "count range");
1811
1812//------------------------------------------------------------------------------
1813
1814//
1815// JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility,
1816// but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
1817// unspecified (HTTP errors and contents of 'error').
1818//
1819// 1.0 spec: http://json-rpc.org/wiki/specification
1820// 1.2 spec: http://groups.google.com/group/json-rpc/web/json-rpc-over-http
1821//
1822
1823std::string
1824jsonrpcRequest(std::string const& strMethod, json::Value const& params, json::Value const& id)
1825{
1826 json::Value request;
1827 request[jss::method] = strMethod;
1828 request[jss::params] = params;
1829 request[jss::id] = id;
1830 return to_string(request) + "\n";
1831}
1832
1833namespace {
1834// Special local exception type thrown when request can't be parsed.
1835class RequestNotParsable : public std::runtime_error
1836{
1837 using std::runtime_error::runtime_error; // Inherit constructors
1838};
1839}; // namespace
1840
1842{
1843 explicit RPCCallImp() = default;
1844
1845 // VFALCO NOTE Is this a to-do comment or a doc comment?
1846 // Place the async result somewhere useful.
1847 static void
1848 callRPCHandler(json::Value* jvOutput, json::Value const& jvInput)
1849 {
1850 (*jvOutput) = jvInput;
1851 }
1852
1853 static bool
1855 std::function<void(json::Value const& jvInput)> callbackFuncP,
1856 boost::system::error_code const& ecResult,
1857 int iStatus,
1858 std::string const& strData,
1860 {
1861 if (callbackFuncP)
1862 {
1863 // Only care about the result, if we care to deliver it
1864 // callbackFuncP.
1865
1866 // Receive reply
1867 if (strData.empty())
1868 {
1870 "no response from server. Please "
1871 "ensure that the xrpld server is running in another "
1872 "process.");
1873 }
1874
1875 // Parse reply
1876 JLOG(j.debug()) << "RPC reply: " << strData << std::endl;
1877 if (strData.starts_with("Unable to parse request") ||
1878 strData.starts_with(jss::invalid_API_version.cStr()))
1880 json::Reader reader;
1881 json::Value jvReply;
1882 if (!reader.parse(strData, jvReply))
1883 Throw<std::runtime_error>("couldn't parse reply from server");
1884
1885 if (!jvReply)
1886 Throw<std::runtime_error>("expected reply to have result, error and id properties");
1887
1889
1890 jvResult["result"] = jvReply;
1891
1892 callbackFuncP(jvResult);
1893 }
1894
1895 return false;
1896 }
1897
1898 // Build the request.
1899 static void
1901 std::string const& strMethod,
1902 json::Value const& jvParams,
1904 std::string const& strPath,
1905 boost::asio::streambuf& sb,
1906 std::string const& strHost,
1908 {
1909 JLOG(j.debug()) << "requestRPC: strPath='" << strPath << "'";
1910
1911 std::ostream osRequest(&sb);
1912 osRequest << createHTTPPost(
1913 strHost, strPath, jsonrpcRequest(strMethod, jvParams, json::Value(1)), headers);
1914 }
1915};
1916
1917//------------------------------------------------------------------------------
1918
1924
1925// Used internally by rpcClient.
1928 std::vector<std::string> const& args,
1929 json::Value& retParams,
1930 unsigned int apiVersion,
1932{
1934
1935 RPCParser rpParser(apiVersion, j);
1937
1938 for (int i = 1; i != args.size(); i++)
1939 jvRpcParams.append(args[i]);
1940
1942
1943 retParams[jss::method] = args[0];
1944 retParams[jss::params] = jvRpcParams;
1945
1946 jvRequest = rpParser.parseCommand(args[0], jvRpcParams, true);
1947
1948 auto const insertApiVersion = [apiVersion](json::Value& jr) {
1949 if (jr.isObject() && !jr.isMember(jss::error) && !jr.isMember(jss::api_version))
1950 {
1951 jr[jss::api_version] = apiVersion;
1952 }
1953 };
1954
1955 if (jvRequest.isObject())
1956 {
1957 insertApiVersion(jvRequest);
1958 }
1959 else if (jvRequest.isArray())
1960 {
1961 // NOLINTNEXTLINE(modernize-use-ranges)
1962 std::for_each(jvRequest.begin(), jvRequest.end(), insertApiVersion);
1963 }
1964
1965 JLOG(j.trace()) << "RPC Request: " << jvRequest << std::endl;
1966 return jvRequest;
1967}
1968
1969//------------------------------------------------------------------------------
1970
1973 std::vector<std::string> const& args,
1974 Config const& config,
1975 Logs& logs,
1976 unsigned int apiVersion,
1978{
1979 static_assert(RpcBadSyntax == 1 && RpcSuccess == 0, "Expect specific rpc enum values.");
1980 if (args.empty())
1981 return {RpcBadSyntax, {}}; // rpcBAD_SYNTAX = print usage
1982
1983 int nRet = RpcSuccess;
1984 json::Value jvOutput;
1986
1987 try
1988 {
1990 jvRequest = rpcCmdToJson(args, jvRpc, apiVersion, logs.journal("RPCParser"));
1991
1992 if (jvRequest.isMember(jss::error))
1993 {
1994 jvOutput = jvRequest;
1995 jvOutput["rpc"] = jvRpc;
1996 }
1997 else
1998 {
2000 try
2001 {
2002 beast::LogStream rpcCallLog{logs.journal("HTTPClient").warn()};
2003 setup = setupServerHandler(config, rpcCallLog);
2004 }
2005 catch (std::exception const&) // NOLINT(bugprone-empty-catch)
2006 {
2007 // ignore any exceptions, so the command
2008 // line client works without a config file
2009 }
2010
2011 if (config.rpcIp)
2012 {
2013 setup.client.ip = config.rpcIp->address().to_string();
2014 setup.client.port = config.rpcIp->port();
2015 }
2016
2018
2019 if (!setup.client.adminUser.empty())
2020 jvRequest["admin_user"] = setup.client.adminUser;
2021
2022 if (!setup.client.adminPassword.empty())
2023 jvRequest["admin_password"] = setup.client.adminPassword;
2024
2025 if (jvRequest.isObject())
2026 {
2027 jvParams.append(jvRequest);
2028 }
2029 else if (jvRequest.isArray())
2030 {
2031 for (json::UInt i = 0; i < jvRequest.size(); ++i)
2032 jvParams.append(jvRequest[i]);
2033 }
2034
2035 {
2036 boost::asio::io_context isService;
2038 isService,
2039 setup.client.ip,
2040 setup.client.port,
2041 setup.client.user,
2042 setup.client.password,
2043 "",
2044 // Allow parser to rewrite method.
2045 [&] -> std::string {
2046 if (jvRequest.isMember(jss::method))
2047 return jvRequest[jss::method].asString();
2048 return jvRequest.isArray() ? "batch" : args[0];
2049 }(),
2050 jvParams, // Parsed, execute.
2051 static_cast<int>(setup.client.secure) != 0, // Use SSL
2052 config.quiet(),
2053 logs,
2054 [&jvOutput](json::Value const& jvInput) {
2055 RPCCallImp::callRPCHandler(&jvOutput, jvInput);
2056 },
2057 headers);
2058 isService.run(); // This blocks until there are no more
2059 // outstanding async calls.
2060 }
2061 if (jvOutput.isMember("result"))
2062 {
2063 // Had a successful JSON-RPC 2.0 call.
2064 jvOutput = jvOutput["result"];
2065
2066 // jvOutput may report a server side error.
2067 // It should report "status".
2068 }
2069 else
2070 {
2071 // Transport error.
2072 json::Value const jvRpcError = jvOutput;
2073
2074 jvOutput = rpcError(RpcJsonRpc);
2075 jvOutput["result"] = jvRpcError;
2076 }
2077
2078 // If had an error, supply invocation in result.
2079 if (jvOutput.isMember(jss::error))
2080 {
2081 jvOutput["rpc"] = jvRpc; // How the command was seen as method + params.
2082 jvOutput["request_sent"] = jvRequest; // How the command was translated.
2083 }
2084 }
2085
2086 if (jvOutput.isMember(jss::error))
2087 {
2088 jvOutput[jss::status] = "error";
2089 if (jvOutput.isMember(jss::error_code))
2090 {
2091 nRet = std::stoi(jvOutput[jss::error_code].asString());
2092 }
2093 else if (jvOutput[jss::error].isMember(jss::error_code))
2094 {
2095 nRet = std::stoi(jvOutput[jss::error][jss::error_code].asString());
2096 }
2097 else
2098 {
2099 nRet = RpcBadSyntax;
2100 }
2101 }
2102
2103 // YYY We could have a command line flag for single line output for
2104 // scripts. YYY We would intercept output here and simplify it.
2105 }
2106 catch (RequestNotParsable const& e)
2107 {
2108 jvOutput = rpcError(RpcInvalidParams);
2109 jvOutput["error_what"] = e.what();
2110 nRet = RpcInvalidParams;
2111 }
2112 catch (std::exception& e)
2113 {
2114 jvOutput = rpcError(RpcInternal);
2115 jvOutput["error_what"] = e.what();
2116 nRet = RpcInternal;
2117 }
2118
2119 return {nRet, std::move(jvOutput)};
2120}
2121
2122//------------------------------------------------------------------------------
2123
2124namespace rpc_call {
2125
2126int
2127fromCommandLine(Config const& config, std::vector<std::string> const& vCmd, Logs& logs)
2128{
2129 auto const result = rpcClient(vCmd, config, logs, rpc::kApiCommandLineVersion);
2130
2131 std::cout << result.second.toStyledString();
2132
2133 return result.first;
2134}
2135
2136//------------------------------------------------------------------------------
2137
2138void
2140 boost::asio::io_context& ioContext,
2141 std::string const& strIp,
2142 std::uint16_t const iPort,
2143 std::string const& strUsername,
2144 std::string const& strPassword,
2145 std::string const& strPath,
2146 std::string const& strMethod,
2147 json::Value const& jvParams,
2148 bool const bSSL,
2149 bool const quiet,
2150 Logs& logs,
2151 std::function<void(json::Value const& jvInput)> callbackFuncP,
2153{
2154 auto const j = logs.journal("HTTPClient");
2155
2156 // Connect to localhost
2157 if (!quiet)
2158 {
2159 JLOG(j.info()) << (bSSL ? "Securely connecting to " : "Connecting to ") << strIp << ":"
2160 << iPort << std::endl;
2161 }
2162
2163 // HTTP basic authentication
2164 headers["Authorization"] =
2165 std::string("Basic ") + base64Encode(strUsername + ":" + strPassword);
2166
2167 // Send request
2168
2169 // Number of bytes to try to receive if no
2170 // Content-Length header received
2171 constexpr auto kRpcReplyMaxBytes = megabytes(256);
2172
2173 using namespace std::chrono_literals;
2174 static constexpr auto kRpcWebhookTimeout = 30s;
2175
2177 bSSL,
2178 ioContext,
2179 strIp,
2180 iPort,
2181 [strMethod, jvParams, headers, strPath, j](
2182 boost::asio::streambuf& sb, std::string const& strHost) {
2183 RPCCallImp::onRequest(strMethod, jvParams, headers, strPath, sb, strHost, j);
2184 },
2185 kRpcReplyMaxBytes,
2186 kRpcWebhookTimeout,
2187 [callbackFuncP, j](
2188 boost::system::error_code const& ecResult, int iStatus, std::string const& strData) {
2189 return RPCCallImp::onResponse(callbackFuncP, ecResult, iStatus, strData, j);
2190 },
2191 j);
2192}
2193
2194} // namespace rpc_call
2195
2196} // namespace xrpl
T all_of(T... args)
T begin(T... args)
A generic endpoint for log messages.
Definition Journal.h:44
Stream debug() const
Definition Journal.h:344
Stream trace() const
Severity stream access functions.
Definition Journal.h:338
Stream warn() const
Definition Journal.h:356
Unserialize a JSON document into a Value.
Definition json_reader.h:20
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Represents a JSON value.
Definition json_value.h:121
const_iterator begin() const
bool isNull() const
isNull() tests to see if this field is null.
bool isObject() const
bool isArray() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
const_iterator end() const
UInt asUInt() const
std::string asString() const
Returns the unquoted string value.
bool isObjectOrNull() const
bool isMember(char const *key) const
Return true if the object has a member named key.
Int asInt() const
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:526
std::optional< beast::ip::Endpoint > rpcIp
static void request(bool bSSL, boost::asio::io_context &ioContext, std::string strSite, unsigned short const port, std::function< void(boost::asio::streambuf &sb, std::string const &strHost)> build, std::size_t responseMax, std::chrono::seconds timeout, std::function< bool(boost::system::error_code const &ecResult, int iStatus, std::string const &strData)> complete, beast::Journal const &j)
Manages partitions for logging.
Definition Log.h:23
beast::Journal journal(std::string const &name)
Definition Log.cpp:137
json::Value parseManifest(json::Value const &jvParams)
Definition RPCCall.cpp:282
json::Value parseJson2(json::Value const &jvParams)
Definition RPCCall.cpp:678
json::Value parseLedgerId(json::Value const &jvParams)
Definition RPCCall.cpp:760
json::Value parseJson(json::Value const &jvParams)
Definition RPCCall.cpp:620
json::Value parseAccountTransactions(json::Value const &jvParams)
Definition RPCCall.cpp:318
json::Value parseSignFor(json::Value const &jvParams)
Definition RPCCall.cpp:592
RPCParser(unsigned apiVersion, beast::Journal j)
Definition RPCCall.cpp:1753
json::Value parseLedgerEntry(json::Value const &jvParams)
Definition RPCCall.cpp:781
json::Value parseAccountItems(json::Value const &jvParams)
Definition RPCCall.cpp:820
json::Value parseEvented(json::Value const &jvParams)
Definition RPCCall.cpp:536
static bool validPublicKey(std::string const &strPk, TokenType type=TokenType::AccountPublic)
Definition RPCCall.cpp:233
json::Value parseChannelAuthorize(json::Value const &jvParams)
Definition RPCCall.cpp:848
json::Value parseFeature(json::Value const &jvParams)
Definition RPCCall.cpp:544
json::Value parseChannelVerify(json::Value const &jvParams)
Definition RPCCall.cpp:892
json::Value parseInternal(json::Value const &jvParams)
Definition RPCCall.cpp:265
json::Value parseAccountRaw1(json::Value const &jvParams)
Definition RPCCall.cpp:963
json::Value parseTxHistory(json::Value const &jvParams)
Definition RPCCall.cpp:1214
json::Value parseRipplePathFind(json::Value const &jvParams)
Definition RPCCall.cpp:1026
json::Value parseValidationCreate(json::Value const &jvParams)
Definition RPCCall.cpp:1231
json::Value parseServerDefinitions(json::Value const &jvParams)
Definition RPCCall.cpp:1305
json::Value parseServerInfo(json::Value const &jvParams)
Definition RPCCall.cpp:1320
json::Value parseCommand(std::string_view strMethod, json::Value const &jvParams, bool allowAnyCommand)
Definition RPCCall.cpp:1762
json::Value parseSubmitMultiSigned(json::Value const &jvParams)
Definition RPCCall.cpp:1135
json::Value parsePeerReservationsDel(json::Value const &jvParams)
Definition RPCCall.cpp:1017
json::Value parseGetCounts(json::Value const &jvParams)
Definition RPCCall.cpp:578
json::Value parseFetchInfo(json::Value const &jvParams)
Definition RPCCall.cpp:303
static std::span< std::string_view const > methodNames()
Names of every method the command line accepts.
Definition RPCCall.cpp:1717
json::Value parseLogLevel(json::Value const &jvParams)
Definition RPCCall.cpp:799
static json::Value jvParseCurrencyIssuer(std::string const &strCurrencyIssuer)
Definition RPCCall.cpp:200
json::Value parseWalletPropose(json::Value const &jvParams)
Definition RPCCall.cpp:1246
static constexpr auto kSortedCommands
Definition RPCCall.cpp:1693
json::Value parseAccountCurrencies(json::Value const &jvParams)
Definition RPCCall.cpp:826
static constexpr bool commandsValid()
Whether the command table is well formed.
Definition RPCCall.cpp:1738
static constexpr auto kCommandArray
Definition RPCCall.cpp:1333
json::Value parseVault(json::Value const &jvParams)
Definition RPCCall.cpp:984
json::Value parseGatewayBalances(json::Value const &jvParams)
Definition RPCCall.cpp:1262
json::Value parseTx(json::Value const &jvParams)
Definition RPCCall.cpp:1181
static bool jvParseLedger(json::Value &jvRequest, std::string const &strLedger)
Definition RPCCall.cpp:179
json::Value parseSimulate(json::Value const &jvParams)
Definition RPCCall.cpp:1053
json::Value parseConnect(json::Value const &jvParams)
Definition RPCCall.cpp:484
json::Value parseSignSubmit(json::Value const &jvParams)
Definition RPCCall.cpp:1085
json::Value parseBookOffers(json::Value const &jvParams)
Definition RPCCall.cpp:394
json::Value parseAccountLines(json::Value const &jvParams)
Definition RPCCall.cpp:833
json::Value parseAccountChannels(json::Value const &jvParams)
Definition RPCCall.cpp:840
json::Value parseTransactionEntry(json::Value const &jvParams)
Definition RPCCall.cpp:1155
unsigned const apiVersion_
Definition RPCCall.cpp:173
json::Value parseAsIs(json::Value const &jvParams)
Definition RPCCall.cpp:253
bool isValidJson2(json::Value const &jv)
Reports whether jv is a request this client accepts as JSON-RPC 2.0: an object whose jsonrpc is rpc::...
Definition RPCCall.cpp:652
beast::Journal const j_
Definition RPCCall.cpp:174
json::Value parseCanDelete(json::Value const &jvParams)
Definition RPCCall.cpp:461
json::Value parseDepositAuthorized(json::Value const &jvParams)
Definition RPCCall.cpp:513
json::Value(RPCParser::*)(json::Value const &jvParams) ParseFuncPtr
Definition RPCCall.cpp:249
json::Value parsePeerReservationsAdd(json::Value const &jvParams)
Definition RPCCall.cpp:1003
json::Value parseLedger(json::Value const &jvParams)
Definition RPCCall.cpp:730
json::Value parseAccountRaw2(json::Value const &jvParams, char const *const acc2Field)
Definition RPCCall.cpp:921
static constexpr auto kCommandNames
Definition RPCCall.cpp:1706
T count(T... args)
T empty(T... args)
T end(T... args)
T endl(T... args)
T find_first_not_of(T... args)
T find_last_of(T... args)
T for_each(T... args)
T is_sorted(T... args)
T lower_bound(T... args)
T max(T... args)
constexpr Out lexicalCast(In in, Out defaultValue=Out())
Convert from one type to another.
BasicLogstream< char > LogStream
Definition Journal.h:474
constexpr Zero kZero
Definition Zero.h:30
unsigned int UInt
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
constexpr std::string_view kInternal
Definition MethodNames.h:43
constexpr std::string_view kAccountNfts
Definition MethodNames.h:23
constexpr std::string_view kPing
Definition MethodNames.h:67
constexpr std::string_view kAccountLines
Definition MethodNames.h:22
constexpr std::string_view kBookOffers
Definition MethodNames.h:30
constexpr std::string_view kAccountOffers
Definition MethodNames.h:25
constexpr std::string_view kConnect
Definition MethodNames.h:34
constexpr std::string_view kRipplePathFind
Definition MethodNames.h:70
constexpr std::string_view kAccountCurrencies
Definition MethodNames.h:20
constexpr std::string_view kLedgerCurrent
Definition MethodNames.h:50
constexpr std::string_view kPeerReservationsAdd
Definition MethodNames.h:63
constexpr std::string_view kChannelAuthorize
Definition MethodNames.h:32
constexpr std::string_view kAccountChannels
Names of the RPC methods the server accepts.
Definition MethodNames.h:19
constexpr std::string_view kPeerReservationsDel
Definition MethodNames.h:64
constexpr std::string_view kLogLevel
Definition MethodNames.h:55
constexpr std::string_view kSubmitMultisigned
Definition MethodNames.h:79
constexpr std::string_view kWalletPropose
Definition MethodNames.h:93
constexpr std::string_view kLedgerAccept
Definition MethodNames.h:47
constexpr std::string_view kLedger
Definition MethodNames.h:46
constexpr std::string_view kAccountTx
Definition MethodNames.h:26
constexpr std::string_view kBookChanges
Definition MethodNames.h:29
constexpr std::string_view kValidationCreate
Definition MethodNames.h:87
constexpr std::string_view kConsensusInfo
Definition MethodNames.h:35
constexpr std::string_view kJson2
Definition MethodNames.h:45
constexpr std::string_view kOwnerInfo
Definition MethodNames.h:61
constexpr std::string_view kDepositAuthorized
Definition MethodNames.h:36
constexpr std::string_view kServerDefinitions
Definition MethodNames.h:71
constexpr std::string_view kAmmInfo
Definition MethodNames.h:27
constexpr std::string_view kCanDelete
Definition MethodNames.h:31
constexpr std::string_view kLogrotate
Definition MethodNames.h:56
constexpr std::string_view kLedgerEntry
Definition MethodNames.h:52
constexpr std::string_view kChannelVerify
Definition MethodNames.h:33
constexpr std::string_view kPeers
Definition MethodNames.h:66
constexpr std::string_view kSign
Definition MethodNames.h:74
constexpr std::string_view kGetCounts
Definition MethodNames.h:42
constexpr std::string_view kVersion
Definition MethodNames.h:92
constexpr std::string_view kPathFind
Definition MethodNames.h:62
constexpr std::string_view kServerInfo
Definition MethodNames.h:72
constexpr std::string_view kAccountObjects
Definition MethodNames.h:24
constexpr std::string_view kManifest
Definition MethodNames.h:57
constexpr std::string_view kLedgerHeader
Definition MethodNames.h:53
constexpr std::string_view kSubmit
Definition MethodNames.h:78
constexpr std::string_view kStop
Definition MethodNames.h:77
constexpr std::string_view kLedgerClosed
Definition MethodNames.h:49
constexpr std::string_view kFetchInfo
Definition MethodNames.h:39
constexpr std::string_view kTxHistory
Definition MethodNames.h:83
constexpr std::string_view kSubscribe
Definition MethodNames.h:80
constexpr std::string_view kValidatorInfo
Definition MethodNames.h:88
constexpr std::string_view kTx
Definition MethodNames.h:82
constexpr std::string_view kPrint
Definition MethodNames.h:68
constexpr std::string_view kTransactionEntry
Definition MethodNames.h:81
constexpr std::string_view kVaultInfo
Definition MethodNames.h:91
constexpr std::string_view kSimulate
Definition MethodNames.h:76
constexpr std::string_view kSignFor
Definition MethodNames.h:75
constexpr std::string_view kPeerReservationsList
Definition MethodNames.h:65
constexpr std::string_view kFeature
Definition MethodNames.h:37
constexpr std::string_view kLedgerRequest
Definition MethodNames.h:54
constexpr std::string_view kUnlList
Definition MethodNames.h:85
constexpr std::string_view kJson
Definition MethodNames.h:44
constexpr std::string_view kRandom
Definition MethodNames.h:69
constexpr std::string_view kServerState
Definition MethodNames.h:73
constexpr std::string_view kAccountInfo
Definition MethodNames.h:21
constexpr std::string_view kUnsubscribe
Definition MethodNames.h:86
constexpr std::string_view kGatewayBalances
Definition MethodNames.h:40
Processes XRPL RPC calls.
Definition RPCCall.cpp:2124
void fromNetwork(boost::asio::io_context &ioContext, std::string const &strIp, std::uint16_t const iPort, std::string const &strUsername, std::string const &strPassword, std::string const &strPath, std::string const &strMethod, json::Value const &jvParams, bool const bSSL, bool const quiet, Logs &logs, std::function< void(json::Value const &jvInput)> callbackFuncP, std::unordered_map< std::string, std::string > headers)
Definition RPCCall.cpp:2139
int fromCommandLine(Config const &config, std::vector< std::string > const &vCmd, Logs &logs)
Definition RPCCall.cpp:2127
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:231
json::Value invalidFieldError(std::string const &name)
Definition ErrorCodes.h:285
static constexpr auto kApiCommandLineVersion
Definition ApiVersion.h:35
constexpr std::string_view kRippleRpcVersion2
Definition ApiVersion.h:57
constexpr std::string_view kJsonRpcVersion
Value of the jsonrpc member of a request and of its reply, fixed at "2.0" by the JSON-RPC specificati...
Definition JsonRpc.h:16
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcChannelAmtMalformed
Definition ErrorCodes.h:84
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcBadKeyType
Definition ErrorCodes.h:116
@ RpcSuccess
Definition ErrorCodes.h:27
@ RpcActMalformed
Definition ErrorCodes.h:73
@ RpcNotSynced
Definition ErrorCodes.h:50
@ RpcLgrIdxsInvalid
Definition ErrorCodes.h:95
@ RpcPublicMalformed
Definition ErrorCodes.h:100
@ RpcJsonRpc
Definition ErrorCodes.h:30
@ RpcNoEvents
Definition ErrorCodes.h:37
@ RpcInvalidParams
Definition ErrorCodes.h:67
@ RpcBadSyntax
Definition ErrorCodes.h:29
@ RpcChannelMalformed
Definition ErrorCodes.h:83
@ RpcLgrIdxMalformed
Definition ErrorCodes.h:96
@ RpcUnknownCommand
Definition ErrorCodes.h:68
ServerHandler::Setup setupServerHandler(Config const &config, std::ostream &log)
std::optional< KeyType > keyTypeFromString(std::string const &s)
Definition KeyType.h:14
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.
Definition AccountID.cpp:95
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
std::string jsonrpcRequest(std::string const &strMethod, json::Value const &params, json::Value const &id)
Definition RPCCall.cpp:1824
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
BaseUInt< 256 > UInt256
Definition base_uint.h:581
json::Value rpcCmdToJson(std::vector< std::string > const &args, json::Value &retParams, unsigned int apiVersion, beast::Journal j)
Definition RPCCall.cpp:1927
constexpr auto megabytes(T value) noexcept
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
std::span< std::string_view const > commandLineMethodNames()
Return the names of all methods accepted on the command line.
Definition RPCCall.cpp:1920
static std::string const & systemName()
std::string base64Encode(std::uint8_t const *data, std::size_t len)
std::optional< std::uint64_t > toUInt64(std::string const &s)
TokenType
Definition tokens.h:19
std::pair< int, json::Value > rpcClient(std::vector< std::string > const &args, Config const &config, Logs &logs, unsigned int apiVersion, std::unordered_map< std::string, std::string > const &headers)
Internal invocation of RPC client.
Definition RPCCall.cpp:1972
bool isRpcError(json::Value jvResult)
Definition RPCErr.cpp:22
std::string createHTTPPost(std::string const &strHost, std::string const &strPath, std::string const &strMsg, std::unordered_map< std::string, std::string > const &mapRequestHeaders)
Definition RPCCall.cpp:143
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T parse(T... args)
T size(T... args)
T sort(T... args)
T starts_with(T... args)
T stoi(T... args)
T str(T... args)
static bool onResponse(std::function< void(json::Value const &jvInput)> callbackFuncP, boost::system::error_code const &ecResult, int iStatus, std::string const &strData, beast::Journal j)
Definition RPCCall.cpp:1854
RPCCallImp()=default
static void callRPCHandler(json::Value *jvOutput, json::Value const &jvInput)
Definition RPCCall.cpp:1848
static void onRequest(std::string const &strMethod, json::Value const &jvParams, std::unordered_map< std::string, std::string > const &headers, std::string const &strPath, boost::asio::streambuf &sb, std::string const &strHost, beast::Journal j)
Definition RPCCall.cpp:1900
T transform(T... args)