Also, for the context, I wonder if we can pipe it through self and then instead remove the JSONRPCRequest instead of RPCMethod:
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index 3852358..6123c38 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -170,3 +170,3 @@ static RPCMethod stop()
RPCExamples{""},
- [](const RPCMethod& self, const JSONRPCRequest& jsonRequest) -> UniValue
+ [](const RPCMethod& self, const JSONRPCRequest&) -> UniValue
{
@@ -174,5 +174,5 @@ static RPCMethod stop()
// this reply will get back to the client.
- CHECK_NONFATAL((CHECK_NONFATAL(EnsureAnyNodeContext(jsonRequest.context).shutdown_request))());
- if (jsonRequest.params[0].isNum()) {
- UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt<int>()});
+ CHECK_NONFATAL((CHECK_NONFATAL(EnsureAnyNodeContext(self.Context()).shutdown_request))());
+ if (const auto wait{self.MaybeArg<int>("wait")}) {
+ UninterruptibleSleep(std::chrono::milliseconds{*wait});
}
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index e2cf363..ccad9da 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -694,2 +694,7 @@ UniValue RPCMethod::HandleRequest(const JSONRPCRequest& request) const
+const std::any& RPCMethod::Context() const
+{
+ return CHECK_NONFATAL(m_req)->context;
+}
+
using CheckFn = void(const RPCArg&);
diff --git a/src/rpc/util.h b/src/rpc/util.h
index bf17885..0e2a075 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -18,2 +18,3 @@
+#include <any>
#include <cstddef>
@@ -451,2 +452,5 @@ public:
UniValue HandleRequest(const JSONRPCRequest& request) const;
+ /// Return the context for the current RPC method invocation.
+ /// Like Arg(), this is only available during the method implementation.
+ const std::any& Context() const;
/**