Skip to content

Commit

Permalink
scripted-diff: Rename InitInterfaces to NodeContext
Browse files Browse the repository at this point in the history
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'struct InitInterfaces'              'struct NodeContext'
s 'InitInterfaces interfaces'          'NodeContext node'
s 'InitInterfaces& interfaces'         'NodeContext\& node'
s 'InitInterfaces m_interfaces'        'NodeContext m_context'
s 'InitInterfaces\* g_rpc_interfaces'  'NodeContext* g_rpc_node'
s 'g_rpc_interfaces = &interfaces'     'g_rpc_node = \&node'
s 'g_rpc_interfaces'                   'g_rpc_node'
s 'm_interfaces'                       'm_context'
s 'interfaces\.chain'                  'node.chain'
s '\(AppInitMain\|Shutdown\|Construct\)(interfaces)' '\1(node)'
s 'init interfaces' 'chain clients'
-END VERIFY SCRIPT-
  • Loading branch information
ryanofsky committed Oct 28, 2019
1 parent cfec3e0 commit 301bd41
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/bitcoind.cpp
Expand Up @@ -39,8 +39,8 @@ static void WaitForShutdown()
//
static bool AppInit(int argc, char* argv[])
{
InitInterfaces interfaces;
interfaces.chain = interfaces::MakeChain();
NodeContext node;
node.chain = interfaces::MakeChain();

bool fRet = false;

Expand Down Expand Up @@ -142,7 +142,7 @@ static bool AppInit(int argc, char* argv[])
// If locking the data directory failed, exit immediately
return false;
}
fRet = AppInitMain(interfaces);
fRet = AppInitMain(node);
}
catch (const std::exception& e) {
PrintExceptionContinue(&e, "AppInit()");
Expand All @@ -156,7 +156,7 @@ static bool AppInit(int argc, char* argv[])
} else {
WaitForShutdown();
}
Shutdown(interfaces);
Shutdown(node);

return fRet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dummywallet.cpp
Expand Up @@ -19,7 +19,7 @@ class DummyWalletInit : public WalletInitInterface {
bool HasWalletSupport() const override {return false;}
void AddWalletOptions() const override;
bool ParameterInteraction() const override {return true;}
void Construct(InitInterfaces& interfaces) const override {LogPrintf("No wallet support compiled in!\n");}
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
};

void DummyWalletInit::AddWalletOptions() const
Expand Down
22 changes: 11 additions & 11 deletions src/init.cpp
Expand Up @@ -170,7 +170,7 @@ void Interrupt()
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Interrupt(); });
}

void Shutdown(InitInterfaces& interfaces)
void Shutdown(NodeContext& node)
{
LogPrintf("%s: In progress...\n", __func__);
static CCriticalSection cs_Shutdown;
Expand All @@ -189,7 +189,7 @@ void Shutdown(InitInterfaces& interfaces)
StopREST();
StopRPC();
StopHTTPServer();
for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
client->flush();
}
StopMapPort();
Expand Down Expand Up @@ -261,7 +261,7 @@ void Shutdown(InitInterfaces& interfaces)
}
pblocktree.reset();
}
for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
client->stop();
}

Expand All @@ -280,7 +280,7 @@ void Shutdown(InitInterfaces& interfaces)
} catch (const fs::filesystem_error& e) {
LogPrintf("%s: Unable to remove PID file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
}
interfaces.chain_clients.clear();
node.chain_clients.clear();
UnregisterAllValidationInterfaces();
GetMainSignals().UnregisterBackgroundSignalScheduler();
GetMainSignals().UnregisterWithMempoolSignals(mempool);
Expand Down Expand Up @@ -1207,7 +1207,7 @@ bool AppInitLockDataDirectory()
return true;
}

