Skip to content

Commit e2c8ba9

Browse files
committed
Remove uses of InitMessage/Warning/Error in wallet code
This commit does not change behavior.
1 parent c5e59a9 commit e2c8ba9

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

src/interfaces/chain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <threadsafety.h>
1717
#include <timedata.h>
1818
#include <txmempool.h>
19+
#include <ui_interface.h>
1920
#include <uint256.h>
2021
#include <util/system.h>
2122
#include <validation.h>
@@ -239,6 +240,9 @@ class ChainImpl : public Chain
239240
bool getPruneMode() override { return ::fPruneMode; }
240241
bool p2pEnabled() override { return g_connman != nullptr; }
241242
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
243+
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
244+
void initWarning(const std::string& message) override { InitWarning(message); }
245+
void initError(const std::string& message) override { InitError(message); }
242246
};
243247

244248
} // namespace

src/interfaces/chain.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ class Chain
167167

168168
//! Get adjusted time.
169169
virtual int64_t getAdjustedTime() = 0;
170+
171+
//! Send init message.
172+
virtual void initMessage(const std::string& message) = 0;
173+
174+
//! Send init warning.
175+
virtual void initWarning(const std::string& message) = 0;
176+
177+
//! Send init error.
178+
virtual void initError(const std::string& message) = 0;
170179
};
171180

172181
//! Interface to let node manage chain clients (wallets, or maybe tools for

src/wallet/init.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,15 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
138138
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
139139
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
140140
if (error || !fs::exists(wallet_dir)) {
141-
return InitError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
141+
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
142+
return false;
142143
} else if (!fs::is_directory(wallet_dir)) {
143-
return InitError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
144+
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
145+
return false;
144146
// The canonical path transforms relative paths into absolute ones, so we check the non-canonical version
145147
} else if (!wallet_dir.is_absolute()) {
146-
return InitError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
148+
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
149+
return false;
147150
}
148151
gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string());
149152
}
@@ -164,14 +167,15 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
164167
WalletLocation location(wallet_file);
165168

166169
if (!wallet_paths.insert(location.GetPath()).second) {
167-
return InitError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
170+
chain.initError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
171+
return false;
168172
}
169173

170174
std::string error_string;
171175
std::string warning_string;
172176
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warning_string);
173-
if (!error_string.empty()) InitError(error_string);
174-
if (!warning_string.empty()) InitWarning(warning_string);
177+
if (!error_string.empty()) chain.initError(error_string);
178+
if (!warning_string.empty()) chain.initWarning(warning_string);
175179
if (!verify_success) return false;
176180
}
177181

src/wallet/wallet.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,17 +4087,17 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
40874087
std::vector<CWalletTx> vWtx;
40884088

40894089
if (gArgs.GetBoolArg("-zapwallettxes", false)) {
4090-
uiInterface.InitMessage(_("Zapping all transactions from wallet..."));
4090+
chain.initMessage(_("Zapping all transactions from wallet..."));
40914091

40924092
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(chain, location, WalletDatabase::Create(location.GetPath()));
40934093
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
40944094
if (nZapWalletRet != DBErrors::LOAD_OK) {
4095-
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
4095+
chain.initError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
40964096
return nullptr;
40974097
}
40984098
}
40994099

4100-
uiInterface.InitMessage(_("Loading wallet..."));
4100+
chain.initMessage(_("Loading wallet..."));
41014101

