Skip to content

Commit

Permalink
Split up util.cpp/h
Browse files Browse the repository at this point in the history
Split up util.cpp/h into:

- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)

The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).

Breaks dependency of sha256.cpp on all the things pulled in by util.
  • Loading branch information
laanwj committed Aug 26, 2014
1 parent f841aa2 commit ad49c25
Show file tree
Hide file tree
Showing 57 changed files with 875 additions and 734 deletions.
6 changes: 6 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ BITCOIN_CORE_H = \
ui_interface.h \
uint256.h \
util.h \
utilstrencodings.h \
utilmoneystr.h \
utiltime.h \
version.h \
walletdb.h \
wallet.h \
Expand Down Expand Up @@ -219,6 +222,9 @@ libbitcoin_util_a_SOURCES = \
sync.cpp \
uint256.cpp \
util.cpp \
utilstrencodings.cpp \
utilmoneystr.cpp \
utiltime.cpp \
version.cpp \
$(BITCOIN_CORE_H)

Expand Down
1 change: 1 addition & 0 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <boost/thread.hpp>

using namespace std;

Expand Down
1 change: 1 addition & 0 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "rpcclient.h"
#include "rpcprotocol.h"
#include "chainparamsbase.h"
#include "utilstrencodings.h"
#include "version.h"

#include <boost/filesystem/operations.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "base58.h"
#include "util.h"
#include "utilmoneystr.h"
#include "core.h"
#include "main.h" // for MAX_BLOCK_SIZE
#include "keystore.h"
Expand Down
1 change: 1 addition & 0 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/thread.hpp>

/* Introduction text for doxygen: */

Expand Down
1 change: 1 addition & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "core.h"
#include "serialize.h"
#include "util.h"
#include "utilmoneystr.h"
#include "base58.h"

using namespace std;
Expand Down
1 change: 1 addition & 0 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "crypter.h"

#include "script.h"
#include "util.h"

#include <string>
#include <vector>
Expand Down
2 changes: 2 additions & 0 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "hash.h"
#include "protocol.h"
#include "util.h"
#include "utilstrencodings.h"

#include <stdint.h>

Expand All @@ -17,6 +18,7 @@
#endif

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <boost/version.hpp>
#include <openssl/rand.h>

Expand Down
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "txdb.h"
#include "ui_interface.h"
#include "util.h"
#include "utilmoneystr.h"
#ifdef ENABLE_WALLET
#include "db.h"
#include "wallet.h"
Expand All @@ -36,6 +37,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>

using namespace boost;
Expand Down
1 change: 1 addition & 0 deletions src/keystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "crypter.h"
#include "key.h"
#include "script.h"
#include "util.h"

#include <boost/foreach.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/thread.hpp>

using namespace std;
using namespace boost;
Expand Down
6 changes: 4 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <inttypes.h>

#include "miner.h"

#include "core.h"
#include "hash.h"
#include "main.h"
#include "net.h"
#include "pow.h"
#include "util.h"
#include "utilmoneystr.h"
#ifdef ENABLE_WALLET
#include "wallet.h"
#endif

#include <boost/thread.hpp>

using namespace std;

//////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>

// Dump addresses to peers.dat every 15 minutes (900s)
#define DUMP_ADDRESSES_INTERVAL 900
Expand Down
3 changes: 2 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "random.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"
#include "utilstrencodings.h"

#include <deque>
#include <stdint.h>
Expand All @@ -25,6 +25,7 @@
#include <arpa/inet.h>
#endif

#include <boost/filesystem/path.hpp>
#include <boost/foreach.hpp>
#include <boost/signals2/signal.hpp>

Expand Down
2 changes: 2 additions & 0 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "sync.h"
#include "uint256.h"
#include "util.h"
#include "utilstrencodings.h"

#ifdef HAVE_GETADDRINFO_A
#include <netdb.h>
Expand All @@ -27,6 +28,7 @@

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
#include <boost/thread.hpp>

#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
Expand Down
1 change: 1 addition & 0 deletions src/noui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ui_interface.h"
#include "util.h"

