mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
refactor: Pass NodeContext to RPC and REST methods through util::Ref
This commit does not change behavior
This commit is contained in:
@@ -151,7 +151,7 @@ static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUserna
|
||||
return multiUserAuthorized(strUserPass);
|
||||
}
|
||||
|
||||
static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
|
||||
static bool HTTPReq_JSONRPC(const util::Ref& context, HTTPRequest* req)
|
||||
{
|
||||
// JSONRPC handles only POST
|
||||
if (req->GetRequestMethod() != HTTPRequest::POST) {
|
||||
@@ -166,7 +166,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
|
||||
return false;
|
||||
}
|
||||
|
||||
JSONRPCRequest jreq;
|
||||
JSONRPCRequest jreq(context);
|
||||
jreq.peerAddr = req->GetPeer().ToString();
|
||||
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
|
||||
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", jreq.peerAddr);
|
||||
@@ -288,15 +288,16 @@ static bool InitRPCAuthentication()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StartHTTPRPC()
|
||||
bool StartHTTPRPC(const util::Ref& context)
|
||||
{
|
||||
LogPrint(BCLog::RPC, "Starting HTTP RPC server\n");
|
||||
if (!InitRPCAuthentication())
|
||||
return false;
|
||||
|
||||
RegisterHTTPHandler("/", true, HTTPReq_JSONRPC);
|
||||
auto handle_rpc = [&context](HTTPRequest* req, const std::string&) { return HTTPReq_JSONRPC(context, req); };
|
||||
RegisterHTTPHandler("/", true, handle_rpc);
|
||||
if (g_wallet_init_interface.HasWalletSupport()) {
|
||||
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
|
||||
RegisterHTTPHandler("/wallet/", false, handle_rpc);
|
||||
}
|
||||
struct event_base* eventBase = EventBase();
|
||||
assert(eventBase);
|
||||
|
||||
Reference in New Issue
Block a user