Skip to content

Commit

Permalink
refactor: Add InitContext function to initialize NodeContext with glo…
Browse files Browse the repository at this point in the history
…bal 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.
  • Loading branch information
ryanofsky committed Oct 18, 2023
1 parent 53e86e4 commit 60dfc5e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ static fs::path GetPidFile(const ArgsManager& args)
}
}

void InitContext(NodeContext& node)
{
node.args = &gArgs;
}

//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
Expand Down
3 changes: 3 additions & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace node {
struct NodeContext;
} // namespace node

/** Initialize node context variables. */
void InitContext(node::NodeContext& node);

/** Interrupt threads */
void Interrupt(node::NodeContext& node);
void Shutdown(node::NodeContext& node);
Expand Down
4 changes: 2 additions & 2 deletions src/init/bitcoin-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
Expand All @@ -23,7 +23,7 @@ class BitcoinGuiInit : public interfaces::Init
public:
BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{
m_node.args = &gArgs;
InitContext(m_node);
m_node.init = this;
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
Expand Down
4 changes: 2 additions & 2 deletions src/init/bitcoin-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
Expand All @@ -25,7 +25,7 @@ class BitcoinNodeInit : public interfaces::Init
: m_node(node),
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{
m_node.args = &gArgs;
InitContext(m_node);
m_node.init = this;
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
Expand Down
4 changes: 2 additions & 2 deletions src/init/bitcoin-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
Expand All @@ -20,7 +20,7 @@ class BitcoinQtInit : public interfaces::Init
public:
BitcoinQtInit()
{
m_node.args = &gArgs;
InitContext(m_node);
m_node.init = this;
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
Expand Down
4 changes: 2 additions & 2 deletions src/init/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/args.h>
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
Expand All @@ -22,7 +22,7 @@ class BitcoindInit : public interfaces::Init
public:
BitcoindInit(NodeContext& node) : m_node(node)
{
m_node.args = &gArgs;
InitContext(m_node);
m_node.init = this;
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
Expand Down

0 comments on commit 60dfc5e

Please sign in to comment.