Skip to content

Commit 37bdcca

Browse files
ryanofskyjnewbery
authored andcommitted
[refactor] Make feebumper namespace
Future commit will remove the FeeBumper class. This commit simply places everything into a feebumper namespace, and changes the enum class name from BumpeFeeResult to feebumper::Result.
1 parent 7c4f009 commit 37bdcca

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

src/qt/walletmodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,14 @@ bool WalletModel::transactionCanBeBumped(uint256 hash) const
666666

667667
bool WalletModel::bumpFee(uint256 hash)
668668
{
669-
std::unique_ptr<FeeBumper> feeBump;
669+
std::unique_ptr<feebumper::FeeBumper> feeBump;
670670
{
671671
CCoinControl coin_control;
672672
coin_control.signalRbf = true;
673673
LOCK2(cs_main, wallet->cs_wallet);
674-
feeBump.reset(new FeeBumper(wallet, hash, coin_control, 0));
674+
feeBump.reset(new feebumper::FeeBumper(wallet, hash, coin_control, 0));
675675
}
676-
if (feeBump->getResult() != BumpFeeResult::OK)
676+
if (feeBump->getResult() != feebumper::Result::OK)
677677
{
678678
QMessageBox::critical(0, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
679679
(feeBump->getErrors().size() ? QString::fromStdString(feeBump->getErrors()[0]) : "") +")");

src/wallet/feebumper.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// calculation, but we should be able to refactor after priority is removed).
2424
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should
2525
// be IsAllFromMe).
26-
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet)
26+
static int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet)
2727
{
2828
CMutableTransaction txNew(tx);
2929
std::vector<CInputCoin> vCoins;
@@ -43,10 +43,12 @@ int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wall
4343
return GetVirtualTransactionSize(txNew);
4444
}
4545

46+
namespace feebumper {
47+
4648
bool FeeBumper::preconditionChecks(const CWallet *wallet, const CWalletTx& wtx) {
4749
if (wallet->HasWalletSpend(wtx.GetHash())) {
4850
errors.push_back("Transaction has descendants in the wallet");
49-
current_result = BumpFeeResult::INVALID_PARAMETER;
51+
current_result = Result::INVALID_PARAMETER;
5052
return false;
5153
}
5254

@@ -55,14 +57,14 @@ bool FeeBumper::preconditionChecks(const CWallet *wallet, const CWalletTx& wtx)
5557
auto it_mp = mempool.mapTx.find(wtx.GetHash());
5658
if (it_mp != mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1) {
5759
errors.push_back("Transaction has descendants in the mempool");
58-
current_result = BumpFeeResult::INVALID_PARAMETER;
60+
current_result = Result::INVALID_PARAMETER;
5961
return false;
6062
}
6163
}
6264

6365
if (wtx.GetDepthInMainChain() != 0) {
6466
errors.push_back("Transaction has been mined, or is conflicted with a mined transaction");
65-
current_result = BumpFeeResult::WALLET_ERROR;
67+
current_result = Result::WALLET_ERROR;
6668
return false;
6769
}
6870
return true;
@@ -80,7 +82,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
8082
auto it = wallet->mapWallet.find(txid);
8183
if (it == wallet->mapWallet.end()) {
8284
errors.push_back("Invalid or non-wallet transaction id");
83-
current_result = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
85+
current_result = Result::INVALID_ADDRESS_OR_KEY;
8486
return;
8587
}
8688
const CWalletTx& wtx = it->second;
@@ -91,21 +93,21 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
9193

9294
if (!SignalsOptInRBF(*wtx.tx)) {
9395
errors.push_back("Transaction is not BIP 125 replaceable");
94-
current_result = BumpFeeResult::WALLET_ERROR;
96+
current_result = Result::WALLET_ERROR;
9597
return;
9698
}
9799

98100
if (wtx.mapValue.count("replaced_by_txid")) {
99101
errors.push_back(strprintf("Cannot bump transaction %s which was already bumped by transaction %s", txid.ToString(), wtx.mapValue.at("replaced_by_txid")));
100-
current_result = BumpFeeResult::WALLET_ERROR;
102+
current_result = Result::WALLET_ERROR;
101103
return;
102104
}
103105

104106
// check that original tx consists entirely of our inputs
105107
// if not, we can't bump the fee, because the wallet has no way of knowing the value of the other inputs (thus the fee)
106108
if (!wallet->IsAllFromMe(*wtx.tx, ISMINE_SPENDABLE)) {
107109
errors.push_back("Transaction contains inputs that don't belong to this wallet");
108-
current_result = BumpFeeResult::WALLET_ERROR;
110+
current_result = Result::WALLET_ERROR;
109111
return;
110112
}
111113

@@ -116,15 +118,15 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
116118
if (wallet->IsChange(wtx.tx->vout[i])) {
117119
if (nOutput != -1) {
118120
errors.push_back("Transaction has multiple change outputs");
119-
current_result = BumpFeeResult::WALLET_ERROR;
121+
current_result = Result::WALLET_ERROR;
120122
return;
121123
}
122124
nOutput = i;
123125
}
124126
}
125127
if (nOutput == -1) {
126128
errors.push_back("Transaction does not have a change output");
127-
current_result = BumpFeeResult::WALLET_ERROR;
129+
current_result = Result::WALLET_ERROR;
128130
return;
129131
}
130132

