Skip to content

Commit d97fe20

Browse files
committed
Move some static functions out of wallet.h/cpp
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 bitcoin/bitcoin#10973, where (at least initially) 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 c2704ec commit d97fe20

File tree

13 files changed

+117
-50
lines changed

13 files changed

+117
-50
lines changed

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ BITCOIN_CORE_H = \
162162
wallet/crypter.h \
163163
wallet/db.h \
164164
wallet/feebumper.h \
165+
wallet/fees.h \
166+
wallet/init.h \
165167
wallet/rpcwallet.h \
166168
wallet/wallet.h \
167169
wallet/walletdb.h \
@@ -239,6 +241,8 @@ libbitcoin_wallet_a_SOURCES = \
239241
wallet/crypter.cpp \
240242
wallet/db.cpp \
241243
wallet/feebumper.cpp \
244+
wallet/fees.cpp \
245+
wallet/init.cpp \
242246
wallet/rpcdump.cpp \
243247
wallet/rpcwallet.cpp \
244248
wallet/wallet.cpp \

src/init.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "utilmoneystr.h"
4444
#include "validationinterface.h"
4545
#ifdef ENABLE_WALLET
46+
#include "wallet/init.h"
4647
#include "wallet/wallet.h"
4748
#endif
4849
#include "warnings.h"
@@ -420,7 +421,7 @@ std::string HelpMessage(HelpMessageMode mode)
420421
strUsage += HelpMessageOpt("-maxuploadtarget=<n>", strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET));
421422

422423
#ifdef ENABLE_WALLET
423-
strUsage += CWallet::GetWalletHelpString(showDebug);
424+
strUsage += GetWalletHelpString(showDebug);
424425
#endif
425426

426427
#if ENABLE_ZMQ
@@ -1035,7 +1036,7 @@ bool AppInitParameterInteraction()
10351036
if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) {
10361037
return InitError(AmountErrMsg("minrelaytxfee", gArgs.GetArg("-minrelaytxfee", "")));
10371038
}
1038-
// High fee check is done afterward in CWallet::ParameterInteraction()
1039+
// High fee check is done afterward in WalletParameterInteraction()
10391040
::minRelayTxFee = CFeeRate(n);
10401041
} else if (incrementalRelayFee > ::minRelayTxFee) {
10411042
// Allow only setting incrementalRelayFee to control both
@@ -1068,7 +1069,7 @@ bool AppInitParameterInteraction()
10681069
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp);
10691070

10701071
#ifdef ENABLE_WALLET
1071-
if (!CWallet::ParameterInteraction())
1072+
if (!WalletParameterInteraction())
10721073
return false;
10731074
#endif
10741075

@@ -1245,7 +1246,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12451246

12461247
// ********************************************************* Step 5: verify wallet database integrity
12471248
#ifdef ENABLE_WALLET
1248-
if (!CWallet::Verify())
1249+
if (!WalletVerify())
12491250
return false;
12501251
#endif
12511252
// ********************************************************* Step 6: network initialization
@@ -1566,7 +1567,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15661567

15671568
// ********************************************************* Step 8: load wallet
15681569
#ifdef ENABLE_WALLET
1569-
if (!CWallet::InitLoadWallet())
1570+
if (!InitLoadWallet())
15701571
return false;
15711572
#else
15721573
LogPrintf("No wallet support compiled in!\n");

src/qt/coincontroldialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "policy/fees.h"
1919
#include "policy/policy.h"
2020
#include "validation.h" // For mempool
21+
#include "wallet/fees.h"
2122
#include "wallet/wallet.h"
2223

2324
#include <QApplication>
@@ -510,7 +511,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
510511
nBytes -= 34;
511512

