Skip to content

Commit 27772d8

Browse files
committed
Merge bitcoin/bitcoin#26889: refactor: wallet, remove global 'ArgsManager' dependency
52f4d56 refactor: remove <util/system.h> include from wallet.h (furszy) 6c9b342 refactor: wallet, remove global 'ArgsManager' access (furszy) d8f5fc4 wallet: set '-walletnotify' script instead of access global args manager (furszy) 3477a28 wallet: set keypool_size instead of access global args manager (furszy) Pull request description: Structurally, the wallet class shouldn't access the global `ArgsManager` class, its internal behavior shouldn't be coupled to a global command line args parsing object. So this PR migrates the only two places where we depend on it: (1) the keypool size, and (2) the "-walletnotify" script. And cleans up the, now unneeded, wallet `ArgsManager` ref member. Extra note: In the process of removing the args ref member, discovered and fixed files that were invalidly depending on the wallet header including `util/system.h`. ACKs for top commit: achow101: ACK 52f4d56 TheCharlatan: Re-ACK 52f4d56 hebasto: re-ACK 52f4d56 Tree-SHA512: 0cffd99b4dd4864bf618aa45aeaabbef2b6441d27b6dbb03489c4e013330877682ff17b418d07aa25fbe1040bdf2c67d7559bdeb84128c5437bf0e6247719016
2 parents fe1b325 + 52f4d56 commit 27772d8

27 files changed

+146
-122
lines changed

src/bench/coin_selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void CoinSelection(benchmark::Bench& bench)
4545
{
4646
NodeContext node;
4747
auto chain = interfaces::MakeChain(node);
48-
CWallet wallet(chain.get(), "", gArgs, CreateDummyWalletDatabase());
48+
CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
4949
std::vector<std::unique_ptr<CWalletTx>> wtxs;
5050
LOCK(wallet.cs_wallet);
5151

src/bench/wallet_balance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
2828

2929
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
3030

31-
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()};
31+
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
3232
{
3333
LOCK(wallet.cs_wallet);
3434
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

src/bench/wallet_create_tx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
8383
{
8484
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
8585

86-
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()};
86+
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
8787
{
8888
LOCK(wallet.cs_wallet);
8989
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@@ -136,7 +136,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
136136
static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type)
137137
{
138138
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
139-
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()};
139+
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
140140
{
141141
LOCK(wallet.cs_wallet);
142142
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

src/qt/optionsmodel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <netbase.h>
1919
#include <txdb.h> // for -dbcache defaults
2020
#include <util/string.h>
21+
#include <util/system.h>
2122
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
2223
#include <wallet/wallet.h> // For DEFAULT_SPEND_ZEROCONF_CHANGE
2324

@@ -668,6 +669,11 @@ bool OptionsModel::isRestartRequired() const
668669
return settings.value("fRestartRequired", false).toBool();
669670
}
670671

672+
bool OptionsModel::hasSigner()
673+
{
674+
return gArgs.GetArg("-signer", "") != "";
675+
}
676+
671677
void OptionsModel::checkAndMigrate()
672678
{
673679
// Migration of default values

src/qt/optionsmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class OptionsModel : public QAbstractListModel
9999
bool getEnablePSBTControls() const { return m_enable_psbt_controls; }
100100
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
101101

102+
/** Whether -signer was set or not */
103+
bool hasSigner();
104+
102105
/* Explicit setters */
103106
void SetPruneTargetGB(int prune_target_gb);
104107

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
203203
if (model->wallet().hasExternalSigner()) {
204204
//: "device" usually means a hardware wallet.
205205
ui->sendButton->setText(tr("Sign on device"));
206-
if (gArgs.GetArg("-signer", "") != "") {
206+
if (model->getOptionsModel()->hasSigner()) {
207207
ui->sendButton->setEnabled(true);
208208
ui->sendButton->setToolTip(tr("Connect your hardware wallet first."));
209209
} else {

src/qt/test/addressbooktests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
7575
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
7676
test.m_node.wallet_loader = wallet_loader.get();
7777
node.setContext(&test.m_node);
78-
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", gArgs, CreateMockWalletDatabase());
78+
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
7979
wallet->LoadWallet();
8080
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
8181
{

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void TestGUI(interfaces::Node& node)
159159
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
160160
test.m_node.wallet_loader = wallet_loader.get();
161161
node.setContext(&test.m_node);
162-
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", gArgs, CreateMockWalletDatabase());
162+
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
163163
wallet->LoadWallet();
164164
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
165165
{

src/wallet/dump.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <wallet/dump.h>
66

77
#include <fs.h>
8+
#include <util/system.h>
89
#include <util/translation.h>
910
#include <wallet/wallet.h>
1011

@@ -202,7 +203,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
202203

203204
// dummy chain interface
204205
bool ret = true;
205-
std::shared_ptr<CWallet> wallet(new CWallet(/*chain=*/nullptr, name, gArgs, std::move(database)), WalletToolReleaseWallet);
206+
std::shared_ptr<CWallet> wallet(new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet);
206207
{
207208
LOCK(wallet->cs_wallet);
208209
DBErrors load_wallet_ret = wallet->LoadWallet();

src/wallet/external_signer_scriptpubkeyman.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace wallet {
1313
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
1414
{
1515
public:
16-
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
17-
: DescriptorScriptPubKeyMan(storage, descriptor)
16+
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size)
17+
: DescriptorScriptPubKeyMan(storage, descriptor, keypool_size)
1818
{}
19-
ExternalSignerScriptPubKeyMan(WalletStorage& storage)
20-
: DescriptorScriptPubKeyMan(storage)
19+
ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
20+
: DescriptorScriptPubKeyMan(storage, keypool_size)
2121
{}
2222

2323
/** Provide a descriptor at setup time

0 commit comments

Comments
 (0)