#include <cstdio>
#include <stdint.h>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "core.h"
#include "main.h"
#include "uint256.h"
#include "util.h"

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
{
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdint.h>

#include <boost/filesystem/operations.hpp>
#include <boost/thread.hpp>
#include <QApplication>
#include <QDebug>
#include <QLibraryInfo>
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

#include "init.h"
#include "util.h"
#include "ui_interface.h"

#include <iostream>
Expand Down
1 change: 1 addition & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "main.h"
#include "net.h"
#include "ui_interface.h"
#include "util.h"

#include <stdint.h>

Expand Down
1 change: 1 addition & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "wallet.h" // for CWallet::minTxFee
#endif

#include <boost/thread.hpp>
#include <QDir>
#include <QIntValidator>
#include <QLocale>
Expand Down
1 change: 1 addition & 0 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "base58.h"
#include "ui_interface.h"
#include "util.h"
#include "wallet.h"

#include <cstdlib>
Expand Down
1 change: 1 addition & 0 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "transactionrecord.h"
#include "timedata.h"
#include "ui_interface.h"
#include "util.h"
#include "wallet.h"

#include <stdint.h>
Expand Down
3 changes: 2 additions & 1 deletion src/qt/utilitydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "guiutil.h"

#include "init.h"
#include "util.h"
#include "version.h"

#include <stdio.h>

#include <QLabel>
#include <QRegExp>
#include <QVBoxLayout>
Expand Down
4 changes: 3 additions & 1 deletion src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#ifdef WIN32
#include "compat.h" // for Windows API
#endif
#include "serialize.h" // for begin_ptr(vec)
#include "util.h" // for LogPrint()
#include "utilstrencodings.h" // for GetTime()

#ifndef WIN32
#include <sys/time.h>
#endif

#include <limits>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
Expand Down
1 change: 1 addition & 0 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "main.h"
#include "rpcserver.h"
#include "sync.h"
#include "util.h"

#include <stdint.h>

Expand Down
2 changes: 2 additions & 0 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "init.h"
#include "main.h"
#include "sync.h"
#include "utiltime.h"
#include "util.h"
#include "wallet.h"

#include <fstream>
Expand Down
1 change: 1 addition & 0 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "miner.h"
#include "pow.h"
#include "core_io.h"
#include "util.h"
#ifdef ENABLE_WALLET
#include "db.h"
#include "wallet.h"
Expand Down
3 changes: 3 additions & 0 deletions src/rpcprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "rpcprotocol.h"

#include "util.h"
#include "tinyformat.h"
#include "utilstrencodings.h"
#include "utiltime.h"
#include "version.h"

#include <stdint.h>
Expand Down
6 changes: 6 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "json/json_spirit_writer_template.h"

using namespace boost;
Expand Down Expand Up @@ -82,6 +83,11 @@ void RPCTypeCheck(const Object& o,
}
}

static inline int64_t roundint64(double d)
{
return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
}

int64_t AmountFromValue(const Value& value)
{
double dAmount = value.get_real();
Expand Down
3 changes: 2 additions & 1 deletion src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include "util.h"

#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/thread.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple.hpp>

using namespace std;
using namespace boost;
Expand Down
3 changes: 2 additions & 1 deletion src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define H_BITCOIN_SCRIPT

#include "key.h"
#include "util.h"
#include "utilstrencodings.h"
#include "tinyformat.h"

#include <stdexcept>
#include <stdint.h>
Expand Down
1 change: 1 addition & 0 deletions src/test/DoS_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "pow.h"
#include "script.h"
#include "serialize.h"
#include "util.h"

#include <stdint.h>

Expand Down
1 change: 1 addition & 0 deletions src/test/alert_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "serialize.h"
#include "util.h"
#include "utilstrencodings.h"
#include "version.h"

#include <fstream>
Expand Down
2 changes: 2 additions & 0 deletions src/test/allocator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "util.h"

#include "allocators.h"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(allocator_tests)
Expand Down
2 changes: 1 addition & 1 deletion src/test/base32_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "util.h"
#include "utilstrencodings.h"

#include <boost/test/unit_test.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/test/base64_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "util.h"
#include "utilstrencodings.h"

#include <boost/test/unit_test.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/test/checkblock_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


#include "main.h"
#include "utiltime.h"

#include <cstdio>

Expand Down

0 comments on commit ad49c25

Please sign in to comment.