@@ -133,7 +135,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
133135
const int64_t maxNewTxSize = CalculateMaximumSignedTxSize(*wtx.tx, wallet);
134136
if (maxNewTxSize < 0) {
135137
errors.push_back("Transaction contains inputs that cannot be signed");
136-
current_result = BumpFeeResult::INVALID_ADDRESS_OR_KEY;
138+
current_result = Result::INVALID_ADDRESS_OR_KEY;
137139
return;
138140
}
139141

@@ -154,14 +156,14 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
154156
if (total_fee < minTotalFee) {
155157
errors.push_back(strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
156158
FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(::incrementalRelayFee.GetFee(maxNewTxSize))));
157-
current_result = BumpFeeResult::INVALID_PARAMETER;
159+
current_result = Result::INVALID_PARAMETER;
158160
return;
159161
}
160162
CAmount requiredFee = GetRequiredFee(maxNewTxSize);
161163
if (total_fee < requiredFee) {
162164
errors.push_back(strprintf("Insufficient totalFee (cannot be less than required fee %s)",
163165
FormatMoney(requiredFee)));
164-
current_result = BumpFeeResult::INVALID_PARAMETER;
166+
current_result = Result::INVALID_PARAMETER;
165167
return;
166168
}
167169
new_fee = total_fee;
@@ -185,7 +187,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
185187
if (new_fee > maxTxFee) {
186188
errors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
187189
FormatMoney(new_fee), FormatMoney(maxTxFee)));
188-
current_result = BumpFeeResult::WALLET_ERROR;
190+
current_result = Result::WALLET_ERROR;
189191
return;
190192
}
191193

@@ -203,7 +205,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
203205
FormatMoney(minMempoolFeeRate.GetFeePerK()),
204206
FormatMoney(minMempoolFeeRate.GetFee(maxNewTxSize)),
205207
FormatMoney(minMempoolFeeRate.GetFeePerK())));
206-
current_result = BumpFeeResult::WALLET_ERROR;
208+
current_result = Result::WALLET_ERROR;
207209
return;
208210
}
209211

@@ -215,7 +217,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
215217
CTxOut* poutput = &(mtx.vout[nOutput]);
216218
if (poutput->nValue < nDelta) {
217219
errors.push_back("Change output is too small to bump the fee");
218-
current_result = BumpFeeResult::WALLET_ERROR;
220+
current_result = Result::WALLET_ERROR;
219221
return;
220222
}
221223

@@ -234,7 +236,7 @@ FeeBumper::FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinCo
234236
}
235237
}
236238

237-
current_result = BumpFeeResult::OK;
239+
current_result = Result::OK;
238240
}
239241