41024102
int64_t nStart = GetTimeMillis();
41034103
bool fFirstRun = true;
@@ -4108,26 +4108,26 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41084108
if (nLoadWalletRet != DBErrors::LOAD_OK)
41094109
{
41104110
if (nLoadWalletRet == DBErrors::CORRUPT) {
4111-
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
4111+
chain.initError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
41124112
return nullptr;
41134113
}
41144114
else if (nLoadWalletRet == DBErrors::NONCRITICAL_ERROR)
41154115
{
4116-
InitWarning(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
4117-
" or address book entries might be missing or incorrect."),
4116+
chain.initWarning(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
4117+
" or address book entries might be missing or incorrect."),
41184118
walletFile));
41194119
}
41204120
else if (nLoadWalletRet == DBErrors::TOO_NEW) {
4121-
InitError(strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, _(PACKAGE_NAME)));
4121+
chain.initError(strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, _(PACKAGE_NAME)));
41224122
return nullptr;
41234123
}
41244124
else if (nLoadWalletRet == DBErrors::NEED_REWRITE)
41254125
{
4126-
InitError(strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)));
4126+
chain.initError(strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)));
41274127
return nullptr;
41284128
}
41294129
else {
4130-
InitError(strprintf(_("Error loading %s"), walletFile));
4130+
chain.initError(strprintf(_("Error loading %s"), walletFile));
41314131
return nullptr;
41324132
}
41334133
}
@@ -4146,7 +4146,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41464146
walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
41474147
if (nMaxVersion < walletInstance->GetVersion())
41484148
{
4149-
InitError(_("Cannot downgrade wallet"));
4149+
chain.initError(_("Cannot downgrade wallet"));
41504150
return nullptr;
41514151
}
41524152
walletInstance->SetMaxVersion(nMaxVersion);
@@ -4159,7 +4159,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41594159
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
41604160
int max_version = walletInstance->nWalletVersion;
41614161
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >=FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
4162-
InitError(_("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified."));
4162+
chain.initError(_("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified."));
41634163
return nullptr;
41644164
}
41654165

@@ -4187,7 +4187,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
41874187
// Regenerate the keypool if upgraded to HD
41884188
if (hd_upgrade) {
41894189
if (!walletInstance->TopUpKeyPool()) {
4190-
InitError(_("Unable to generate keys"));
4190+
chain.initError(_("Unable to generate keys"));
41914191
return nullptr;
41924192
}
41934193
}
@@ -4211,42 +4211,42 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
42114211

42124212
// Top up the keypool
42134213
if (walletInstance->CanGenerateKeys() && !walletInstance->TopUpKeyPool()) {
4214-
InitError(_("Unable to generate initial keys"));
4214+
chain.initError(_("Unable to generate initial keys"));
42154215
return nullptr;
42164216
}
42174217

