|
7 | 7 | #include <index/blockfilterindex.h>
|
8 | 8 | #include <index/txindex.h>
|
9 | 9 | #include <interfaces/chain.h>
|
| 10 | +#include <interfaces/echo.h> |
| 11 | +#include <interfaces/init.h> |
| 12 | +#include <interfaces/ipc.h> |
10 | 13 | #include <key_io.h>
|
11 | 14 | #include <node/context.h>
|
12 | 15 | #include <outputtype.h>
|
@@ -644,6 +647,43 @@ static RPCHelpMan echo(const std::string& name)
|
644 | 647 | static RPCHelpMan echo() { return echo("echo"); }
|
645 | 648 | static RPCHelpMan echojson() { return echo("echojson"); }
|
646 | 649 |
|
| 650 | +static RPCHelpMan echoipc() |
| 651 | +{ |
| 652 | + return RPCHelpMan{ |
| 653 | + "echoipc", |
| 654 | + "\nEcho back the input argument, passing it through a spawned process in a multiprocess build.\n" |
| 655 | + "This command is for testing.\n", |
| 656 | + {{"arg", RPCArg::Type::STR, RPCArg::Optional::NO, "The string to echo",}}, |
| 657 | + RPCResult{RPCResult::Type::STR, "echo", "The echoed string."}, |
| 658 | + RPCExamples{HelpExampleCli("echo", "\"Hello world\"") + |
| 659 | + HelpExampleRpc("echo", "\"Hello world\"")}, |
| 660 | + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { |
| 661 | + std::unique_ptr<interfaces::Echo> echo; |
| 662 | + if (interfaces::Ipc* ipc = Assert(EnsureAnyNodeContext(request.context).init)->ipc()) { |
| 663 | + // Spawn a new bitcoin-node process and call makeEcho to get a |
| 664 | + // client pointer to a interfaces::Echo instance running in |
| 665 | + // that process. This is just for testing. A slightly more |
| 666 | + // realistic test spawning a different executable instead of |
| 667 | + // the same executable would add a new bitcoin-echo executable, |
| 668 | + // and spawn bitcoin-echo below instead of bitcoin-node. But |
| 669 | + // using bitcoin-node avoids the need to build and install a |
| 670 | + // new executable just for this one test. |
| 671 | + auto init = ipc->spawnProcess("bitcoin-node"); |
| 672 | + echo = init->makeEcho(); |
| 673 | + ipc->addCleanup(*echo, [init = init.release()] { delete init; }); |
| 674 | + } else { |
| 675 | + // IPC support is not available because this is a bitcoind |
| 676 | + // process not a bitcoind-node process, so just create a local |
| 677 | + // interfaces::Echo object and return it so the `echoipc` RPC |
| 678 | + // method will work, and the python test calling `echoipc` |
| 679 | + // can expect the same result. |
| 680 | + echo = interfaces::MakeEcho(); |
| 681 | + } |
| 682 | + return echo->echo(request.params[0].get_str()); |
| 683 | + }, |
| 684 | + }; |
| 685 | +} |
| 686 | + |
647 | 687 | static UniValue SummaryToJSON(const IndexSummary&& summary, std::string index_name)
|
648 | 688 | {
|
649 | 689 | UniValue ret_summary(UniValue::VOBJ);
|
@@ -719,6 +759,7 @@ static const CRPCCommand commands[] =
|
719 | 759 | { "hidden", &mockscheduler, },
|
720 | 760 | { "hidden", &echo, },
|
721 | 761 | { "hidden", &echojson, },
|
| 762 | + { "hidden", &echoipc, }, |
722 | 763 | };
|
723 | 764 | // clang-format on
|
724 | 765 | for (const auto& c : commands) {
|
|
0 commit comments