240242
bool FeeBumper::signTransaction(CWallet *wallet)
@@ -245,13 +247,13 @@ bool FeeBumper::signTransaction(CWallet *wallet)
245247
bool FeeBumper::commit(CWallet *wallet)
246248
{
247249
AssertLockHeld(wallet->cs_wallet);
248-
if (!errors.empty() || current_result != BumpFeeResult::OK) {
250+
if (!errors.empty() || current_result != Result::OK) {
249251
return false;
250252
}
251253
auto it = txid.IsNull() ? wallet->mapWallet.end() : wallet->mapWallet.find(txid);
252254
if (it == wallet->mapWallet.end()) {
253255
errors.push_back("Invalid or non-wallet transaction id");
254-
current_result = BumpFeeResult::MISC_ERROR;
256+
current_result = Result::MISC_ERROR;
255257
return false;
256258
}
257259
CWalletTx& oldWtx = it->second;
@@ -295,3 +297,5 @@ bool FeeBumper::commit(CWallet *wallet)
295297
return true;
296298
}
297299

300+
} // namespace feebumper
301+

src/wallet/feebumper.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class uint256;
1313
class CCoinControl;
1414
enum class FeeEstimateMode;
1515

16-
enum class BumpFeeResult
16+
namespace feebumper {
17+
18+
enum class Result
1719
{
1820
OK,
1921
INVALID_ADDRESS_OR_KEY,
@@ -27,7 +29,7 @@ class FeeBumper
2729
{
2830
public:
2931
FeeBumper(const CWallet *wallet, const uint256 txid_in, const CCoinControl& coin_control, CAmount total_fee);
30-
BumpFeeResult getResult() const { return current_result; }
32+
Result getResult() const { return current_result; }
3133
const std::vector<std::string>& getErrors() const { return errors; }
3234
CAmount getOldFee() const { return old_fee; }
3335
CAmount getNewFee() const { return new_fee; }
@@ -53,9 +55,11 @@ class FeeBumper
5355
uint256 bumped_txid;
5456
CMutableTransaction mtx;
5557
std::vector<std::string> errors;
56-
BumpFeeResult current_result;
58+
Result current_result;
5759
CAmount old_fee;
5860
CAmount new_fee;
5961
};
6062

63+
} // namespace feebumper
64+
6165
#endif // BITCOIN_WALLET_FEEBUMPER_H

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,21 +3125,21 @@ UniValue bumpfee(const JSONRPCRequest& request)
31253125
LOCK2(cs_main, pwallet->cs_wallet);
31263126
EnsureWalletIsUnlocked(pwallet);
31273127

3128-
FeeBumper feeBump(pwallet, hash, coin_control, totalFee);
3129-
BumpFeeResult res = feeBump.getResult();
3130-
if (res != BumpFeeResult::OK)
3128+
feebumper::FeeBumper feeBump(pwallet, hash, coin_control, totalFee);
3129+
feebumper::Result res = feeBump.getResult();
3130+
if (res != feebumper::Result::OK)
31313131
{
31323132
switch(res) {
3133-
case BumpFeeResult::INVALID_ADDRESS_OR_KEY:
3133+
case feebumper::Result::INVALID_ADDRESS_OR_KEY:
31343134
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, feeBump.getErrors()[0]);
31353135
break;
3136-
case BumpFeeResult::INVALID_REQUEST:
3136+
case feebumper::Result::INVALID_REQUEST:
31373137
throw JSONRPCError(RPC_INVALID_REQUEST, feeBump.getErrors()[0]);
31383138
break;
3139-
case BumpFeeResult::INVALID_PARAMETER:
3139+
case feebumper::Result::INVALID_PARAMETER:
31403140
throw JSONRPCError(RPC_INVALID_PARAMETER, feeBump.getErrors()[0]);
31413141
break;
3142-
case BumpFeeResult::WALLET_ERROR:
3142+
case feebumper::Result::WALLET_ERROR:
31433143
throw JSONRPCError(RPC_WALLET_ERROR, feeBump.getErrors()[0]);
31443144
break;
31453145
default:

0 commit comments

Comments
 (0)