scripted-diff: Rename InitInterfaces to NodeContext

-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-
This commit is contained in:
Russell Yanofsky 2019-09-17 17:04:39 -04:00
parent cfec3e01b4
commit 301bd41a2e
11 changed files with 41 additions and 41 deletions

View file

@ -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;
@ -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()");
@ -156,7 +156,7 @@ static bool AppInit(int argc, char* argv[])
} else {
WaitForShutdown();
}
Shutdown(interfaces);
Shutdown(node);
return fRet;
}

View file

@ -19,7 +19,7 @@ public:
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

View file

@ -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;
@ -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();
@ -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();
}
@ -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);
@ -1207,7 +1207,7 @@ bool AppInitLockDataDirectory()
return true;
}
bool AppInitMain(InitInterfaces& interfaces)
bool AppInitMain(NodeContext& node)
{
const CChainParams& chainparams = Params();
// ********************************************************* Step 4a: application initialization
@ -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
@ -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;
}
@ -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;
}
@ -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);
}

View file

@ -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;
@ -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
@ -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

View file

@ -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
{
@ -75,11 +75,11 @@ public:
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(); }
@ -255,12 +255,12 @@ public:
}
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;
}
@ -315,7 +315,7 @@ public:
/* verification progress is unused when a header was received */ 0);
}));
}
InitInterfaces m_interfaces;
NodeContext m_context;
};
} // namespace

View file

@ -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,

View file

@ -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. */

View file

@ -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)

View file

@ -25,8 +25,8 @@ public:
//! 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();
@ -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")));
}

View file

@ -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);
@ -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);

View file

@ -5,7 +5,7 @@
#ifndef BITCOIN_WALLETINITINTERFACE_H
#define BITCOIN_WALLETINITINTERFACE_H
struct InitInterfaces;
struct NodeContext;
class WalletInitInterface {
public:
@ -15,8 +15,8 @@ public:
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() {}
};