diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -426,6 +426,7 @@ index/base.cpp index/txindex.cpp init.cpp + interfaces/chain.cpp interfaces/handler.cpp interfaces/node.cpp merkleblock.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -148,6 +148,7 @@ index/txindex.h \ indirectmap.h \ init.h \ + interfaces/chain.h \ interfaces/handler.h \ interfaces/node.h \ interfaces/wallet.h \ @@ -268,6 +269,7 @@ index/base.cpp \ index/txindex.cpp \ init.cpp \ + interfaces/chain.h \ interfaces/handler.cpp \ interfaces/node.cpp \ dbwrapper.cpp \ diff --git a/src/interfaces/README.md b/src/interfaces/README.md --- a/src/interfaces/README.md +++ b/src/interfaces/README.md @@ -4,7 +4,7 @@ * [`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.h b/src/interfaces/chain.h new file mode 100644 --- /dev/null +++ b/src/interfaces/chain.h @@ -0,0 +1,43 @@ +// 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/chain.cpp b/src/interfaces/chain.cpp new file mode 100644 --- /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 std::make_unique(); +} + +} // namespace interfaces diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -18,12 +19,16 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include namespace interfaces { namespace { @@ -449,10 +454,26 @@ 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 std::make_unique(wallet); } +std::unique_ptr +MakeWalletClient(Chain &chain, std::vector wallet_filenames) { + return std::make_unique(chain, + std::move(wallet_filenames)); +} + } // namespace interfaces