mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
refactor: Create interfaces earlier during initialization
Add AppInitInterfaces function so wallet chain and chain client interfaces are created earlier during initialization. This is needed in the next commit to allow the gui splash screen to be able to register for wallet events through a dedicated WalletClient interface instead managing wallets indirectly through the Node interface. This only works if the wallet client interface is created before the splash screen needs to use it.
This commit is contained in:
parent
15886b08aa
commit
b266b3e0bf
4 changed files with 17 additions and 10 deletions
|
@ -44,7 +44,6 @@ static void WaitForShutdown(NodeContext& node)
|
||||||
static bool AppInit(int argc, char* argv[])
|
static bool AppInit(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
NodeContext node;
|
NodeContext node;
|
||||||
node.chain = interfaces::MakeChain(node);
|
|
||||||
|
|
||||||
bool fRet = false;
|
bool fRet = false;
|
||||||
|
|
||||||
|
@ -144,7 +143,7 @@ static bool AppInit(int argc, char* argv[])
|
||||||
// If locking the data directory failed, exit immediately
|
// If locking the data directory failed, exit immediately
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fRet = AppInitMain(context, node);
|
fRet = AppInitInterfaces(node) && AppInitMain(context, node);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
PrintExceptionContinue(&e, "AppInit()");
|
PrintExceptionContinue(&e, "AppInit()");
|
||||||
|
|
17
src/init.cpp
17
src/init.cpp
|
@ -1229,6 +1229,17 @@ bool AppInitLockDataDirectory()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppInitInterfaces(NodeContext& node)
|
||||||
|
{
|
||||||
|
node.chain = interfaces::MakeChain(node);
|
||||||
|
// Create client interfaces for wallets that are supposed to be loaded
|
||||||
|
// 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(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
{
|
{
|
||||||
const ArgsManager& args = *Assert(node.args);
|
const ArgsManager& args = *Assert(node.args);
|
||||||
|
@ -1318,12 +1329,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||||
|
|
||||||
GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
|
GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
|
||||||
|
|
||||||
// Create client interfaces for wallets that are supposed to be loaded
|
|
||||||
// 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(node);
|
|
||||||
|
|
||||||
/* Register RPC commands regardless of -server setting so they will be
|
/* Register RPC commands regardless of -server setting so they will be
|
||||||
* available in the GUI RPC console even if external calls are disabled.
|
* available in the GUI RPC console even if external calls are disabled.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,10 @@ bool AppInitSanityChecks();
|
||||||
* @pre Parameters should be parsed and config file should be read, AppInitSanityChecks should have been called.
|
* @pre Parameters should be parsed and config file should be read, AppInitSanityChecks should have been called.
|
||||||
*/
|
*/
|
||||||
bool AppInitLockDataDirectory();
|
bool AppInitLockDataDirectory();
|
||||||
|
/**
|
||||||
|
* Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
|
||||||
|
*/
|
||||||
|
bool AppInitInterfaces(NodeContext& node);
|
||||||
/**
|
/**
|
||||||
* Bitcoin core main initialization.
|
* Bitcoin core main initialization.
|
||||||
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
|
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
|
||||||
|
|
|
@ -64,11 +64,10 @@ public:
|
||||||
bool baseInitialize() override
|
bool baseInitialize() override
|
||||||
{
|
{
|
||||||
return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(gArgs) && AppInitSanityChecks() &&
|
return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(gArgs) && AppInitSanityChecks() &&
|
||||||
AppInitLockDataDirectory();
|
AppInitLockDataDirectory() && AppInitInterfaces(*m_context);
|
||||||
}
|
}
|
||||||
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
|
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
|
||||||
{
|
{
|
||||||
m_context->chain = MakeChain(*m_context);
|
|
||||||
return AppInitMain(m_context_ref, *m_context, tip_info);
|
return AppInitMain(m_context_ref, *m_context, tip_info);
|
||||||
}
|
}
|
||||||
void appShutdown() override
|
void appShutdown() override
|
||||||
|
|
Loading…
Add table
Reference in a new issue