mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
wallet: Use shared pointer to retain wallet instance
This commit is contained in:
@@ -222,8 +222,8 @@ class NodeImpl : public Node
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
std::vector<std::unique_ptr<Wallet>> wallets;
|
||||
for (CWallet* wallet : GetWallets()) {
|
||||
wallets.emplace_back(MakeWallet(*wallet));
|
||||
for (const std::shared_ptr<CWallet>& wallet : GetWallets()) {
|
||||
wallets.emplace_back(MakeWallet(wallet));
|
||||
}
|
||||
return wallets;
|
||||
#else
|
||||
@@ -249,7 +249,7 @@ class NodeImpl : public Node
|
||||
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
|
||||
{
|
||||
CHECK_WALLET(
|
||||
return MakeHandler(::uiInterface.LoadWallet.connect([fn](CWallet* wallet) { fn(MakeWallet(*wallet)); })));
|
||||
return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
|
||||
}
|
||||
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ WalletTxOut MakeWalletTxOut(CWallet& wallet, const CWalletTx& wtx, int n, int de
|
||||
class WalletImpl : public Wallet
|
||||
{
|
||||
public:
|
||||
WalletImpl(CWallet& wallet) : m_wallet(wallet) {}
|
||||
WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_shared_wallet(wallet), m_wallet(*wallet.get()) {}
|
||||
|
||||
bool encryptWallet(const SecureString& wallet_passphrase) override
|
||||
{
|
||||
@@ -453,11 +453,12 @@ public:
|
||||
return MakeHandler(m_wallet.NotifyWatchonlyChanged.connect(fn));
|
||||
}
|
||||
|
||||
std::shared_ptr<CWallet> m_shared_wallet;
|
||||
CWallet& m_wallet;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Wallet> MakeWallet(CWallet& wallet) { return MakeUnique<WalletImpl>(wallet); }
|
||||
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return MakeUnique<WalletImpl>(wallet); }
|
||||
|
||||
} // namespace interfaces
|
||||
|
||||
@@ -363,7 +363,7 @@ struct WalletTxOut
|
||||
|
||||
//! Return implementation of Wallet interface. This function will be undefined
|
||||
//! in builds where ENABLE_WALLET is false.
|
||||
std::unique_ptr<Wallet> MakeWallet(CWallet& wallet);
|
||||
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);
|
||||
|
||||
} // namespace interfaces
|
||||
|
||||
|
||||
Reference in New Issue
Block a user