Skip to content

Commit e2f02aa

Browse files
committed
Refactor: Copy CWallet signals and print function to LegacyScriptPubKeyMan
This commit does not change behavior.
1 parent c729afd commit e2f02aa

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <util/strencodings.h>
1010
#include <util/translation.h>
1111
#include <wallet/scriptpubkeyman.h>
12-
#include <wallet/wallet.h>
1312

1413
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
1514
{
@@ -1427,12 +1426,3 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
14271426
}
14281427
return set_address;
14291428
}
1430-
1431-
// Temporary CWallet accessors and aliases.
1432-
LegacyScriptPubKeyMan::LegacyScriptPubKeyMan(CWallet& wallet)
1433-
: ScriptPubKeyMan(wallet),
1434-
m_wallet(wallet) {}
1435-
1436-
void LegacyScriptPubKeyMan::NotifyWatchonlyChanged(bool fHaveWatchOnly) const { return m_wallet.NotifyWatchonlyChanged(fHaveWatchOnly); }
1437-
void LegacyScriptPubKeyMan::NotifyCanGetAddressesChanged() const { return m_wallet.NotifyCanGetAddressesChanged(); }
1438-
template<typename... Params> void LegacyScriptPubKeyMan::WalletLogPrintf(const std::string& fmt, const Params&... parameters) const { return m_wallet.WalletLogPrintf(fmt, parameters...); }

src/wallet/scriptpubkeyman.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ class ScriptPubKeyMan
206206
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
207207

208208
virtual uint256 GetID() const { return uint256(); }
209+
210+
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
211+
template<typename... Params>
212+
void WalletLogPrintf(std::string fmt, Params... parameters) const {
213+
LogPrintf(("%s " + fmt).c_str(), m_storage.GetDisplayName(), parameters...);
214+
};
215+
216+
/** Watch-only address added */
217+
boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
218+
219+
/** Keypool has new keys */
220+
boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
209221
};
210222

211223
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
@@ -290,6 +302,8 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
290302
bool ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
291303

292304
public:
305+
using ScriptPubKeyMan::ScriptPubKeyMan;
306+
293307
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
294308
isminetype IsMine(const CScript& script) const override;
295309

@@ -426,14 +440,6 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
426440
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
427441

428442
std::set<CKeyID> GetKeys() const override;
429-
// Temporary CWallet accessors and aliases.
430-
friend class CWallet;
431-
friend class ReserveDestination;
432-
LegacyScriptPubKeyMan(CWallet& wallet);
433-
void NotifyWatchonlyChanged(bool fHaveWatchOnly) const;
434-
void NotifyCanGetAddressesChanged() const;
435-
template<typename... Params> void WalletLogPrintf(const std::string& fmt, const Params&... parameters) const;
436-
CWallet& m_wallet;
437443
};
438444

439445
#endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H

src/wallet/wallet.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bool AddWallet(const std::shared_ptr<CWallet>& wallet)
5656
std::vector<std::shared_ptr<CWallet>>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
5757
if (i != vpwallets.end()) return false;
5858
vpwallets.push_back(wallet);
59+
wallet->ConnectScriptPubKeyManNotifiers();
5960
return true;
6061
}
6162

@@ -4218,3 +4219,11 @@ bool CWallet::HasEncryptionKeys() const
42184219
{
42194220
return !mapMasterKeys.empty();
42204221
}
4222+
4223+
void CWallet::ConnectScriptPubKeyManNotifiers()
4224+
{
4225+
for (const auto& spk_man : GetActiveScriptPubKeyMans()) {
4226+
spk_man->NotifyWatchonlyChanged.connect(NotifyWatchonlyChanged);
4227+
spk_man->NotifyCanGetAddressesChanged.connect(NotifyCanGetAddressesChanged);
4228+
}
4229+
}

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
11811181
m_last_block_processed_height = block_height;
11821182
m_last_block_processed = block_hash;
11831183
};
1184+
1185+
//! Connect the signals from ScriptPubKeyMans to the signals in CWallet
1186+
void ConnectScriptPubKeyManNotifiers();
11841187
};
11851188

11861189
/**

test/lint/lint-circular-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
2525
"wallet/fees -> wallet/wallet -> wallet/fees"
2626
"wallet/wallet -> wallet/walletdb -> wallet/wallet"
2727
"policy/fees -> txmempool -> validation -> policy/fees"
28-
"wallet/scriptpubkeyman -> wallet/wallet -> wallet/scriptpubkeyman"
2928
)
3029

3130
EXIT_CODE=0

test/lint/lint-format-strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
("src/validationinterface.cpp", "LogPrint(BCLog::VALIDATION, fmt \"\\n\", __VA_ARGS__)"),
2121
("src/wallet/wallet.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
2222
("src/wallet/wallet.h", "LogPrintf((\"%s \" + fmt).c_str(), GetDisplayName(), parameters...)"),
23+
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
24+
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + fmt).c_str(), m_storage.GetDisplayName(), parameters...)"),
2325
("src/logging.h", "LogPrintf(const char* fmt, const Args&... args)"),
2426
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const std::string& fmt, const Params&... parameters)"),
25-
("src/wallet/scriptpubkeyman.cpp", "WalletLogPrintf(fmt, parameters...)"),
26-
("src/wallet/scriptpubkeyman.cpp", "WalletLogPrintf(const std::string& fmt, const Params&... parameters)"),
2727
]
2828

2929

0 commit comments

Comments
 (0)