From 4d58e8947e4222994cf2d0f49c71009e5cfc5792 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Tue, 30 May 2017 15:55:17 -0400 Subject: [PATCH] bitcoin#14437: Start to separate wallet from node --- src/Makefile.am | 3 + src/bench/coin_selection.cpp | 7 +- src/coinjoin/coinjoin-client.cpp | 5 +- src/coinjoin/coinjoin-util.cpp | 4 +- src/dashd.cpp | 8 +- src/dummywallet.cpp | 7 - src/init.cpp | 47 ++++-- src/init.h | 19 ++- src/interfaces/README.md | 2 +- src/interfaces/chain.cpp | 44 ++++++ src/interfaces/chain.h | 84 ++++++++++ src/interfaces/node.cpp | 12 +- src/interfaces/wallet.cpp | 135 +++++++++++----- src/qt/test/addressbooktests.cpp | 4 +- src/qt/test/wallettests.cpp | 6 +- src/rpc/masternode.cpp | 3 +- src/rpc/rawtransaction.cpp | 4 +- src/rpc/rawtransaction.h | 6 +- src/rpc/rpcevo.cpp | 5 +- src/rpc/util.cpp | 2 + src/rpc/util.h | 6 + src/test/rpc_tests.cpp | 7 + src/threadsafety.h | 12 ++ src/wallet/init.cpp | 66 +++----- src/wallet/rpcdump.cpp | 32 ++-- src/wallet/rpcwallet.cpp | 166 +++++++++++-------- src/wallet/test/coinjoin_tests.cpp | 7 +- src/wallet/test/coinselector_tests.cpp | 3 +- src/wallet/test/init_test_fixture.cpp | 2 + src/wallet/test/init_test_fixture.h | 5 +- src/wallet/test/init_tests.cpp | 16 +- src/wallet/test/wallet_test_fixture.cpp | 2 +- src/wallet/test/wallet_test_fixture.h | 3 + src/wallet/test/wallet_tests.cpp | 66 ++++---- src/wallet/wallet.cpp | 201 +++++++++++++----------- src/wallet/wallet.h | 71 ++++++--- src/walletinitinterface.h | 17 +- 37 files changed, 715 insertions(+), 374 deletions(-) create mode 100644 src/interfaces/chain.cpp create mode 100644 src/interfaces/chain.h diff --git a/src/Makefile.am b/src/Makefile.am index b63a7e7ddaee44..447a21725233de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -181,6 +181,7 @@ BITCOIN_CORE_H = \ index/txindex.h \ indirectmap.h \ init.h \ + interfaces/chain.h \ interfaces/handler.h \ interfaces/node.h \ interfaces/wallet.h \ @@ -345,6 +346,7 @@ libdash_server_a_SOURCES = \ index/base.cpp \ index/blockfilterindex.cpp \ index/txindex.cpp \ + interfaces/chain.cpp \ interfaces/handler.cpp \ interfaces/node.cpp \ init.cpp \ @@ -674,6 +676,7 @@ endif dashd_LDADD = \ $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_WALLET) \ + $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_COMMON) \ $(LIBUNIVALUE) \ $(LIBBITCOIN_UTIL) \ diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index aa44f5dc736a30..c43defa6533ae9 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include @@ -33,7 +34,8 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector CoinSet; -static const CWallet testWallet(WalletLocation(), WalletDatabase::CreateDummy()); +static auto testChain = interfaces::MakeChain(); +static const CWallet testWallet(*testChain, WalletLocation(), WalletDatabase::CreateDummy()); std::vector> wtxn; // Copied from src/wallet/test/coinselector_tests.cpp diff --git a/src/coinjoin/coinjoin-client.cpp b/src/coinjoin/coinjoin-client.cpp index f22a64fc6f0b9d..8c4ba9918217f7 100644 --- a/src/coinjoin/coinjoin-client.cpp +++ b/src/coinjoin/coinjoin-client.cpp @@ -1513,13 +1513,14 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CompactTallyItem& tally bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason) { - LOCK2(cs_main, mixingWallet.cs_wallet); + auto locked_chain = mixingWallet.chain().lock(); + LOCK(mixingWallet.cs_wallet); std::vector vCoins; CCoinControl coin_control; coin_control.nCoinType = CoinType::ONLY_COINJOIN_COLLATERAL; - mixingWallet.AvailableCoins(vCoins, true, &coin_control); + mixingWallet.AvailableCoins(*locked_chain, vCoins, true, &coin_control); if (vCoins.empty()) { strReason = strprintf("%s requires a collateral transaction and could not locate an acceptable input!", gCoinJoinName); diff --git a/src/coinjoin/coinjoin-util.cpp b/src/coinjoin/coinjoin-util.cpp index 2e296e7aeed393..69397197ea68ac 100644 --- a/src/coinjoin/coinjoin-util.cpp +++ b/src/coinjoin/coinjoin-util.cpp @@ -269,8 +269,10 @@ bool CTransactionBuilder::Commit(std::string& strResult) } } + auto locked_chain = pwallet->chain().lock(); + CTransactionRef tx; - if (!pwallet->CreateTransaction(vecSend, tx, dummyReserveKey, nFeeRet, nChangePosRet, strResult, coinControl)) { + if (!pwallet->CreateTransaction(*locked_chain, vecSend, tx, dummyReserveKey, nFeeRet, nChangePosRet, strResult, coinControl)) { return false; } diff --git a/src/dashd.cpp b/src/dashd.cpp index 2201cef15bb4f7..fe4a1b9ad59920 100644 --- a/src/dashd.cpp +++ b/src/dashd.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,9 @@ static void WaitForShutdown() // static bool AppInit(int argc, char* argv[]) { + InitInterfaces interfaces; + interfaces.chain = interfaces::MakeChain(); + bool fRet = false; util::ThreadRename("init"); @@ -178,7 +182,7 @@ static bool AppInit(int argc, char* argv[]) // If locking the data directory failed, exit immediately return false; } - fRet = AppInitMain(); + fRet = AppInitMain(interfaces); } catch (...) { PrintExceptionContinue(std::current_exception(), "AppInit()"); } @@ -189,7 +193,7 @@ static bool AppInit(int argc, char* argv[]) } else { WaitForShutdown(); } - Shutdown(); + Shutdown(interfaces); return fRet; } diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index c3f85e0ec74281..1f6cc135e7f3c3 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -16,13 +16,6 @@ class DummyWalletInit : public WalletInitInterface { bool HasWalletSupport() const override {return false;} void AddWalletOptions() const override; bool ParameterInteraction() const override {return true;} - void RegisterRPC(CRPCTable &) const override {} - bool Verify() const override {return true;} - bool Open() const override {LogPrintf("No wallet support compiled in!\n"); return true;} - void Start(CScheduler& scheduler) const override {} - void Flush() const override {} - void Stop() const override {} - void Close() const override {} // Dash Specific WalletInitInterface InitCoinJoinSettings void AutoLockMasternodeCollaterals() const override {} diff --git a/src/init.cpp b/src/init.cpp index ffd9ddd885461a..8d224854e83e94 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include