512513
// Fee
513-
nPayFee = CWallet::GetMinimumFee(nBytes, *coinControl, ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
514+
nPayFee = GetMinimumFee(nBytes, *coinControl, ::mempool, ::feeEstimator, nullptr /* FeeCalculation */);
514515

515516
if (nPayAmount > 0)
516517
{

src/qt/optionsdialog.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
#include "netbase.h"
1818
#include "txdb.h" // for -dbcache defaults
1919

20-
#ifdef ENABLE_WALLET
21-
#include "wallet/wallet.h" // for CWallet::GetRequiredFee()
22-
#endif
23-
2420
#include <QDataWidgetMapper>
2521
#include <QDir>
2622
#include <QIntValidator>

src/qt/sendcoinsdialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "ui_interface.h"
2323
#include "txmempool.h"
2424
#include "policy/fees.h"
25-
#include "wallet/wallet.h"
25+
#include "wallet/fees.h"
2626

2727
#include <QFontMetrics>
2828
#include <QMessageBox>
@@ -185,7 +185,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
185185
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
186186
connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(updateSmartFeeLabel()));
187187
connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
188-
ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000));
188+
ui->customFee->setSingleStep(GetRequiredFee(1000));
189189
updateFeeSectionControls();
190190
updateMinFeeLabel();
191191
updateSmartFeeLabel();
@@ -610,7 +610,7 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
610610
void SendCoinsDialog::setMinimumFee()
611611
{
612612
ui->radioCustomPerKilobyte->setChecked(true);
613-
ui->customFee->setValue(CWallet::GetRequiredFee(1000));
613+
ui->customFee->setValue(GetRequiredFee(1000));
614614
}
615615

616616
void SendCoinsDialog::updateFeeSectionControls()
@@ -643,7 +643,7 @@ void SendCoinsDialog::updateMinFeeLabel()
643643
{
644644
if (model && model->getOptionsModel())
645645
ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg(
646-
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), CWallet::GetRequiredFee(1000)) + "/kB")
646+
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), GetRequiredFee(1000)) + "/kB")
647647
);
648648
}
649649

@@ -668,7 +668,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
668668
updateCoinControlState(coin_control);
669669
coin_control.m_feerate.reset(); // Explicitly use only fee estimation rate for smart fee labels
670670
FeeCalculation feeCalc;
671-
CFeeRate feeRate = CFeeRate(CWallet::GetMinimumFee(1000, coin_control, ::mempool, ::feeEstimator, &feeCalc));
671+
CFeeRate feeRate = CFeeRate(GetMinimumFee(1000, coin_control, ::mempool, ::feeEstimator, &feeCalc));
672672

673673
ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB");
674674

src/wallet/feebumper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "consensus/validation.h"
66
#include "wallet/coincontrol.h"
77
#include "wallet/feebumper.h"
8+
#include "wallet/fees.h"
89
#include "wallet/wallet.h"
910
#include "policy/fees.h"
1011
#include "policy/policy.h"
@@ -156,7 +157,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
156157
currentResult = BumpFeeResult::INVALID_PARAMETER;
157158
return;
158159
}
159-
CAmount requiredFee = CWallet::GetRequiredFee(maxNewTxSize);
160+
CAmount requiredFee = GetRequiredFee(maxNewTxSize);
160161
if (totalFee < requiredFee) {
161162
vErrors.push_back(strprintf("Insufficient totalFee (cannot be less than required fee %s)",
162163
FormatMoney(requiredFee)));
@@ -166,7 +167,7 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin
166167
nNewFee = totalFee;
167168
nNewFeeRate = CFeeRate(totalFee, maxNewTxSize);
168169
} else {
169-
nNewFee = CWallet::GetMinimumFee(maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */);
170+
nNewFee = GetMinimumFee(maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */);
170171
nNewFeeRate = CFeeRate(nNewFee, maxNewTxSize);
171172

172173
// New fee rate must be at least old rate + minimum incremental relay rate

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+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include "wallet/fees.h"
7+
8+
#include "policy/policy.h"
9+
#include "txmempool.h"
10+
#include "util.h"
11+
#include "validation.h"
12+
#include "wallet/coincontrol.h"
13+
#include "wallet/wallet.h"

src/wallet/fees.h

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

src/wallet/init.cpp

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

src/wallet/init.h

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

0 commit comments

Comments
 (0)