From 0444112b743602ae2182832603fb9ac603907c9a Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Mon, 1 Jun 2015 13:41:12 -0400 Subject: [PATCH] Applied JJ's patch to v0.10.2 --- Makefile.am | 5 +++++ configure.ac | 31 +++++++++++++++++++++++++-- src/Makefile.am | 19 +++++++++++++++-- src/Makefile.daemon.include | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/bitcoin-main.cpp | 15 +++++++++++++ src/bitcoind.cpp | 22 +------------------ src/bitcoind.h | 25 ++++++++++++++++++++++ src/init.h | 8 +++++++ src/leveldbwrapper.h | 6 ++---- src/rpcdump.cpp | 7 +++--- src/rpcwallet.cpp | 1 + src/rpcwallet.h | 17 +++++++++++++++ src/wallet.h | 3 +-- 13 files changed, 176 insertions(+), 35 deletions(-) create mode 100644 src/Makefile.daemon.include create mode 100644 src/bitcoin-main.cpp create mode 100644 src/bitcoind.h create mode 100644 src/rpcwallet.h diff --git a/Makefile.am b/Makefile.am index b51f477..58241df 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,6 +35,11 @@ COVERAGE_INFO = baseline_filtered_combined.info baseline.info block_test.info \ baseline_filtered.info block_test_filtered.info \ leveldb_baseline_filtered.info test_bitcoin_coverage.info test_bitcoin.info +if ENABLE_DAEMONLIB +all: + $(MAKE) -C src +endif + dist-hook: -$(MAKE) -C $(top_distdir)/src/leveldb clean -$(MAKE) -C $(top_distdir)/src/secp256k1 distclean diff --git a/configure.ac b/configure.ac index 579035f..cd20489 100644 --- a/configure.ac +++ b/configure.ac @@ -126,6 +126,12 @@ AC_ARG_ENABLE([reduce-exports], [use_reduce_exports=$enableval], [use_reduce_exports=auto]) +AC_ARG_ENABLE([daemonlib], + [AS_HELP_STRING([--enable-daemonlib], + [compile all of bitcoind as a library (default is no)])], + [use_daemonlib=$enableval], + [use_daemonlib=no]) + AC_ARG_ENABLE([ccache], [AS_HELP_STRING([--enable-ccache], [use ccache for building (default is yes if ccache is found)])], @@ -409,6 +415,9 @@ fi if test x$use_hardening != xno; then AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"]) AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"]) + if test x$use_daemonlib = xno; then + AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"]) + fi AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[ AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[ @@ -422,7 +431,7 @@ if test x$use_hardening != xno; then AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"]) AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"]) - if test x$TARGET_OS != xwindows; then + if test x$TARGET_OS != xwindows -a x$use_daemonlib = xno; then # All windows code is PIC, forcing it on just adds useless compile warnings AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"]) AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"]) @@ -440,6 +449,17 @@ if test x$use_hardening != xno; then OBJCXXFLAGS="$CXXFLAGS" fi +AC_DEFINE([ENABLE_DAEMONLIB],[0],[Enable daemonlib.]) +AM_CONDITIONAL([ENABLE_DAEMONLIB],[false]) +if test x$use_daemonlib != xno; then + AX_CHECK_COMPILE_FLAG([-fPIC],[DAEMONLIB_CXXFLAGS="$DAEMONLIB_CXXFLAGS -fPIC"]) + AC_DEFINE([ENABLE_DAEMONLIB],[1],[Enable daemonlib.]) + AM_CONDITIONAL([ENABLE_DAEMONLIB],[true]) + CXXFLAGS="$CXXFLAGS $DAEMONLIB_CXXFLAGS" + CPPFLAGS="$CPPFLAGS $DAEMONLIB_CPPFLAGS" + OBJCXXFLAGS="$CXXFLAGS" +fi + dnl this flag screws up non-darwin gcc even when the check fails. special-case it. if test x$TARGET_OS = xdarwin; then AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"]) @@ -485,7 +505,7 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ ] ) -if test x$use_reduce_exports != xno; then +if test x$use_reduce_exports != xno -a x$use_daemonlib = xno; then AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"], [ if test x$use_reduce_exports = xyes; then @@ -496,6 +516,13 @@ if test x$use_reduce_exports != xno; then ]) fi +AC_MSG_CHECKING([whether to compile as daemonlib]) +if test x$use_daemonlib != xno; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + LEVELDB_CPPFLAGS= LIBLEVELDB= LIBMEMENV= diff --git a/src/Makefile.am b/src/Makefile.am index 81b16d1..cc926e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,12 +31,14 @@ LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a LIBBITCOIN_UNIVALUE=univalue/libbitcoin_univalue.a LIBBITCOINQT=qt/libbitcoinqt.a LIBSECP256K1=secp256k1/libsecp256k1.la +LIBBITCOIND=libbitcoind.so $(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) # Make is not made aware of per-object dependencies to avoid limiting building parallelization # But to build the less dependent modules first, we manually select their order here: +if !ENABLE_DAEMONLIB EXTRA_LIBRARIES = \ crypto/libbitcoin_crypto.a \ libbitcoin_util.a \ @@ -76,6 +78,7 @@ BITCOIN_CORE_H = \ amount.h \ base58.h \ bloom.h \ + bitcoind.h \ chain.h \ chainparams.h \ chainparamsbase.h \ @@ -152,10 +155,17 @@ JSON_H = \ json/json_spirit_writer.h \ json/json_spirit_writer_template.h +else +.PHONY: FORCE +BITCOIN_INCLUDES += $(BDB_CPPFLAGS) +endif + obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj @$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \ $(abs_top_srcdir) + +if !ENABLE_DAEMONLIB libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h # server: shared between bitcoind and bitcoin-qt @@ -165,6 +175,7 @@ libbitcoin_server_a_SOURCES = \ alert.cpp \ bloom.cpp \ chain.cpp \ + bitcoind.cpp \ checkpoints.cpp \ init.cpp \ leveldbwrapper.cpp \ @@ -304,8 +315,7 @@ bitcoind_LDADD = \ if ENABLE_WALLET bitcoind_LDADD += libbitcoin_wallet.a endif -bitcoind_SOURCES = bitcoind.cpp -# +bitcoind_SOURCES = bitcoin-main.cpp if TARGET_WINDOWS bitcoind_SOURCES += bitcoind-res.rc @@ -380,6 +390,7 @@ if USE_LIBSECP256K1 libbitcoinconsensus_la_LIBADD += secp256k1/libsecp256k1.la endif endif +endif CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno @@ -405,6 +416,9 @@ clean-local: @test -f $(PROTOC) $(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $( -#include -#include +#include "bitcoind.h" /* Introduction text for doxygen: */ @@ -174,13 +164,3 @@ bool AppInit(int argc, char* argv[]) return fRet; } - -int main(int argc, char* argv[]) -{ - SetupEnvironment(); - - // Connect bitcoind signal handlers - noui_connect(); - - return (AppInit(argc, argv) ? 0 : 1); -} diff --git a/src/bitcoind.h b/src/bitcoind.h new file mode 100644 index 0000000..0e34008 --- /dev/null +++ b/src/bitcoind.h @@ -0,0 +1,25 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef _BITCOIN_BITCOIND +#define _BITCOIN_BITCOIND 1 + +#include "clientversion.h" +#include "rpcserver.h" +#include "init.h" +#include "main.h" +#include "noui.h" +#include "ui_interface.h" +#include "util.h" +#include "rpcclient.h" + +#include +#include +#include + +extern void DetectShutdownThread(boost::thread_group* threadGroup); +extern bool AppInit(int argc, char* argv[]); + +#endif diff --git a/src/init.h b/src/init.h index f2f7ac6..10abc3a 100644 --- a/src/init.h +++ b/src/init.h @@ -15,7 +15,15 @@ namespace boost class thread_group; } // namespace boost +#ifdef ENABLE_WALLET +extern std::string strWalletFile; extern CWallet* pwalletMain; +#endif + +#include +#include + +void ThreadImport(std::vector vImportFiles); void StartShutdown(); bool ShutdownRequested(); diff --git a/src/leveldbwrapper.h b/src/leveldbwrapper.h index 4247920..08c8164 100644 --- a/src/leveldbwrapper.h +++ b/src/leveldbwrapper.h @@ -29,10 +29,9 @@ class CLevelDBBatch { friend class CLevelDBWrapper; -private: +public: leveldb::WriteBatch batch; -public: template void Write(const K& key, const V& value) { @@ -63,7 +62,7 @@ public: class CLevelDBWrapper { -private: +public: //! custom environment this database is using (may be NULL in case of default environment) leveldb::Env* penv; @@ -85,7 +84,6 @@ private: //! the database itself leveldb::DB* pdb; -public: CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false); ~CLevelDBWrapper(); diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 8b95373..cd18b91 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -25,12 +25,11 @@ using namespace json_spirit; using namespace std; void EnsureWalletIsUnlocked(); - -std::string static EncodeDumpTime(int64_t nTime) { +std::string EncodeDumpTime(int64_t nTime) { return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime); } -int64_t static DecodeDumpTime(const std::string &str) { +int64_t DecodeDumpTime(const std::string &str) { static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0); static const std::locale loc(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); @@ -43,7 +42,7 @@ int64_t static DecodeDumpTime(const std::string &str) { return (ptime - epoch).total_seconds(); } -std::string static EncodeDumpString(const std::string &str) { +std::string EncodeDumpString(const std::string &str) { std::stringstream ret; BOOST_FOREACH(unsigned char c, str) { if (c <= 32 || c >= 128 || c == '%') { diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index e43eee1..8862738 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "amount.h" +#include "rpcwallet.h" #include "base58.h" #include "core_io.h" #include "rpcserver.h" diff --git a/src/rpcwallet.h b/src/rpcwallet.h new file mode 100644 index 0000000..2b53241 --- /dev/null +++ b/src/rpcwallet.h @@ -0,0 +1,17 @@ +// Copyright (c) 2010 Satoshi Nakamoto +// Copyright (c) 2009-2013 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef _BITCOINRPC_WALLET_H_ +#define _BITCOINRPC_WALLET_H_ 1 + +#include "wallet.h" +#include "walletdb.h" + +#include + +CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, int nMinDepth, const isminefilter& filter); +CAmount GetAccountBalance(const std::string& strAccount, int nMinDepth, const isminefilter& filter); + +#endif diff --git a/src/wallet.h b/src/wallet.h index 058107e..3dfc8c4 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -110,8 +110,6 @@ public: class CWallet : public CCryptoKeyStore, public CValidationInterface { private: - bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const; - CWalletDB *pwalletdbEncryption; //! the current wallet version: clients below this version are not able to load the wallet @@ -206,6 +204,7 @@ public: bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const; + bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const; bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; bool IsSpent(const uint256& hash, unsigned int n) const; -- 2.3.2 (Apple Git-55)