From b266b3e0bf29d0f3d5deaeec62d57c5025b35525 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Fri, 29 May 2020 00:07:18 -0400 Subject: 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. --- src/interfaces/node.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/interfaces/node.cpp') diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 206262eb0..73171686e 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -64,11 +64,10 @@ public: bool baseInitialize() override { return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(gArgs) && AppInitSanityChecks() && - AppInitLockDataDirectory(); + AppInitLockDataDirectory() && AppInitInterfaces(*m_context); } bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override { - m_context->chain = MakeChain(*m_context); return AppInitMain(m_context_ref, *m_context, tip_info); } void appShutdown() override -- cgit v1.2.3 From e4f435047121886edb6e6a6c4e4998e44ed2e36a Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Thu, 28 May 2020 09:48:30 -0400 Subject: refactor: Move wallet methods out of chain.h and node.h Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. Also tweaks splash screen registration for load wallet events to be delayed until after wallet client is created. --- src/interfaces/node.cpp | 45 +++------------------------------------------ 1 file changed, 3 insertions(+), 42 deletions(-) (limited to 'src/interfaces/node.cpp') diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 73171686e..2c5f8627e 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -41,16 +42,7 @@ #include -class CWallet; -fs::path GetWalletDir(); -std::vector ListWalletDir(); -std::vector> GetWallets(); -std::shared_ptr LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector& warnings); -WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector& warnings, std::shared_ptr& result); -std::unique_ptr HandleLoadWallet(interfaces::Node::LoadWalletFn load_wallet); - namespace interfaces { - namespace { class NodeImpl : public Node @@ -239,36 +231,9 @@ public: LOCK(::cs_main); return ::ChainstateActive().CoinsTip().GetCoin(output, coin); } - std::string getWalletDir() override - { - return GetWalletDir().string(); - } - std::vector listWalletDir() override - { - std::vector paths; - for (auto& path : ListWalletDir()) { - paths.push_back(path.string()); - } - return paths; - } - std::vector> getWallets() override + WalletClient& walletClient() override { - std::vector> wallets; - for (auto& client : m_context->chain_clients) { - auto client_wallets = client->getWallets(); - std::move(client_wallets.begin(), client_wallets.end(), std::back_inserter(wallets)); - } - return wallets; - } - std::unique_ptr loadWallet(const std::string& name, bilingual_str& error, std::vector& warnings) override - { - return MakeWallet(LoadWallet(*m_context->chain, name, error, warnings)); - } - std::unique_ptr createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector& warnings, WalletCreationStatus& status) override - { - std::shared_ptr wallet; - status = CreateWallet(*m_context->chain, passphrase, wallet_creation_flags, name, error, warnings, wallet); - return MakeWallet(wallet); + return *Assert(m_context->wallet_client); } std::unique_ptr handleInitMessage(InitMessageFn fn) override { @@ -286,10 +251,6 @@ public: { return MakeHandler(::uiInterface.ShowProgress_connect(fn)); } - std::unique_ptr handleLoadWallet(LoadWalletFn fn) override - { - return HandleLoadWallet(std::move(fn)); - } std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override { return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); -- cgit v1.2.3