MCPcopy Create free account
hub / github.com/ElementsProject/elements / echoipc

Function echoipc

src/rpc/misc.cpp:743–779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

741static RPCHelpMan echojson() { return echo("echojson"); }
742
743static RPCHelpMan echoipc()
744{
745 return RPCHelpMan{
746 "echoipc",
747 "\nEcho back the input argument, passing it through a spawned process in a multiprocess build.\n"
748 "This command is for testing.\n",
749 {{"arg", RPCArg::Type::STR, RPCArg::Optional::NO, "The string to echo",}},
750 RPCResult{RPCResult::Type::STR, "echo", "The echoed string."},
751 RPCExamples{HelpExampleCli("echo", "\"Hello world\"") +
752 HelpExampleRpc("echo", "\"Hello world\"")},
753 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
754 interfaces::Init& local_init = *EnsureAnyNodeContext(request.context).init;
755 std::unique_ptr<interfaces::Echo> echo;
756 if (interfaces::Ipc* ipc = local_init.ipc()) {
757 // Spawn a new bitcoin-node process and call makeEcho to get a
758 // client pointer to a interfaces::Echo instance running in
759 // that process. This is just for testing. A slightly more
760 // realistic test spawning a different executable instead of
761 // the same executable would add a new bitcoin-echo executable,
762 // and spawn bitcoin-echo below instead of bitcoin-node. But
763 // using bitcoin-node avoids the need to build and install a
764 // new executable just for this one test.
765 auto init = ipc->spawnProcess("bitcoin-node");
766 echo = init->makeEcho();
767 ipc->addCleanup(*echo, [init = init.release()] { delete init; });
768 } else {
769 // IPC support is not available because this is a bitcoind
770 // process not a bitcoind-node process, so just create a local
771 // interfaces::Echo object and return it so the `echoipc` RPC
772 // method will work, and the python test calling `echoipc`
773 // can expect the same result.
774 echo = local_init.makeEcho();
775 }
776 return echo->echo(request.params[0].get_str());
777 },
778 };
779}
780
781static UniValue SummaryToJSON(const IndexSummary&& summary, std::string index_name)
782{

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
spawnProcessMethod · 0.80
releaseMethod · 0.80
echoMethod · 0.80
ipcMethod · 0.45
makeEchoMethod · 0.45
addCleanupMethod · 0.45

Tested by

no test coverage detected