From 7e2e62cf7c513bd7d8e784069c5534fda1c50c52 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 30 May 2017 15:55:17 -0400 Subject: [PATCH 1/5] Add skeleton chain and client classes This commit does not change behavior. It just adds new skeleton classes that don't do anything and aren't instantiated yet. --- build_msvc/msvc-autogen.py | 14 ++++++------ src/Makefile.am | 2 ++ src/interfaces/README.md | 2 +- src/interfaces/chain.cpp | 20 +++++++++++++++++ src/interfaces/chain.h | 44 ++++++++++++++++++++++++++++++++++++++ src/interfaces/wallet.cpp | 24 +++++++++++++++++++++ 6 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 src/interfaces/chain.cpp create mode 100644 src/interfaces/chain.h diff --git a/build_msvc/msvc-autogen.py b/build_msvc/msvc-autogen.py index 8888487e754..f351532f9d4 100644 --- a/build_msvc/msvc-autogen.py +++ b/build_msvc/msvc-autogen.py @@ -16,10 +16,6 @@ libs = [ ] ignore_list = [ - 'rpc/net.cpp', - 'interfaces/handler.cpp', - 'interfaces/node.cpp', - 'interfaces/wallet.cpp', ] lib_sources = {} @@ -32,7 +28,9 @@ def parse_makefile(makefile): if current_lib: source = line.split()[0] if source.endswith('.cpp') and not source.startswith('$') and source not in ignore_list: - lib_sources[current_lib].append(source.replace('/', '\\')) + source_filename = source.replace('/', '\\') + object_filename = source.replace('/', '_')[:-4] + ".obj" + lib_sources[current_lib].append((source_filename, object_filename)) if not line.endswith('\\'): current_lib = '' continue @@ -51,8 +49,10 @@ def main(): for key, value in lib_sources.items(): vcxproj_filename = os.path.abspath(os.path.join(os.path.dirname(__file__), key, key + '.vcxproj')) content = '' - for source_filename in value: - content += ' \n' + for source_filename, object_filename in value: + content += ' \n' + content += ' $(IntDir)' + object_filename + '\n' + content += ' \n' with open(vcxproj_filename + '.in', 'r', encoding='utf-8') as vcxproj_in_file: with open(vcxproj_filename, 'w', encoding='utf-8') as vcxproj_file: vcxproj_file.write(vcxproj_in_file.read().replace( diff --git a/src/Makefile.am b/src/Makefile.am index 6852ef408a2..e2727ac5225 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -125,6 +125,7 @@ BITCOIN_CORE_H = \ index/txindex.h \ indirectmap.h \ init.h \ + interfaces/chain.h \ interfaces/handler.h \ interfaces/node.h \ interfaces/wallet.h \ @@ -233,6 +234,7 @@ libbitcoin_server_a_SOURCES = \ httpserver.cpp \ index/base.cpp \ index/txindex.cpp \ + interfaces/chain.cpp \ interfaces/handler.cpp \ interfaces/node.cpp \ init.cpp \ diff --git a/src/interfaces/README.md b/src/interfaces/README.md index e93b91d23ce..57d41df746b 100644 --- a/src/interfaces/README.md +++ b/src/interfaces/README.md @@ -4,7 +4,7 @@ The following interfaces are defined here: * [`Chain`](chain.h) — used by wallet to access blockchain and mempool state. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973). -* [`Chain::Client`](chain.h) — used by node to start & stop `Chain` clients. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973). +* [`ChainClient`](chain.h) — used by node to start & stop `Chain` clients. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973). * [`Node`](node.h) — used by GUI to start & stop bitcoin node. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244). diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp new file mode 100644 index 00000000000..28b36717d5d --- /dev/null +++ b/src/interfaces/chain.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +namespace interfaces { +namespace { + +class ChainImpl : public Chain +{ +}; + +} // namespace + +std::unique_ptr MakeChain() { return MakeUnique(); } + +} // namespace interfaces diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h new file mode 100644 index 00000000000..8a40cb4cda2 --- /dev/null +++ b/src/interfaces/chain.h @@ -0,0 +1,44 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_INTERFACES_CHAIN_H +#define BITCOIN_INTERFACES_CHAIN_H + +#include +#include +#include + +namespace interfaces { + +//! Interface for giving wallet processes access to blockchain state. +class Chain +{ +public: + virtual ~Chain() {} +}; + +//! Interface to let node manage chain clients (wallets, or maybe tools for +//! monitoring and analysis in the future). +class ChainClient +{ +public: + virtual ~ChainClient() {} +}; + +//! Return implementation of Chain interface. +std::unique_ptr MakeChain(); + +//! Return implementation of ChainClient interface for a wallet client. This +//! function will be undefined in builds where ENABLE_WALLET is false. +//! +//! Currently, wallets are the only chain clients. But in the future, other +//! types of chain clients could be added, such as tools for monitoring, +//! analysis, or fee estimation. These clients need to expose their own +//! MakeXXXClient functions returning their implementations of the ChainClient +//! interface. +std::unique_ptr MakeWalletClient(Chain& chain, std::vector wallet_filenames); + +} // namespace interfaces + +#endif // BITCOIN_INTERFACES_CHAIN_H diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 14c6bd03304..e9f4669f4d9 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,11 +21,17 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include +#include + namespace interfaces { namespace { @@ -456,8 +463,25 @@ public: CWallet& m_wallet; }; +class WalletClientImpl : public ChainClient +{ +public: + WalletClientImpl(Chain& chain, std::vector wallet_filenames) + : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames)) + { + } + + Chain& m_chain; + std::vector m_wallet_filenames; +}; + } // namespace std::unique_ptr MakeWallet(const std::shared_ptr& wallet) { return MakeUnique(wallet); } +std::unique_ptr MakeWalletClient(Chain& chain, std::vector wallet_filenames) +{ + return MakeUnique(chain, std::move(wallet_filenames)); +} + } // namespace interfaces From 8db11dd0b182a93042899651545cc21b34bf0742 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 30 May 2017 15:55:17 -0400 Subject: [PATCH 2/5] Pass chain and client variables where needed This commit does not change behavior. All it does is pass new function parameters. It is easiest to review this change with: git log -p -n1 -U0 --word-diff-regex=. --- src/bench/coin_selection.cpp | 7 +++++-- src/bitcoind.cpp | 8 ++++++-- src/dummywallet.cpp | 4 ++-- src/init.cpp | 10 ++++++---- src/init.h | 17 +++++++++++++---- src/interfaces/node.cpp | 8 ++++++-- src/qt/test/addressbooktests.cpp | 4 +++- src/qt/test/wallettests.cpp | 4 +++- src/rpc/rawtransaction.cpp | 6 ++++-- src/rpc/rawtransaction.h | 6 +++++- src/rpc/util.cpp | 2 ++ src/rpc/util.h | 6 ++++++ src/test/rpc_tests.cpp | 7 +++++++ src/wallet/init.cpp | 12 ++++++------ src/wallet/rpcwallet.cpp | 19 ++++++++++--------- src/wallet/test/coinselector_tests.cpp | 3 ++- src/wallet/test/init_test_fixture.h | 2 ++ src/wallet/test/init_tests.cpp | 14 +++++++------- src/wallet/test/wallet_test_fixture.cpp | 2 +- src/wallet/test/wallet_test_fixture.h | 3 +++ src/wallet/test/wallet_tests.cpp | 23 +++++++++++++++-------- src/wallet/wallet.cpp | 10 +++++----- src/wallet/wallet.h | 16 +++++++++++++--- src/walletinitinterface.h | 8 ++++++-- 24 files changed, 138 insertions(+), 63 deletions(-) diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index decdadfb26e..8552ed34fd8 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/bitcoind.cpp b/src/bitcoind.cpp index c6e2a7c20a6..1306ba3821f 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,9 @@ static void WaitForShutdown() // static bool AppInit(int argc, char* argv[]) { + InitInterfaces interfaces; + interfaces.chain = interfaces::MakeChain(); + bool fRet = false; // @@ -164,7 +168,7 @@ static bool AppInit(int argc, char* argv[]) // If locking the data directory failed, exit immediately return false; } - fRet = AppInitMain(); + fRet = AppInitMain(interfaces); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); @@ -178,7 +182,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 2a9b2970295..fa232d2dd08 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -15,8 +15,8 @@ public: 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;} + bool Verify(interfaces::Chain& chain) const override {return true;} + bool Open(interfaces::Chain& chain) 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 {} diff --git a/src/init.cpp b/src/init.cpp index d54d4a8782f..88d4d059f99 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include