Skip to content

Commit 343feec

Browse files
committed
Merge pull request #4368
75c82d4 Move coins.cpp and keystore.cpp to libbitcoin_common (Wladimir J. van der Laan) 84ce18c Remove unnecessary dependencies for bitcoin-cli (Wladimir J. van der Laan) 14f888c Move network-time related functions to timedata.cpp/h (Wladimir J. van der Laan)
2 parents 208bf5b + 75c82d4 commit 343feec

29 files changed

+353
-173
lines changed

src/Makefile.am

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ endif
2020
BITCOIN_CONFIG_INCLUDES=-I$(builddir)/config
2121
BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)
2222

23+
LIBBITCOIN_SERVER=libbitcoin_server.a
24+
LIBBITCOIN_WALLET=libbitcoin_wallet.a
25+
LIBBITCOIN_COMMON=libbitcoin_common.a
26+
LIBBITCOIN_CLI=libbitcoin_cli.a
27+
LIBBITCOIN_UTIL=libbitcoin_util.a
28+
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
29+
LIBBITCOINQT=qt/libbitcoinqt.a
30+
2331
noinst_LIBRARIES = \
2432
libbitcoin_server.a \
2533
libbitcoin_common.a \
2634
libbitcoin_cli.a \
35+
libbitcoin_util.a \
2736
crypto/libbitcoin_crypto.a
2837
if ENABLE_WALLET
2938
BITCOIN_INCLUDES += $(BDB_CPPFLAGS)
@@ -50,6 +59,7 @@ BITCOIN_CORE_H = \
5059
base58.h \
5160
bloom.h \
5261
chainparams.h \
62+
chainparamsbase.h \
5363
checkpoints.h \
5464
checkqueue.h \
5565
clientversion.h \
@@ -80,6 +90,7 @@ BITCOIN_CORE_H = \
8090
serialize.h \
8191
sync.h \
8292
threadsafety.h \
93+
timedata.h \
8394
tinyformat.h \
8495
txdb.h \
8596
txmempool.h \
@@ -106,17 +117,16 @@ obj/build.h: FORCE
106117
@$(MKDIR_P) $(builddir)/obj
107118
@$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \
108119
$(abs_top_srcdir)
109-
libbitcoin_common_a-version.$(OBJEXT): obj/build.h
120+
libbitcoin_util_a-version.$(OBJEXT): obj/build.h
110121

122+
# server: shared between bitcoind and bitcoin-qt
111123
libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES)
112124
libbitcoin_server_a_SOURCES = \
113125
addrman.cpp \
114126
alert.cpp \
115127
bloom.cpp \
116128
checkpoints.cpp \
117-
coins.cpp \
118129
init.cpp \
119-
keystore.cpp \
120130
leveldbwrapper.cpp \
121131
main.cpp \
122132
miner.cpp \
@@ -129,11 +139,14 @@ libbitcoin_server_a_SOURCES = \
129139
rpcnet.cpp \
130140
rpcrawtransaction.cpp \
131141
rpcserver.cpp \
142+
timedata.cpp \
132143
txdb.cpp \
133144
txmempool.cpp \
134145
$(JSON_H) \
135146
$(BITCOIN_CORE_H)
136147

148+
# wallet: shared between bitcoind and bitcoin-qt, but only linked
149+
# when wallet enabled
137150
libbitcoin_wallet_a_CPPFLAGS = $(BITCOIN_INCLUDES)
138151
libbitcoin_wallet_a_SOURCES = \
139152
db.cpp \
@@ -144,6 +157,7 @@ libbitcoin_wallet_a_SOURCES = \
144157
walletdb.cpp \
145158
$(BITCOIN_CORE_H)
146159

160+
# crypto primitives library
147161
crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES)
148162
crypto_libbitcoin_crypto_a_SOURCES = \
149163
crypto/sha1.cpp \
@@ -154,18 +168,29 @@ crypto_libbitcoin_crypto_a_SOURCES = \
154168
crypto/sha1.h \
155169
crypto/ripemd160.h
156170

171+
# common: shared between bitcoind, and bitcoin-qt and non-server tools
157172
libbitcoin_common_a_CPPFLAGS = $(BITCOIN_INCLUDES)
158173
libbitcoin_common_a_SOURCES = \
159-
base58.cpp \
160174
allocators.cpp \
175+
base58.cpp \
161176
chainparams.cpp \
177+
coins.cpp \
162178
core.cpp \
163179
hash.cpp \
164180
key.cpp \
181+
keystore.cpp \
165182
netbase.cpp \
166183
protocol.cpp \
167-
rpcprotocol.cpp \
168184
script.cpp \
185+
$(BITCOIN_CORE_H)
186+
187+
# util: shared between all executables.
188+
# This library *must* be included to make sure that the glibc
189+
# backward-compatibility objects and their sanity checks are linked.
190+
libbitcoin_util_a_CPPFLAGS = $(BITCOIN_INCLUDES)
191+
libbitcoin_util_a_SOURCES = \
192+
chainparamsbase.cpp \
193+
rpcprotocol.cpp \
169194
sync.cpp \
170195
util.cpp \
171196
version.cpp \
@@ -174,22 +199,24 @@ libbitcoin_common_a_SOURCES = \
174199
$(BITCOIN_CORE_H)
175200

