mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
9044522ef7
Drop JSONRPCRequest constructors after #21366 (Russell Yanofsky) Pull request description: This just makes an additional simplification after #21366 replaced util::Ref with std::any. It was originally suggested https://github.com/bitcoin/bitcoin/pull/21366#issuecomment-792044351 but delayed for a followup. It would have prevented usage bug https://github.com/bitcoin/bitcoin/pull/21572. ACKs for top commit: promag: ACK9044522ef7
, fixed conflict in src/wallet/interfaces.cpp. Tree-SHA512: e909411b8f75013620b94e1a609296befb832fdcb574cd2e6689bfe3c636b03cd4ac1ccb2b32b532daf0f2131bb043464024966310fffc7e3cad77713d4bd0ef
This commit is contained in:
commit
6664211be2
10 changed files with 28 additions and 41 deletions
|
@ -224,7 +224,7 @@ static bool AppInit(int argc, char* argv[])
|
|||
// If locking the data directory failed, exit immediately
|
||||
return false;
|
||||
}
|
||||
fRet = AppInitInterfaces(node) && AppInitMain(context, node);
|
||||
fRet = AppInitInterfaces(node) && AppInitMain(node);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PrintExceptionContinue(&e, "AppInit()");
|
||||
|
|
|
@ -159,7 +159,8 @@ static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
|
|||
return false;
|
||||
}
|
||||
|
||||
JSONRPCRequest jreq(context);
|
||||
JSONRPCRequest jreq;
|
||||
jreq.context = context;
|
||||
jreq.peerAddr = req->GetPeer().ToString();
|
||||
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
|
||||
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", jreq.peerAddr);
|
||||
|
@ -294,7 +295,7 @@ bool StartHTTPRPC(const std::any& context)
|
|||
if (!InitRPCAuthentication())
|
||||
return false;
|
||||
|
||||
auto handle_rpc = [&context](HTTPRequest* req, const std::string&) { return HTTPReq_JSONRPC(context, req); };
|
||||
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, handle_rpc);
|
||||
|
|
10
src/init.cpp
10
src/init.cpp
|
@ -788,7 +788,7 @@ static bool InitSanityCheck()
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool AppInitServers(const std::any& context, NodeContext& node)
|
||||
static bool AppInitServers(NodeContext& node)
|
||||
{
|
||||
const ArgsManager& args = *Assert(node.args);
|
||||
RPCServer::OnStarted(&OnRPCStarted);
|
||||
|
@ -797,9 +797,9 @@ static bool AppInitServers(const std::any& context, NodeContext& node)
|
|||
return false;
|
||||
StartRPC();
|
||||
node.rpc_interruption_point = RpcInterruptionPoint;
|
||||
if (!StartHTTPRPC(context))
|
||||
if (!StartHTTPRPC(&node))
|
||||
return false;
|
||||
if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(context);
|
||||
if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(&node);
|
||||
StartHTTPServer();
|
||||
return true;
|
||||
}
|
||||
|
@ -1277,7 +1277,7 @@ bool AppInitInterfaces(NodeContext& node)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AppInitMain(const std::any& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
{
|
||||
const ArgsManager& args = *Assert(node.args);
|
||||
const CChainParams& chainparams = Params();
|
||||
|
@ -1382,7 +1382,7 @@ bool AppInitMain(const std::any& context, NodeContext& node, interfaces::BlockAn
|
|||
*/
|
||||
if (args.GetBoolArg("-server", false)) {
|
||||
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
|
||||
if (!AppInitServers(context, node))
|
||||
if (!AppInitServers(node))
|
||||
return InitError(_("Unable to start HTTP server. See debug log for details."));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ bool AppInitInterfaces(NodeContext& node);
|
|||
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
|
||||
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
|
||||
*/
|
||||
bool AppInitMain(const std::any& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
|
||||
bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
|
||||
|
||||
/**
|
||||
* Register all arguments with the ArgsManager
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
}
|
||||
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
|
||||
{
|
||||
return AppInitMain(m_context_ref, *m_context, tip_info);
|
||||
return AppInitMain(*m_context, tip_info);
|
||||
}
|
||||
void appShutdown() override
|
||||
{
|
||||
|
@ -244,7 +244,8 @@ public:
|
|||
CFeeRate getDustRelayFee() override { return ::dustRelayFee; }
|
||||
UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
|
||||
{
|
||||
JSONRPCRequest req(m_context_ref);
|
||||
JSONRPCRequest req;
|
||||
req.context = m_context;
|
||||
req.params = params;
|
||||
req.strMethod = command;
|
||||
req.URI = uri;
|
||||
|
@ -314,14 +315,8 @@ public:
|
|||
void setContext(NodeContext* context) override
|
||||
{
|
||||
m_context = context;
|
||||
if (context) {
|
||||
m_context_ref = context;
|
||||
} else {
|
||||
m_context_ref.reset();
|
||||
}
|
||||
}
|
||||
NodeContext* m_context{nullptr};
|
||||
std::any m_context_ref;
|
||||
};
|
||||
|
||||
bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active)
|
||||
|
|
|
@ -317,7 +317,8 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
|
|||
|
||||
switch (rf) {
|
||||
case RetFormat::JSON: {
|
||||
JSONRPCRequest jsonRequest(context);
|
||||
JSONRPCRequest jsonRequest;
|
||||
jsonRequest.context = context;
|
||||
jsonRequest.params = UniValue(UniValue::VARR);
|
||||
UniValue chainInfoObject = getblockchaininfo().HandleRequest(jsonRequest);
|
||||
std::string strJSON = chainInfoObject.write() + "\n";
|
||||
|
@ -687,7 +688,7 @@ static const struct {
|
|||
void StartREST(const std::any& context)
|
||||
{
|
||||
for (const auto& up : uri_prefixes) {
|
||||
auto handler = [&context, up](HTTPRequest* req, const std::string& prefix) { return up.handler(context, req, prefix); };
|
||||
auto handler = [context, up](HTTPRequest* req, const std::string& prefix) { return up.handler(context, req, prefix); };
|
||||
RegisterHTTPHandler(up.prefix, false, handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,18 +35,7 @@ public:
|
|||
std::string URI;
|
||||
std::string authUser;
|
||||
std::string peerAddr;
|
||||
const std::any& context;
|
||||
|
||||
explicit JSONRPCRequest(const std::any& context) : id(NullUniValue), params(NullUniValue), context(context) {}
|
||||
|
||||
//! Initializes request information from another request object and the
|
||||
//! given context. The implementation should be updated if any members are
|
||||
//! added or removed above.
|
||||
JSONRPCRequest(const JSONRPCRequest& other, const std::any& context)
|
||||
: id(other.id), strMethod(other.strMethod), params(other.params), mode(other.mode), URI(other.URI),
|
||||
authUser(other.authUser), peerAddr(other.peerAddr), context(context)
|
||||
{
|
||||
}
|
||||
std::any context;
|
||||
|
||||
void parse(const UniValue& valRequest);
|
||||
};
|
||||
|
|
|
@ -33,8 +33,8 @@ UniValue RPCTestingSetup::CallRPC(std::string args)
|
|||
boost::split(vArgs, args, boost::is_any_of(" \t"));
|
||||
std::string strMethod = vArgs[0];
|
||||
vArgs.erase(vArgs.begin());
|
||||
std::any context{&m_node};
|
||||
JSONRPCRequest request(context);
|
||||
JSONRPCRequest request;
|
||||
request.context = &m_node;
|
||||
request.strMethod = strMethod;
|
||||
request.params = RPCConvertValues(strMethod, vArgs);
|
||||
if (RPCIsInWarmup(nullptr)) SetRPCWarmupFinished();
|
||||
|
|
|
@ -514,7 +514,9 @@ public:
|
|||
{
|
||||
for (const CRPCCommand& command : GetWalletRPCCommands()) {
|
||||
m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
|
||||
return command.actor({request, &m_context}, result, last_handler);
|
||||
JSONRPCRequest wallet_request = request;
|
||||
wallet_request.context = &m_context;
|
||||
return command.actor(wallet_request, result, last_handler);
|
||||
}, command.argNames, command.unique_id);
|
||||
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
|
||||
}
|
||||
|
@ -522,7 +524,9 @@ public:
|
|||
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||
for (const CRPCCommand& command : GetSignerRPCCommands()) {
|
||||
m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
|
||||
return command.actor({request, &m_context}, result, last_handler);
|
||||
JSONRPCRequest wallet_request = request;
|
||||
wallet_request.context = &m_context;
|
||||
return command.actor(wallet_request, result, last_handler);
|
||||
}, command.argNames, command.unique_id);
|
||||
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
|
||||
}
|
||||
|
|
|
@ -213,8 +213,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
|||
key.pushKV("timestamp", newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
|
||||
key.pushKV("internal", UniValue(true));
|
||||
keys.push_back(key);
|
||||
std::any context;
|
||||
JSONRPCRequest request(context);
|
||||
JSONRPCRequest request;
|
||||
request.params.setArray();
|
||||
request.params.push_back(keys);
|
||||
|
||||
|
@ -265,8 +264,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
|||
AddWallet(wallet);
|
||||
wallet->SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||
}
|
||||
std::any context;
|
||||
JSONRPCRequest request(context);
|
||||
JSONRPCRequest request;
|
||||
request.params.setArray();
|
||||
request.params.push_back(backup_file);
|
||||
|
||||
|
@ -281,8 +279,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
|||
LOCK(wallet->cs_wallet);
|
||||
wallet->SetupLegacyScriptPubKeyMan();
|
||||
|
||||
std::any context;
|
||||
JSONRPCRequest request(context);
|
||||
JSONRPCRequest request;
|
||||
request.params.setArray();
|
||||
request.params.push_back(backup_file);
|
||||
AddWallet(wallet);
|
||||
|
|
Loading…
Add table
Reference in a new issue