bool AppInitMain(InitInterfaces& interfaces)
bool AppInitMain(NodeContext& node)
{
const CChainParams& chainparams = Params();
// ********************************************************* Step 4a: application initialization
Expand Down Expand Up @@ -1275,16 +1275,16 @@ bool AppInitMain(InitInterfaces& interfaces)
// according to -wallet and -disablewallet options. This only constructs
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
// when load() and start() interface methods are called below.
g_wallet_init_interface.Construct(interfaces);
g_wallet_init_interface.Construct(node);

/* Register RPC commands regardless of -server setting so they will be
* available in the GUI RPC console even if external calls are disabled.
*/
RegisterAllCoreRPCCommands(tableRPC);
for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
client->registerRpcs();
}
g_rpc_interfaces = &interfaces;
g_rpc_node = &node;
#if ENABLE_ZMQ
RegisterZMQRPCCommands(tableRPC);
#endif
Expand All @@ -1302,7 +1302,7 @@ bool AppInitMain(InitInterfaces& interfaces)
}

// ********************************************************* Step 5: verify wallet database integrity
for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
if (!client->verify()) {
return false;
}
Expand Down Expand Up @@ -1661,7 +1661,7 @@ bool AppInitMain(InitInterfaces& interfaces)
}

// ********************************************************* Step 9: load wallet
for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
if (!client->load()) {
return false;
}
Expand Down Expand Up @@ -1815,7 +1815,7 @@ bool AppInitMain(InitInterfaces& interfaces)
SetRPCWarmupFinished();
uiInterface.InitMessage(_("Done loading").translated);

for (const auto& client : interfaces.chain_clients) {
for (const auto& client : node.chain_clients) {
client->start(scheduler);
}

Expand Down
6 changes: 3 additions & 3 deletions src/init.h
Expand Up @@ -16,7 +16,7 @@ class ChainClient;
} // namespace interfaces

//! Pointers to interfaces used during init and destroyed on shutdown.
struct InitInterfaces
struct NodeContext
{
std::unique_ptr<interfaces::Chain> chain;
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
Expand All @@ -29,7 +29,7 @@ class thread_group;

/** Interrupt threads */
void Interrupt();
void Shutdown(InitInterfaces& interfaces);
void Shutdown(NodeContext& node);
//!Initialize the logging infrastructure
void InitLogging();
//!Parameter interaction: change current parameters depending on various rules
Expand Down Expand Up @@ -63,7 +63,7 @@ bool AppInitLockDataDirectory();
* @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(InitInterfaces& interfaces);
bool AppInitMain(NodeContext& node);

/**
* Setup the arguments for gArgs
Expand Down
12 changes: 6 additions & 6 deletions src/interfaces/node.cpp
Expand Up @@ -52,7 +52,7 @@ namespace {
class NodeImpl : public Node
{
public:
NodeImpl() { m_interfaces.chain = MakeChain(); }
NodeImpl() { m_context.chain = MakeChain(); }
void initError(const std::string& message) override { InitError(message); }
bool parseParameters(int argc, const char* const argv[], std::string& error) override
{
Expand All @@ -75,11 +75,11 @@ class NodeImpl : public Node
return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() &&
AppInitLockDataDirectory();
}
bool appInitMain() override { return AppInitMain(m_interfaces); }
bool appInitMain() override { return AppInitMain(m_context); }
void appShutdown() override
{
Interrupt();
Shutdown(m_interfaces);
Shutdown(m_context);
}
void startShutdown() override { StartShutdown(); }
bool shutdownRequested() override { return ShutdownRequested(); }
Expand Down Expand Up @@ -255,12 +255,12 @@ class NodeImpl : public Node
}
std::unique_ptr<Wallet> loadWallet(const std::string& name, std::string& error, std::vector<std::string>& warnings) override
{
return MakeWallet(LoadWallet(*m_interfaces.chain, name, error, warnings));
return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings));
}
WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector<std::string>& warnings, std::unique_ptr<Wallet>& result) override
{
std::shared_ptr<CWallet> wallet;
WalletCreationStatus status = CreateWallet(*m_interfaces.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
WalletCreationStatus status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
result = MakeWallet(wallet);
return status;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ class NodeImpl : public Node
/* verification progress is unused when a header was received */ 0);
}));
}
InitInterfaces m_interfaces;
NodeContext m_context;
};

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/util.cpp
Expand Up @@ -13,7 +13,7 @@

#include <tuple>

InitInterfaces* g_rpc_interfaces = nullptr;
NodeContext* g_rpc_node = nullptr;