176201
if GLIBC_BACK_COMPAT
177-
libbitcoin_common_a_SOURCES += compat/glibc_compat.cpp
178-
libbitcoin_common_a_SOURCES += compat/glibcxx_compat.cpp
202+
libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
203+
libbitcoin_util_a_SOURCES += compat/glibcxx_compat.cpp
179204
endif
180205

206+
# cli: shared between bitcoin-cli and bitcoin-qt
181207
libbitcoin_cli_a_SOURCES = \
182208
rpcclient.cpp \
183209
$(BITCOIN_CORE_H)
184210

185-
nodist_libbitcoin_common_a_SOURCES = $(srcdir)/obj/build.h
211+
nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
186212
#
187213

188214
# bitcoind binary #
189215
bitcoind_LDADD = \
190-
libbitcoin_server.a \
191-
libbitcoin_common.a \
192-
crypto/libbitcoin_crypto.a \
216+
$(LIBBITCOIN_SERVER) \
217+
$(LIBBITCOIN_COMMON) \
218+
$(LIBBITCOIN_UTIL) \
219+
$(LIBBITCOIN_CRYPTO) \
193220
$(LIBLEVELDB) \
194221
$(LIBMEMENV)
195222
if ENABLE_WALLET
@@ -207,11 +234,13 @@ bitcoind_CPPFLAGS = $(BITCOIN_INCLUDES)
207234

208235
# bitcoin-cli binary #
209236
bitcoin_cli_LDADD = \
210-
libbitcoin_cli.a \
211-
libbitcoin_common.a \
212-
crypto/libbitcoin_crypto.a \
237+
$(LIBBITCOIN_CLI) \
238+
$(LIBBITCOIN_COMMON) \
239+
$(LIBBITCOIN_UTIL) \
240+
$(LIBBITCOIN_CRYPTO) \
213241
$(BOOST_LIBS)
214-
bitcoin_cli_SOURCES = bitcoin-cli.cpp
242+
bitcoin_cli_SOURCES = \
243+
bitcoin-cli.cpp
215244
bitcoin_cli_CPPFLAGS = $(BITCOIN_INCLUDES)
216245
#
217246

@@ -242,13 +271,6 @@ clean-local:
242271
@test -f $(PROTOC)
243272
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $(<D) $<)
244273

245-
LIBBITCOIN_SERVER=libbitcoin_server.a
246-
LIBBITCOIN_WALLET=libbitcoin_wallet.a
247-
LIBBITCOIN_COMMON=libbitcoin_common.a
248-
LIBBITCOIN_CLI=libbitcoin_cli.a
249-
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
250-
LIBBITCOINQT=qt/libbitcoinqt.a
251-
252274
if ENABLE_TESTS
253275
include Makefile.test.include
254276
endif

src/Makefile.qt.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ qt_bitcoin_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER)
355355
if ENABLE_WALLET
356356
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
357357
endif
358-
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
358+
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
359359
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
360360
qt_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)
361361

@@ -364,7 +364,7 @@ QT_QM=$(QT_TS:.ts=.qm)
364364

365365
.SECONDARY: $(QT_QM)
366366

367-
qt/bitcoinstrings.cpp: $(libbitcoin_server_a_SOURCES) $(libbitcoin_common_a_SOURCES) $(libbitcoin_cli_a_SOURCES)
367+
qt/bitcoinstrings.cpp: $(libbitcoin_server_a_SOURCES) $(libbitcoin_common_a_SOURCES) $(libbitcoin_cli_a_SOURCES) $(libbitcoin_util_a_SOURCES)
368368
@test -n $(XGETTEXT) || echo "xgettext is required for updating translations"
369369
$(AM_V_GEN) cd $(top_srcdir); XGETTEXT=$(XGETTEXT) share/qt/extract_strings_qt.py
370370

src/Makefile.qttest.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER)
3030
if ENABLE_WALLET
3131
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
3232
endif
33-
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) \
33+
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) \
3434
$(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
3535
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
3636
qt_test_test_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)

src/Makefile.test.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ endif
6363

6464
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
6565
test_test_bitcoin_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS)
66-
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
66+
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
6767
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
6868
if ENABLE_WALLET
6969
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)

src/addrman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "netbase.h"
99
#include "protocol.h"
1010
#include "sync.h"
11+
#include "timedata.h"
1112
#include "util.h"
1213

1314
#include <map>

src/alert.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "chainparams.h"
99
#include "key.h"
1010
#include "net.h"
11+
#include "timedata.h"
1112
#include "ui_interface.h"
1213
#include "util.h"
1314

src/bitcoin-cli.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "rpcclient.h"
99
#include "rpcprotocol.h"
1010
#include "ui_interface.h" /* for _(...) */
11-
#include "chainparams.h"
11+
#include "chainparamsbase.h"
1212

1313
#include <boost/filesystem/operations.hpp>
1414

