Skip to content

Commit 213542b

Browse files
committed
refactor: Add InitContext function to initialize NodeContext with global pointers
Having InitContext() avoids the need to add duplicate code to src/init/*.cpp files in the next commit. It also lets these files avoid referencing global variables like gArgs. There is no change in behavior in this commit.
1 parent feeb7b8 commit 213542b

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/init.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ static void RemovePidFile(const ArgsManager& args)
192192
}
193193
}
194194

195+
void InitContext(NodeContext& node)
196+
{
197+
node.args = &gArgs;
198+
}
195199

196200
//////////////////////////////////////////////////////////////////////////////
197201
//

src/init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ namespace node {
2626
struct NodeContext;
2727
} // namespace node
2828

29+
/** Initialize node context variables. */
30+
void InitContext(node::NodeContext& node);
31+
2932
/** Interrupt threads */
3033
void Interrupt(node::NodeContext& node);
3134
void Shutdown(node::NodeContext& node);

src/init/bitcoin-gui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <common/args.h>
5+
#include <init.h>
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
@@ -23,7 +23,7 @@ class BitcoinGuiInit : public interfaces::Init
2323
public:
2424
BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
2525
{
26-
m_node.args = &gArgs;
26+
InitContext(m_node);
2727
m_node.init = this;
2828
}
2929
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

src/init/bitcoin-node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <common/args.h>
5+
#include <init.h>
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
@@ -25,7 +25,7 @@ class BitcoinNodeInit : public interfaces::Init
2525
: m_node(node),
2626
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
2727
{
28-
m_node.args = &gArgs;
28+
InitContext(m_node);
2929
m_node.init = this;
3030
}
3131
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

src/init/bitcoin-qt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <common/args.h>
5+
#include <init.h>
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
@@ -20,7 +20,7 @@ class BitcoinQtInit : public interfaces::Init
2020
public:
2121
BitcoinQtInit()
2222
{
23-
m_node.args = &gArgs;
23+
InitContext(m_node);
2424
m_node.init = this;
2525
}
2626
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

src/init/bitcoind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <common/args.h>
5+
#include <init.h>
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
@@ -22,7 +22,7 @@ class BitcoindInit : public interfaces::Init
2222
public:
2323
BitcoindInit(NodeContext& node) : m_node(node)
2424
{
25-
m_node.args = &gArgs;
25+
InitContext(m_node);
2626
m_node.init = this;
2727
}
2828
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

0 commit comments

Comments
 (0)