mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-03 17:30:25 +01:00
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.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <support/allocators/secure.h>
|
||||
#include <sync.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/check.h>
|
||||
#include <util/ref.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
@@ -41,16 +42,7 @@
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
class CWallet;
|
||||
fs::path GetWalletDir();
|
||||
std::vector<fs::path> ListWalletDir();
|
||||
std::vector<std::shared_ptr<CWallet>> GetWallets();
|
||||
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||
WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::shared_ptr<CWallet>& result);
|
||||
std::unique_ptr<interfaces::Handler> 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
|
||||
WalletClient& walletClient() override
|
||||
{
|
||||
return GetWalletDir().string();
|
||||
}
|
||||
std::vector<std::string> listWalletDir() override
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
for (auto& path : ListWalletDir()) {
|
||||
paths.push_back(path.string());
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
std::vector<std::unique_ptr<Wallet>> getWallets() override
|
||||
{
|
||||
std::vector<std::unique_ptr<Wallet>> 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<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
|
||||
{
|
||||
return MakeWallet(LoadWallet(*m_context->chain, name, error, warnings));
|
||||
}
|
||||
std::unique_ptr<Wallet> createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) override
|
||||
{
|
||||
std::shared_ptr<CWallet> 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<Handler> handleInitMessage(InitMessageFn fn) override
|
||||
{
|
||||
@@ -286,10 +251,6 @@ public:
|
||||
{
|
||||
return MakeHandler(::uiInterface.ShowProgress_connect(fn));
|
||||
}
|
||||
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
|
||||
{
|
||||
return HandleLoadWallet(std::move(fn));
|
||||
}
|
||||
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
|
||||
{
|
||||
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
|
||||
|
||||
Reference in New Issue
Block a user