42184218
auto locked_chain = chain.assumeLocked(); // Temporary. Removed in upcoming lock cleanup
42194219
walletInstance->ChainStateFlushed(locked_chain->getTipLocator());
42204220
} else if (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) {
42214221
// Make it impossible to disable private keys after creation
4222-
InitError(strprintf(_("Error loading %s: Private keys can only be disabled during creation"), walletFile));
4222+
chain.initError(strprintf(_("Error loading %s: Private keys can only be disabled during creation"), walletFile));
42234223
return NULL;
42244224
} else if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
42254225
LOCK(walletInstance->cs_KeyStore);
42264226
if (!walletInstance->mapKeys.empty() || !walletInstance->mapCryptedKeys.empty()) {
4227-
InitWarning(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys"), walletFile));
4227+
chain.initWarning(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys"), walletFile));
42284228
}
42294229
}
42304230

42314231
if (!gArgs.GetArg("-addresstype", "").empty() && !ParseOutputType(gArgs.GetArg("-addresstype", ""), walletInstance->m_default_address_type)) {
4232-
InitError(strprintf("Unknown address type '%s'", gArgs.GetArg("-addresstype", "")));
4232+
chain.initError(strprintf("Unknown address type '%s'", gArgs.GetArg("-addresstype", "")));
42334233
return nullptr;
42344234
}
42354235

42364236
if (!gArgs.GetArg("-changetype", "").empty() && !ParseOutputType(gArgs.GetArg("-changetype", ""), walletInstance->m_default_change_type)) {
4237-
InitError(strprintf("Unknown change type '%s'", gArgs.GetArg("-changetype", "")));
4237+
chain.initError(strprintf("Unknown change type '%s'", gArgs.GetArg("-changetype", "")));
42384238
return nullptr;
42394239
}
42404240

42414241
if (gArgs.IsArgSet("-mintxfee")) {
42424242
CAmount n = 0;
42434243
if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
4244-
InitError(AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", "")));
4244+
chain.initError(AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", "")));
42454245
return nullptr;
42464246
}
42474247
if (n > HIGH_TX_FEE_PER_KB) {
4248-
InitWarning(AmountHighWarn("-mintxfee") + " " +
4249-
_("This is the minimum transaction fee you pay on every transaction."));
4248+
chain.initWarning(AmountHighWarn("-mintxfee") + " " +
4249+
_("This is the minimum transaction fee you pay on every transaction."));
42504250
}
42514251
walletInstance->m_min_fee = CFeeRate(n);
42524252
}
@@ -4255,41 +4255,41 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
42554255
if (gArgs.IsArgSet("-fallbackfee")) {
42564256
CAmount nFeePerK = 0;
42574257
if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
4258-
InitError(strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", "")));
4258+
chain.initError(strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", "")));
42594259
return nullptr;
42604260
}
42614261
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
4262-
InitWarning(AmountHighWarn("-fallbackfee") + " " +
4263-
_("This is the transaction fee you may pay when fee estimates are not available."));
4262+
chain.initWarning(AmountHighWarn("-fallbackfee") + " " +
4263+
_("This is the transaction fee you may pay when fee estimates are not available."));
42644264
}
42654265
walletInstance->m_fallback_fee = CFeeRate(nFeePerK);
42664266
walletInstance->m_allow_fallback_fee = nFeePerK != 0; //disable fallback fee in case value was set to 0, enable if non-null value
42674267
}
42684268
if (gArgs.IsArgSet("-discardfee")) {
42694269
CAmount nFeePerK = 0;
42704270
if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
4271-
InitError(strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", "")));
4271+
chain.initError(strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", "")));
42724272
return nullptr;
42734273
}
42744274
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
4275-
InitWarning(AmountHighWarn("-discardfee") + " " +
4276-
_("This is the transaction fee you may discard if change is smaller than dust at this level"));
4275+
chain.initWarning(AmountHighWarn("-discardfee") + " " +
4276+
_("This is the transaction fee you may discard if change is smaller than dust at this level"));
42774277
}
42784278
walletInstance->m_discard_rate = CFeeRate(nFeePerK);
42794279
}
42804280
if (gArgs.IsArgSet("-paytxfee")) {
42814281
CAmount nFeePerK = 0;
42824282
if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
4283-
InitError(AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", "")));
4283+
chain.initError(AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", "")));
42844284
return nullptr;
42854285
}
42864286
if (nFeePerK > HIGH_TX_FEE_PER_KB) {
4287-
InitWarning(AmountHighWarn("-paytxfee") + " " +
4288-
_("This is the transaction fee you will pay if you send a transaction."));
4287+
chain.initWarning(AmountHighWarn("-paytxfee") + " " +
4288+
_("This is the transaction fee you will pay if you send a transaction."));
42894289
}
42904290
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
42914291
if (walletInstance->m_pay_tx_fee < ::minRelayTxFee) {
4292-
InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
4292+
chain.initError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
42934293
gArgs.GetArg("-paytxfee", ""), ::minRelayTxFee.ToString()));
42944294
return nullptr;
42954295
}
@@ -4338,12 +4338,12 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43384338
}
43394339

43404340
if (rescan_height != block_height) {
4341-
InitError(_("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"));
4341+
chain.initError(_("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"));
43424342
return nullptr;
43434343
}
43444344
}
43454345

4346-
uiInterface.InitMessage(_("Rescanning..."));
4346+
chain.initMessage(_("Rescanning..."));
43474347
walletInstance->WalletLogPrintf("Rescanning last %i blocks (from block %i)...\n", *tip_height - rescan_height, rescan_height);
43484348

43494349
// No need to read and scan block if block was created before
@@ -4358,7 +4358,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43584358
{
43594359
WalletRescanReserver reserver(walletInstance.get());
43604360
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(locked_chain->getBlockHash(rescan_height), {} /* stop block */, reserver, true /* update */).status)) {
4361-
InitError(_("Failed to rescan the wallet during initialization"));
4361+
chain.initError(_("Failed to rescan the wallet during initialization"));
43624362
return nullptr;
43634363
}
43644364
}

0 commit comments

Comments
 (0)