Skip to content

Commit 91a25d1

Browse files
committed
[build] Add several util units
Adds the following util units and adds them to libbitcoin_util: - `util/url.cpp` takes `urlDecode` from `httpserver.cpp` - `util/error.cpp` takes `TransactionErrorString` from `node/transaction.cpp` and `AmountHighWarn` and `AmountErrMsg` from `ui_interface.cpp` - `util/fees.cpp` takes `StringForFeeReason` and `FeeModeFromString` from `policy/fees.cpp` - `util/rbf.cpp` takes `SignalsOptInRBF` from `policy/rbf.cpp` - 'util/validation.cpp` takes `FormatStateMessage` and `strMessageMagic` from 'validation.cpp`
1 parent 9951786 commit 91a25d1

39 files changed

+282
-143
lines changed

src/Makefile.am

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ BITCOIN_CORE_H = \
203203
undo.h \
204204
util/bip32.h \
205205
util/bytevectorhash.h \
206+
util/error.h \
207+
util/fees.h \
206208
util/system.h \
207209
util/memory.h \
208210
util/moneystr.h \
211+
util/rbf.h \
209212
util/time.h \
213+
util/url.h \
214+
util/validation.h \
210215
validation.h \
211216
validationinterface.h \
212217
versionbits.h \
@@ -471,10 +476,15 @@ libbitcoin_util_a_SOURCES = \
471476
threadinterrupt.cpp \
472477
util/bip32.cpp \
473478
util/bytevectorhash.cpp \
479+
util/error.cpp \
480+
util/fees.cpp \
474481
util/system.cpp \
475482
util/moneystr.cpp \
483+
util/rbf.cpp \
476484
util/strencodings.cpp \
477485
util/time.cpp \
486+
util/url.cpp \
487+
util/validation.cpp \
478488
$(BITCOIN_CORE_H)
479489

480490
if GLIBC_BACK_COMPAT

src/bitcoin-tx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <script/script.h>
1919
#include <script/sign.h>
2020
#include <univalue.h>
21+
#include <util/rbf.h>
2122
#include <util/system.h>
2223
#include <util/moneystr.h>
2324
#include <util/strencodings.h>

src/httpserver.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,3 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
655655
pathHandlers.erase(i);
656656
}
657657
}
658-
659-
std::string urlDecode(const std::string &urlEncoded) {
660-
std::string res;
661-
if (!urlEncoded.empty()) {
662-
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr);
663-
if (decoded) {
664-
res = std::string(decoded);
665-
free(decoded);
666-
}
667-
}
668-
return res;
669-
}

src/httpserver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,4 @@ class HTTPEvent
148148
struct event* ev;
149149
};
150150

151-
std::string urlDecode(const std::string &urlEncoded);
152-
153151
#endif // BITCOIN_HTTPSERVER_H

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <ui_interface.h>
4848
#include <util/system.h>
4949
#include <util/moneystr.h>
50+
#include <util/validation.h>
5051
#include <validationinterface.h>
5152
#include <warnings.h>
5253
#include <walletinitinterface.h>

src/miner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <timedata.h>
2424
#include <util/moneystr.h>
2525
#include <util/system.h>
26+
#include <util/validation.h>
2627
#include <validationinterface.h>
2728

2829
#include <algorithm>

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <util/system.h>
3030
#include <util/moneystr.h>
3131
#include <util/strencodings.h>
32+
#include <util/validation.h>
3233

3334
#include <memory>
3435

src/node/transaction.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,13 @@
66
#include <consensus/validation.h>
77
#include <net.h>
88
#include <txmempool.h>
9+
#include <util/validation.h>
910
#include <validation.h>
1011
#include <validationinterface.h>
1112
#include <node/transaction.h>
1213

1314
#include <future>
1415

15-
std::string TransactionErrorString(const TransactionError err)
16-
{
17-
switch (err) {
18-
case TransactionError::OK:
19-
return "No error";
20-
case TransactionError::MISSING_INPUTS:
21-
return "Missing inputs";
22-
case TransactionError::ALREADY_IN_CHAIN:
23-
return "Transaction already in block chain";
24-
case TransactionError::P2P_DISABLED:
25-
return "Peer-to-peer functionality missing or disabled";
26-
case TransactionError::MEMPOOL_REJECTED:
27-
return "Transaction rejected by AcceptToMemoryPool";
28-
case TransactionError::MEMPOOL_ERROR:
29-
return "AcceptToMemoryPool failed";
30-
case TransactionError::INVALID_PSBT:
31-
return "PSBT is not sane";
32-
case TransactionError::PSBT_MISMATCH:
33-
return "PSBTs not compatible (different transactions)";
34-
case TransactionError::SIGHASH_MISMATCH:
35-
return "Specified sighash value does not match existing value";
36-
// no default case, so the compiler can warn about missing cases
37-
}
38-
assert(false);
39-
}
40-
4116
TransactionError BroadcastTransaction(const CTransactionRef tx, uint256& hashTx, std::string& err_string, const CAmount& highfee)
4217
{
4318
std::promise<void> promise;

src/node/transaction.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@
88
#include <attributes.h>
99
#include <primitives/transaction.h>
1010
#include <uint256.h>
11-
12-
enum class TransactionError {
13-
OK, //!< No error
14-
MISSING_INPUTS,
15-
ALREADY_IN_CHAIN,
16-
P2P_DISABLED,
17-
MEMPOOL_REJECTED,
18-
MEMPOOL_ERROR,
19-
INVALID_PSBT,
20-
PSBT_MISMATCH,
21-
SIGHASH_MISMATCH,
22-
};
23-
24-
std::string TransactionErrorString(const TransactionError error);
11+
#include <util/error.h>
2512

2613
/**
2714
* Broadcast a transaction

src/policy/fees.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,6 @@ std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon) {
2727
return horizon_string->second;
2828
}
2929

30-
std::string StringForFeeReason(FeeReason reason) {
31-
static const std::map<FeeReason, std::string> fee_reason_strings = {
32-
{FeeReason::NONE, "None"},
33-
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
34-
{FeeReason::FULL_ESTIMATE, "Target 85% Threshold"},
35-
{FeeReason::DOUBLE_ESTIMATE, "Double Target 95% Threshold"},
36-
{FeeReason::CONSERVATIVE, "Conservative Double Target longer horizon"},
37-
{FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},
38-
{FeeReason::PAYTXFEE, "PayTxFee set"},
39-
{FeeReason::FALLBACK, "Fallback fee"},
40-
{FeeReason::REQUIRED, "Minimum Required Fee"},
41-
{FeeReason::MAXTXFEE, "MaxTxFee limit"}
42-
};
43-
auto reason_string = fee_reason_strings.find(reason);
44-
45-
if (reason_string == fee_reason_strings.end()) return "Unknown";
46-
47-
return reason_string->second;
48-
}
49-
50-
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
51-
static const std::map<std::string, FeeEstimateMode> fee_modes = {
52-
{"UNSET", FeeEstimateMode::UNSET},
53-
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
54-
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
55-
};
56-
auto mode = fee_modes.find(mode_string);
57-
58-
if (mode == fee_modes.end()) return false;
59-
60-
fee_estimate_mode = mode->second;
61-
return true;
62-
}
63-
6430
/**
6531
* We will instantiate an instance of this class to track transactions that were
6632
* included in a block. We will lump transactions into a bucket according to their

0 commit comments

Comments
 (0)