void RPCTypeCheck(const UniValue& params,
const std::list<UniValueType>& typesExpected,
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/util.h
Expand Up @@ -25,12 +25,12 @@
class FillableSigningProvider;
class CPubKey;
class CScript;
struct InitInterfaces;
struct NodeContext;

//! Pointers to interfaces that need to be accessible from RPC methods. Due to
//! limitations of the RPC framework, there's currently no direct way to pass in
//! state to RPC method implementations.
extern InitInterfaces* g_rpc_interfaces;
extern NodeContext* g_rpc_node;

/** Wrapper for UniValue::VType, which includes typeAny:
* Used to denote don't care type. */
Expand Down
8 changes: 4 additions & 4 deletions src/test/rpc_tests.cpp
Expand Up @@ -112,14 +112,14 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
std::string notsigned = r.get_str();
std::string privkey1 = "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\"";
std::string privkey2 = "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\"";
InitInterfaces interfaces;
interfaces.chain = interfaces::MakeChain();
g_rpc_interfaces = &interfaces;
NodeContext node;
node.chain = interfaces::MakeChain();
g_rpc_node = &node;
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout);
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false);
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout);
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true);
g_rpc_interfaces = nullptr;
g_rpc_node = nullptr;
}

BOOST_AUTO_TEST_CASE(rpc_createraw_op_return)
Expand Down
8 changes: 4 additions & 4 deletions src/wallet/init.cpp
Expand Up @@ -25,8 +25,8 @@ class WalletInit : public WalletInitInterface {
//! Wallets parameter interaction
bool ParameterInteraction() const override;

//! Add wallets that should be opened to list of init interfaces.
void Construct(InitInterfaces& interfaces) const override;
//! Add wallets that should be opened to list of chain clients.
void Construct(NodeContext& node) const override;
};

const WalletInitInterface& g_wallet_init_interface = WalletInit();
Expand Down Expand Up @@ -125,12 +125,12 @@ bool WalletInit::ParameterInteraction() const
return true;
}

void WalletInit::Construct(InitInterfaces& interfaces) const
void WalletInit::Construct(NodeContext& node) const
{
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
LogPrintf("Wallet disabled!\n");
return;
}
gArgs.SoftSetArg("-wallet", "");
interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient(*interfaces.chain, gArgs.GetArgs("-wallet")));
node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, gArgs.GetArgs("-wallet")));
}
4 changes: 2 additions & 2 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -2574,7 +2574,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)

std::string error;
std::vector<std::string> warning;
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_interfaces->chain, location, error, warning);
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_node->chain, location, error, warning);
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);

UniValue obj(UniValue::VOBJ);
Expand Down Expand Up @@ -2700,7 +2700,7 @@ static UniValue createwallet(const JSONRPCRequest& request)

std::string error;
std::shared_ptr<CWallet> wallet;
WalletCreationStatus status = CreateWallet(*g_rpc_interfaces->chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
WalletCreationStatus status = CreateWallet(*g_rpc_node->chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
switch (status) {
case WalletCreationStatus::CREATION_FAILED:
throw JSONRPCError(RPC_WALLET_ERROR, error);
Expand Down
6 changes: 3 additions & 3 deletions src/walletinitinterface.h
Expand Up @@ -5,7 +5,7 @@
#ifndef BITCOIN_WALLETINITINTERFACE_H
#define BITCOIN_WALLETINITINTERFACE_H

struct InitInterfaces;
struct NodeContext;

class WalletInitInterface {
public:
Expand All @@ -15,8 +15,8 @@ class WalletInitInterface {
virtual void AddWalletOptions() const = 0;
/** Check wallet parameter interaction */
virtual bool ParameterInteraction() const = 0;
/** Add wallets that should be opened to list of init interfaces. */
virtual void Construct(InitInterfaces& interfaces) const = 0;
/** Add wallets that should be opened to list of chain clients. */
virtual void Construct(NodeContext& node) const = 0;

virtual ~WalletInitInterface() {}
};
Expand Down

0 comments on commit 301bd41

Please sign in to comment.