@@ -60,12 +60,11 @@ static bool AppInitRPC(int argc, char* argv[])
6060
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
6161
return false;
6262
}
63-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
64-
if (!SelectParamsFromCommandLine()) {
63+
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
64+
if (!SelectBaseParamsFromCommandLine()) {
6565
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
6666
return false;
6767
}
68-
6968
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
7069
{
7170
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
@@ -104,7 +103,7 @@ Object CallRPC(const string& strMethod, const Array& params)
104103

105104
bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
106105
do {
107-
bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort())));
106+
bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(BaseParams().RPCPort())));
108107
if (fConnected) break;
109108
if (fWait)
110109
MilliSleep(1000);

src/chainparams.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ unsigned int pnSeed[] =
9999
class CMainParams : public CChainParams {
100100
public:
101101
CMainParams() {
102-
networkID = CChainParams::MAIN;
102+
networkID = CBaseChainParams::MAIN;
103103
strNetworkID = "main";
104104
// The message start string is designed to be unlikely to occur in normal data.
105105
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -110,7 +110,6 @@ class CMainParams : public CChainParams {
110110
pchMessageStart[3] = 0xd9;
111111
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
112112
nDefaultPort = 8333;
113-
nRPCPort = 8332;
114113
bnProofOfWorkLimit = ~uint256(0) >> 32;
115114
nSubsidyHalvingInterval = 210000;
116115
nEnforceBlockUpgradeMajority = 750;
@@ -191,7 +190,7 @@ static CMainParams mainParams;
191190
class CTestNetParams : public CMainParams {
192191
public:
193192
CTestNetParams() {
194-
networkID = CChainParams::TESTNET;
193+
networkID = CBaseChainParams::TESTNET;
195194
strNetworkID = "test";
196195
// The message start string is designed to be unlikely to occur in normal data.
197196
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -202,14 +201,12 @@ class CTestNetParams : public CMainParams {
202201
pchMessageStart[3] = 0x07;
203202
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
204203
nDefaultPort = 18333;
205-
nRPCPort = 18332;
206204
nEnforceBlockUpgradeMajority = 51;
207205
nRejectBlockOutdatedMajority = 75;
208206
nToCheckBlockUpgradeMajority = 100;
209207
nMinerThreads = 0;
210208
nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
211209
nTargetSpacing = 10 * 60;
212-
strDataDir = "testnet3";
213210

214211
// Modify the testnet genesis block so the timestamp is valid for a later start.
215212
genesis.nTime = 1296688602;
@@ -245,7 +242,7 @@ static CTestNetParams testNetParams;
245242
class CRegTestParams : public CTestNetParams {
246243
public:
247244
CRegTestParams() {
248-
networkID = CChainParams::REGTEST;
245+
networkID = CBaseChainParams::REGTEST;
249246
strNetworkID = "regtest";
250247
pchMessageStart[0] = 0xfa;
251248
pchMessageStart[1] = 0xbf;
@@ -264,7 +261,6 @@ class CRegTestParams : public CTestNetParams {
264261
genesis.nNonce = 2;
265262
hashGenesisBlock = genesis.GetHash();
266263
nDefaultPort = 18444;
267-
strDataDir = "regtest";
268264
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
269265

270266
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
@@ -279,21 +275,23 @@ class CRegTestParams : public CTestNetParams {
279275
};
280276
static CRegTestParams regTestParams;
281277

282-
static CChainParams *pCurrentParams = &mainParams;
278+
static CChainParams *pCurrentParams = 0;
283279

284280
const CChainParams &Params() {
281+
assert(pCurrentParams);
285282
return *pCurrentParams;
286283
}
287284

288-
void SelectParams(CChainParams::Network network) {
285+
void SelectParams(CBaseChainParams::Network network) {
286+
SelectBaseParams(network);
289287
switch (network) {
290-
case CChainParams::MAIN:
288+
case CBaseChainParams::MAIN:
291289
pCurrentParams = &mainParams;
292290
break;
293-
case CChainParams::TESTNET:
291+
case CBaseChainParams::TESTNET:
294292
pCurrentParams = &testNetParams;
295293
break;
296-
case CChainParams::REGTEST:
294+
case CBaseChainParams::REGTEST:
297295
pCurrentParams = &regTestParams;
298296
break;
299297
default:
@@ -303,19 +301,9 @@ void SelectParams(CChainParams::Network network) {
303301
}
304302

305303
bool SelectParamsFromCommandLine() {
306-
bool fRegTest = GetBoolArg("-regtest", false);
307-
bool fTestNet = GetBoolArg("-testnet", false);
308-
309-
if (fTestNet && fRegTest) {
304+
if (!SelectBaseParamsFromCommandLine())
310305
return false;
311-
}
312306

313-
if (fRegTest) {
314-
SelectParams(CChainParams::REGTEST);
315-
} else if (fTestNet) {
316-
SelectParams(CChainParams::TESTNET);
317-
} else {
318-
SelectParams(CChainParams::MAIN);
319-
}
307+
SelectParams(BaseParams().NetworkID());
320308
return true;
321309
}

0 commit comments

Comments
 (0)