Skip to content

Commit 2188c3e

Browse files
committed
Move some static functions out of wallet.h/cpp
>>> backports bitcoin/bitcoin@d97fe20 This commit just moves a few function declarations and updates callers. Function bodies are moved in two followup MOVEONLY commits. This change is desirable because wallet.h/cpp are monolithic and hard to navigate, so pulling things out and grouping together pieces of related functionality should improve the organization. Another proximate motivation is the wallet process separation work in parameter parsing and fee estimation are still done in the main process rather than the wallet process, and having functions that run in different processes scrambled up throughout wallet.cpp is unnecessarily confusing.
1 parent f49acf7 commit 2188c3e

File tree

13 files changed

+121
-45
lines changed

13 files changed

+121
-45
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ set(WALLET_SOURCES
259259
./src/wallet/hdchain.cpp
260260
./src/wallet/rpcdump.cpp
261261
./src/zpiv/zerocoin.cpp
262+
./src/wallet/fees.cpp
263+
./src/wallet/init.cpp
262264
./src/wallet/scriptpubkeyman.cpp
263265
./src/wallet/rpcwallet.cpp
264266
./src/kernel.cpp

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ BITCOIN_CORE_H = \
297297
wallet/rpcwallet.h \
298298
wallet/scriptpubkeyman.h \
299299
destination_io.h \
300+
wallet/fees.h \
301+
wallet/init.h \
300302
wallet/wallet.h \
301303
wallet/walletdb.h \
302304
warnings.h \
@@ -395,6 +397,8 @@ libbitcoin_wallet_a_SOURCES = \
395397
legacy/stakemodifier.cpp \
396398
kernel.cpp \
397399
wallet/db.cpp \
400+
wallet/fees.cpp \
401+
wallet/init.cpp \
398402
wallet/rpcdump.cpp \
399403
wallet/rpcwallet.cpp \
400404
wallet/hdchain.cpp \

src/guiinterfaceutil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define GUIINTERFACEUTIL_H
77

88
#include "guiinterface.h"
9+
#include "tinyformat.h"
10+
#include "util/system.h"
911

1012
inline static bool UIError(const std::string &str)
1113
{

src/init.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
#include "validation.h"
5858
#include "validationinterface.h"
5959
#include "zpivchain.h"
60+
#include "warnings.h"
6061

6162
#ifdef ENABLE_WALLET
63+
#include "wallet/init.h"
6264
#include "wallet/wallet.h"
6365
#include "wallet/rpcwallet.h"
64-
6566
#endif
66-
#include "warnings.h"
6767

6868
#include <atomic>
6969
#include <fstream>
@@ -507,7 +507,7 @@ std::string HelpMessage(HelpMessageMode mode)
507507
" " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway"));
508508

509509
#if ENABLE_WALLET
510-
strUsage += CWallet::GetWalletHelpString(showDebug);
510+
strUsage += GetWalletHelpString(showDebug);
511511
#endif
512512

513513
if (mode == HMM_BITCOIN_QT) {
@@ -1158,7 +1158,7 @@ bool AppInitParameterInteraction()
11581158

11591159
#ifdef ENABLE_WALLET
11601160
strWalletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
1161-
if (!CWallet::ParameterInteraction())
1161+
if (!WalletParameterInteraction())
11621162
return false;
11631163
#endif // ENABLE_WALLET
11641164

@@ -1332,7 +1332,7 @@ bool AppInitMain()
13321332

13331333
// ********************************************************* Step 5: Verify wallet database integrity
13341334
#ifdef ENABLE_WALLET
1335-
if (!CWallet::Verify()) {
1335+
if (!WalletVerify()) {
13361336
return false;
13371337
}
13381338
#endif
@@ -1721,7 +1721,7 @@ bool AppInitMain()
17211721

17221722
// ********************************************************* Step 8: Backup and Load wallet
17231723
#ifdef ENABLE_WALLET
1724-
if (!CWallet::InitLoadWallet())
1724+
if (!InitLoadWallet())
17251725
return false;
17261726
#else
17271727
LogPrintf("No wallet compiled in!\n");

src/qt/coincontroldialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "optionsmodel.h"
1616
#include "policy/policy.h"
1717
#include "txmempool.h"
18+
#include "wallet/fees.h"
1819
#include "wallet/wallet.h"
1920
#include "walletmodel.h"
2021

@@ -632,7 +633,7 @@ void CoinControlDialog::updateLabels()
632633

633634
// tool tips
634635
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
635-
toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CWallet::GetRequiredFee(1000))) + "<br /><br />";
636+
toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, GetRequiredFee(1000))) + "<br /><br />";
636637
toolTip1 += tr("Can vary +/- 1 byte per input.");
637638

