mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
refactor: remove ::vpwallets and related global variables
Move global wallet variables to WalletContext struct
This commit is contained in:
@@ -110,7 +110,7 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet,
|
||||
class WalletImpl : public Wallet
|
||||
{
|
||||
public:
|
||||
explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet) {}
|
||||
explicit WalletImpl(WalletContext& context, const std::shared_ptr<CWallet>& wallet) : m_context(context), m_wallet(wallet) {}
|
||||
|
||||
bool encryptWallet(const SecureString& wallet_passphrase) override
|
||||
{
|
||||
@@ -458,7 +458,7 @@ public:
|
||||
CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
|
||||
void remove() override
|
||||
{
|
||||
RemoveWallet(m_wallet, false /* load_on_start */);
|
||||
RemoveWallet(m_context, m_wallet, false /* load_on_start */);
|
||||
}
|
||||
bool isLegacy() override { return m_wallet->IsLegacy(); }
|
||||
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
|
||||
@@ -494,6 +494,7 @@ public:
|
||||
}
|
||||
CWallet* wallet() override { return m_wallet.get(); }
|
||||
|
||||
WalletContext& m_context;
|
||||
std::shared_ptr<CWallet> m_wallet;
|
||||
};
|
||||
|
||||
@@ -505,7 +506,7 @@ public:
|
||||
m_context.chain = &chain;
|
||||
m_context.args = &args;
|
||||
}
|
||||
~WalletClientImpl() override { UnloadWallets(); }
|
||||
~WalletClientImpl() override { UnloadWallets(m_context); }
|
||||
|
||||
//! ChainClient methods
|
||||
void registerRpcs() override
|
||||
@@ -519,11 +520,11 @@ public:
|
||||
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
|
||||
}
|
||||
}
|
||||
bool verify() override { return VerifyWallets(*m_context.chain); }
|
||||
bool load() override { return LoadWallets(*m_context.chain); }
|
||||
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
|
||||
void flush() override { return FlushWallets(); }
|
||||
void stop() override { return StopWallets(); }
|
||||
bool verify() override { return VerifyWallets(m_context); }
|
||||
bool load() override { return LoadWallets(m_context); }
|
||||
void start(CScheduler& scheduler) override { return StartWallets(m_context, scheduler); }
|
||||
void flush() override { return FlushWallets(m_context); }
|
||||
void stop() override { return StopWallets(m_context); }
|
||||
void setMockTime(int64_t time) override { return SetMockTime(time); }
|
||||
|
||||
//! WalletClient methods
|
||||
@@ -535,14 +536,14 @@ public:
|
||||
options.require_create = true;
|
||||
options.create_flags = wallet_creation_flags;
|
||||
options.create_passphrase = passphrase;
|
||||
return MakeWallet(CreateWallet(*m_context.chain, name, true /* load_on_start */, options, status, error, warnings));
|
||||
return MakeWallet(m_context, CreateWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
|
||||
}
|
||||
std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
|
||||
{
|
||||
DatabaseOptions options;
|
||||
DatabaseStatus status;
|
||||
options.require_existing = true;
|
||||
return MakeWallet(LoadWallet(*m_context.chain, name, true /* load_on_start */, options, status, error, warnings));
|
||||
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
|
||||
}
|
||||
std::string getWalletDir() override
|
||||
{
|
||||
@@ -559,15 +560,16 @@ public:
|
||||
std::vector<std::unique_ptr<Wallet>> getWallets() override
|
||||
{
|
||||
std::vector<std::unique_ptr<Wallet>> wallets;
|
||||
for (const auto& wallet : GetWallets()) {
|
||||
wallets.emplace_back(MakeWallet(wallet));
|
||||
for (const auto& wallet : GetWallets(m_context)) {
|
||||
wallets.emplace_back(MakeWallet(m_context, wallet));
|
||||
}
|
||||
return wallets;
|
||||
}
|
||||
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
|
||||
{
|
||||
return HandleLoadWallet(std::move(fn));
|
||||
return HandleLoadWallet(m_context, std::move(fn));
|
||||
}
|
||||
WalletContext* context() override { return &m_context; }
|
||||
|
||||
WalletContext m_context;
|
||||
const std::vector<std::string> m_wallet_filenames;
|
||||
@@ -578,7 +580,7 @@ public:
|
||||
} // namespace wallet
|
||||
|
||||
namespace interfaces {
|
||||
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? std::make_unique<wallet::WalletImpl>(wallet) : nullptr; }
|
||||
std::unique_ptr<Wallet> MakeWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet) { return wallet ? std::make_unique<wallet::WalletImpl>(context, wallet) : nullptr; }
|
||||
|
||||
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user