Skip to content

Commit 82e272a

Browse files
committed
refactor: Move src/interfaces/*.cpp files to libbitcoin_common.a
These belong in libbitcoin_common.a, not libbitcoin_util.a, because they aren't general-purpose utilities, they just contain common code that is used by both the node and the wallet. Another reason to reason to not include these in libbitcoin_util.a is to prevent them from being used by the kernel library.
1 parent a035b6a commit 82e272a

File tree

5 files changed

+33
-61
lines changed

5 files changed

+33
-61
lines changed

src/Makefile.am

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ libbitcoin_common_a_SOURCES = \
633633
chainparams.cpp \
634634
coins.cpp \
635635
common/bloom.cpp \
636+
common/interfaces.cpp \
636637
common/run_command.cpp \
637638
compressor.cpp \
638639
core_read.cpp \
@@ -678,9 +679,6 @@ libbitcoin_util_a_SOURCES = \
678679
chainparamsbase.cpp \
679680
clientversion.cpp \
680681
fs.cpp \
681-
interfaces/echo.cpp \
682-
interfaces/handler.cpp \
683-
interfaces/init.cpp \
684682
logging.cpp \
685683
random.cpp \
686684
randomenv.cpp \
Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
// Copyright (c) 2018-2021 The Bitcoin Core developers
1+
// Copyright (c) 2021 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <interfaces/echo.h>
56
#include <interfaces/handler.h>
67

7-
88
#include <boost/signals2/connection.hpp>
9+
#include <memory>
910
#include <utility>
1011

11-
namespace interfaces {
12+
namespace common {
1213
namespace {
14+
class CleanupHandler : public interfaces::Handler
15+
{
16+
public:
17+
explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
18+
~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
19+
void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
20+
std::function<void()> m_cleanup;
21+
};
1322

14-
class HandlerImpl : public Handler
23+
class HandlerImpl : public interfaces::Handler
1524
{
1625
public:
1726
explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
@@ -21,25 +30,24 @@ class HandlerImpl : public Handler
2130
boost::signals2::scoped_connection m_connection;
2231
};
2332

24-
class CleanupHandler : public Handler
33+
class EchoImpl : public interfaces::Echo
2534
{
2635
public:
27-
explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
28-
~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
29-
void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
30-
std::function<void()> m_cleanup;
36+
std::string echo(const std::string& echo) override { return echo; }
3137
};
32-
3338
} // namespace
39+
} // namespace common
3440

35-
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
41+
namespace interfaces {
42+
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
3643
{
37-
return std::make_unique<HandlerImpl>(std::move(connection));
44+
return std::make_unique<common::CleanupHandler>(std::move(cleanup));
3845
}
3946

40-
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
47+
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
4148
{
42-
return std::make_unique<CleanupHandler>(std::move(cleanup));
49+
return std::make_unique<common::HandlerImpl>(std::move(connection));
4350
}
4451

52+
std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); }
4553
} // namespace interfaces

src/interfaces/echo.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/interfaces/init.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/interfaces/init.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
#ifndef BITCOIN_INTERFACES_INIT_H
66
#define BITCOIN_INTERFACES_INIT_H
77

8+
#include <interfaces/chain.h>
9+
#include <interfaces/echo.h>
10+
#include <interfaces/node.h>
11+
#include <interfaces/wallet.h>
12+
813
#include <memory>
914

1015
namespace node {
1116
struct NodeContext;
1217
} // namespace node
1318

1419
namespace interfaces {
15-
class Chain;
16-
class Echo;
1720
class Ipc;
18-
class Node;
19-
class WalletLoader;
2021

2122
//! Initial interface created when a process is first started, and used to give
2223
//! and get access to other interfaces (Node, Chain, Wallet, etc).
@@ -29,11 +30,11 @@ class Init
2930
{
3031
public:
3132
virtual ~Init() = default;
32-
virtual std::unique_ptr<Node> makeNode();
33-
virtual std::unique_ptr<Chain> makeChain();
34-
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain);
35-
virtual std::unique_ptr<Echo> makeEcho();
36-
virtual Ipc* ipc();
33+
virtual std::unique_ptr<Node> makeNode() { return nullptr; }
34+
virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
35+
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
36+
virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
37+
virtual Ipc* ipc() { return nullptr; }
3738
};
3839

3940
//! Return implementation of Init interface for the node process. If the argv

0 commit comments

Comments
 (0)