638639
QString toolTip3 = tr("This label turns red, if recipient receives an amount smaller than %1 (transparent) / %2 (shield)."
@@ -641,9 +642,9 @@ void CoinControlDialog::updateLabels()
641642
// how many satoshis the estimated fee can vary per byte we guess wrong
642643
double dFeeVary;
643644
if (payTxFee.GetFeePerK() > 0)
644-
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), payTxFee.GetFeePerK()) / 1000;
645+
dFeeVary = (double)std::max(GetRequiredFee(1000), payTxFee.GetFeePerK()) / 1000;
645646
else
646-
dFeeVary = (double)std::max(CWallet::GetRequiredFee(1000), mempool.estimateSmartFee(nTxConfirmTarget).GetFeePerK()) / 1000;
647+
dFeeVary = (double)std::max(GetRequiredFee(1000), mempool.estimateSmartFee(nTxConfirmTarget).GetFeePerK()) / 1000;
647648
QString toolTip4 = tr("Can vary +/- %1 u%2 per input.").arg(dFeeVary).arg(CURRENCY_UNIT.c_str());
648649

649650
ui->labelCoinControlFee->setToolTip(toolTip4);

src/qt/pivx/sendcustomfeedialog.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "qt/pivx/sendcustomfeedialog.h"
66
#include "qt/pivx/forms/ui_sendcustomfeedialog.h"
77
#include "qt/pivx/qtutils.h"
8-
#include "walletmodel.h"
8+
#include "qt/walletmodel.h"
99
#include "optionsmodel.h"
1010
#include "guiutil.h"
11+
#include "wallet/fees.h"
1112
#include <QListView>
1213
#include <QComboBox>
1314

@@ -123,19 +124,19 @@ void SendCustomFeeDialog::accept()
123124
// Check insane fee
124125
const CAmount insaneFee = ::minRelayTxFee.GetFeePerK() * 10000;
125126
if (customFee >= insaneFee) {
126-
ui->lineEditCustomFee->setText(BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), insaneFee - CWallet::GetRequiredFee(1000)));
127+
ui->lineEditCustomFee->setText(BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), insaneFee - GetRequiredFee(1000)));
127128
inform(tr("Fee too high. Must be below: %1").arg(
128129
BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), insaneFee)));
129-
} else if (customFee < CWallet::GetRequiredFee(1000)) {
130+
} else if (customFee < GetRequiredFee(1000)) {
130131
CAmount nFee = 0;
131132
if (walletModel->hasWalletCustomFee()) {
132133
walletModel->getWalletCustomFee(nFee);
133134
} else {
134-
nFee = CWallet::GetRequiredFee(1000);
135+
nFee = GetRequiredFee(1000);
135136
}
136137
ui->lineEditCustomFee->setText(BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), nFee));
137138
inform(tr("Fee too low. Must be at least: %1").arg(
138-
BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000))));
139+
BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), GetRequiredFee(1000))));
139140
} else {
140141
walletModel->setWalletCustomFee(fUseCustomFee, customFee);
141142
QDialog::accept();

src/wallet/fees.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2017 The Bitcoin Core developers
3+
// Copyright (c) 2021 The PIVX developers
4+
// Distributed under the MIT software license, see the accompanying
5+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
#include "wallet/fees.h"
8+
9+
#include "policy/policy.h"
10+
#include "txmempool.h"
11+
#include "util/system.h"
12+
#include "validation.h"
13+
#include "wallet/wallet.h"

src/wallet/fees.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2017 The Bitcoin Core developers
3+
// Copyright (c) 2021 The PIVX developers
4+
// Distributed under the MIT software license, see the accompanying
5+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
#ifndef PIVX_WALLET_FEES_H
8+
#define PIVX_WALLET_FEES_H
9+
10+
#include "amount.h"
11+
12+
class CTxMemPool;
13+
14+
/**
15+
* Return the minimum required fee taking into account the
16+
* floating relay fee and user set minimum transaction fee
17+
*/
18+
CAmount GetRequiredFee(unsigned int nTxBytes);
19+
20+
/**
21+
* Estimate the minimum fee considering user set parameters
22+
* and the required fee
23+
*/
24+
CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
25+
26+
27+
#endif // PIVX_WALLET_FEES_H

src/wallet/init.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2017 The Bitcoin Core developers
3+
// Copyright (c) 2021 The PIVX developers
4+
// Distributed under the MIT software license, see the accompanying
5+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
#include "wallet/init.h"
8+
9+
#include "guiinterfaceutil.h"
10+
#include "net.h"
11+
#include "util/system.h"
12+
#include "utilmoneystr.h"
13+
#include "validation.h"
14+
#include "wallet/wallet.h"

src/wallet/init.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2017 The Bitcoin Core developers
3+
// Copyright (c) 2021 The PIVX developers
4+
// Distributed under the MIT software license, see the accompanying
5+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
#ifndef PIVX_WALLET_INIT_H
8+
#define PIVX_WALLET_INIT_H
9+
10+
#include <string>
11+
12+
//! Return the wallets help message.
13+
std::string GetWalletHelpString(bool showDebug);
14+
15+
//! Wallets parameter interaction
16+
bool WalletParameterInteraction();
17+
18+
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
19+
// This function will perform salvage on the wallet if requested, as long as only one wallet is
20+
// being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
21+
bool WalletVerify();
22+
23+
//! Load wallet databases.
24+
bool InitLoadWallet();
25+
26+
#endif // PIVX_WALLET_INIT_H

0 commit comments

Comments
 (0)