diff --git a/Makefile.am b/Makefile.am
index cea8151d..f1c3090f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,6 +64,7 @@ src_libbitcoin_node_la_SOURCES = \
src/protocols/protocol_block_in_31800.cpp \
src/protocols/protocol_block_out_106.cpp \
src/protocols/protocol_block_out_70012.cpp \
+ src/protocols/protocol_electrum.cpp \
src/protocols/protocol_explore.cpp \
src/protocols/protocol_filter_out_70015.cpp \
src/protocols/protocol_header_in_31800.cpp \
@@ -75,6 +76,7 @@ src_libbitcoin_node_la_SOURCES = \
src/protocols/protocol_observer.cpp \
src/protocols/protocol_peer.cpp \
src/protocols/protocol_performer.cpp \
+ src/protocols/protocol_stratum_v1.cpp \
src/protocols/protocol_transaction_in_106.cpp \
src/protocols/protocol_transaction_out_106.cpp \
src/sessions/session.cpp \
@@ -184,7 +186,7 @@ include_bitcoin_node_channels_HEADERS = \
include/bitcoin/node/channels/channel_http.hpp \
include/bitcoin/node/channels/channel_peer.hpp \
include/bitcoin/node/channels/channel_rpc.hpp \
- include/bitcoin/node/channels/channel_tcp.hpp \
+ include/bitcoin/node/channels/channel_sv2.hpp \
include/bitcoin/node/channels/channel_ws.hpp \
include/bitcoin/node/channels/channels.hpp
@@ -250,7 +252,6 @@ include_bitcoin_node_protocols_HEADERS = \
include/bitcoin/node/protocols/protocol_rpc.hpp \
include/bitcoin/node/protocols/protocol_stratum_v1.hpp \
include/bitcoin/node/protocols/protocol_stratum_v2.hpp \
- include/bitcoin/node/protocols/protocol_tcp.hpp \
include/bitcoin/node/protocols/protocol_transaction_in_106.hpp \
include/bitcoin/node/protocols/protocol_transaction_out_106.hpp \
include/bitcoin/node/protocols/protocol_web.hpp \
diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt
index 1188288b..15f19bb9 100644
--- a/builds/cmake/CMakeLists.txt
+++ b/builds/cmake/CMakeLists.txt
@@ -276,6 +276,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/protocols/protocol_block_in_31800.cpp"
"../../src/protocols/protocol_block_out_106.cpp"
"../../src/protocols/protocol_block_out_70012.cpp"
+ "../../src/protocols/protocol_electrum.cpp"
"../../src/protocols/protocol_explore.cpp"
"../../src/protocols/protocol_filter_out_70015.cpp"
"../../src/protocols/protocol_header_in_31800.cpp"
@@ -287,6 +288,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/protocols/protocol_observer.cpp"
"../../src/protocols/protocol_peer.cpp"
"../../src/protocols/protocol_performer.cpp"
+ "../../src/protocols/protocol_stratum_v1.cpp"
"../../src/protocols/protocol_transaction_in_106.cpp"
"../../src/protocols/protocol_transaction_out_106.cpp"
"../../src/sessions/session.cpp"
diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
index f4662b04..d9899614 100644
--- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
+++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
@@ -149,6 +149,7 @@
+
@@ -160,6 +161,7 @@
+
@@ -176,7 +178,7 @@
-
+
@@ -233,7 +235,6 @@
-
diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters
index 4a167287..4adb9895 100644
--- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters
+++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters
@@ -147,6 +147,9 @@
src\protocols
+
+ src\protocols
+
src\protocols
@@ -180,6 +183,9 @@
src\protocols
+
+ src\protocols
+
src\protocols
@@ -224,7 +230,7 @@
include\bitcoin\node\channels
-
+
include\bitcoin\node\channels
@@ -395,9 +401,6 @@
include\bitcoin\node\protocols
-
- include\bitcoin\node\protocols
-
include\bitcoin\node\protocols
diff --git a/include/bitcoin/node.hpp b/include/bitcoin/node.hpp
index 517b5687..846c7491 100644
--- a/include/bitcoin/node.hpp
+++ b/include/bitcoin/node.hpp
@@ -31,7 +31,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -81,7 +81,6 @@
#include
#include
#include
-#include
#include
#include
#include
diff --git a/include/bitcoin/node/channels/channel_rpc.hpp b/include/bitcoin/node/channels/channel_rpc.hpp
index f2827385..2be67709 100644
--- a/include/bitcoin/node/channels/channel_rpc.hpp
+++ b/include/bitcoin/node/channels/channel_rpc.hpp
@@ -28,19 +28,22 @@ namespace libbitcoin {
namespace node {
/// Channel for electrum and stratum v1 channels (non-http json-rpc).
+template
class BCN_API channel_rpc
: public node::channel,
- public network::channel_rpc,
- protected network::tracker
+ public network::channel_rpc,
+ protected network::tracker>
{
public:
typedef std::shared_ptr ptr;
+ using options_t = typename network::channel_rpc::options_t;
inline channel_rpc(const network::logger& log,
const network::socket::ptr& socket, uint64_t identifier,
const node::configuration& config, const options_t& options) NOEXCEPT
: node::channel(log, socket, identifier, config),
- network::channel_rpc(log, socket, identifier, config.network, options),
+ network::channel_rpc(log, socket, identifier,
+ config.network, options),
network::tracker(log)
{
}
diff --git a/include/bitcoin/node/channels/channel_tcp.hpp b/include/bitcoin/node/channels/channel_sv2.hpp
similarity index 76%
rename from include/bitcoin/node/channels/channel_tcp.hpp
rename to include/bitcoin/node/channels/channel_sv2.hpp
index 8871cc06..43fbcf32 100644
--- a/include/bitcoin/node/channels/channel_tcp.hpp
+++ b/include/bitcoin/node/channels/channel_sv2.hpp
@@ -16,8 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-#ifndef LIBBITCOIN_NODE_CHANNELS_CHANNEL_TCP_HPP
-#define LIBBITCOIN_NODE_CHANNELS_CHANNEL_TCP_HPP
+#ifndef LIBBITCOIN_NODE_CHANNELS_CHANNEL_SV2_HPP
+#define LIBBITCOIN_NODE_CHANNELS_CHANNEL_SV2_HPP
#include
#include
@@ -27,22 +27,21 @@
namespace libbitcoin {
namespace node {
-/// Abstract base TCP channel state for the node.
-/// This is a placeholder for stratum v2 (any unimplemented).
-class BCN_API channel_tcp
+/// Channel for stratum v2 (custom protocol, not implemented).
+class BCN_API channel_sv2
: public node::channel,
public network::channel,
- protected network::tracker
+ protected network::tracker
{
public:
- typedef std::shared_ptr ptr;
+ typedef std::shared_ptr ptr;
- inline channel_tcp(const network::logger& log,
+ inline channel_sv2(const network::logger& log,
const network::socket::ptr& socket, uint64_t identifier,
const node::configuration& config, const options_t& options) NOEXCEPT
: node::channel(log, socket, identifier, config),
network::channel(log, socket, identifier, config.network, options),
- network::tracker(log)
+ network::tracker(log)
{
}
};
diff --git a/include/bitcoin/node/channels/channels.hpp b/include/bitcoin/node/channels/channels.hpp
index 01b0a5b9..77a0110b 100644
--- a/include/bitcoin/node/channels/channels.hpp
+++ b/include/bitcoin/node/channels/channels.hpp
@@ -23,7 +23,7 @@
#include
#include
#include
-#include
+#include
#include
#endif
diff --git a/include/bitcoin/node/interfaces/electrum.hpp b/include/bitcoin/node/interfaces/electrum.hpp
index 696e6156..b1463da8 100644
--- a/include/bitcoin/node/interfaces/electrum.hpp
+++ b/include/bitcoin/node/interfaces/electrum.hpp
@@ -86,8 +86,6 @@ struct electrum_methods
using server_peers_subscribe = at<19>;
using server_ping = at<20>;
using server_version = at<21>;
-
- ////using subscribers = unsubscriber>;
};
} // namespace interface
diff --git a/include/bitcoin/node/protocols/protocol_electrum.hpp b/include/bitcoin/node/protocols/protocol_electrum.hpp
index a262f95a..f25bcf0b 100644
--- a/include/bitcoin/node/protocols/protocol_electrum.hpp
+++ b/include/bitcoin/node/protocols/protocol_electrum.hpp
@@ -22,31 +22,36 @@
#include
#include
#include
+#include
#include
namespace libbitcoin {
namespace node {
class BCN_API protocol_electrum
- : public node::protocol_rpc,
+ : public node::protocol_rpc,
protected network::tracker
{
public:
typedef std::shared_ptr ptr;
+ using rpc_interface = interface::electrum;
inline protocol_electrum(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
- : node::protocol_rpc(session, channel, options),
+ : node::protocol_rpc(session, channel, options),
network::tracker(session->log)
{
}
- /// Public start is required.
- inline void start() NOEXCEPT override
- {
- node::protocol_rpc::start();
- }
+ void start() NOEXCEPT override;
+
+protected:
+ /// Handlers.
+ bool handle_blockchain_headers_subscribe(const code& ec,
+ rpc_interface::blockchain_headers_subscribe) NOEXCEPT;
+ bool handle_blockchain_relayfee(const code& ec,
+ rpc_interface::blockchain_relayfee) NOEXCEPT;
};
} // namespace node
diff --git a/include/bitcoin/node/protocols/protocol_rpc.hpp b/include/bitcoin/node/protocols/protocol_rpc.hpp
index 92f22dd5..f5264c0d 100644
--- a/include/bitcoin/node/protocols/protocol_rpc.hpp
+++ b/include/bitcoin/node/protocols/protocol_rpc.hpp
@@ -24,26 +24,25 @@
#include
#include
- // Only session.hpp.
-#include
-
namespace libbitcoin {
namespace node {
/// Abstract base for RPC protocols, thread safe.
+template
class BCN_API protocol_rpc
: public node::protocol,
- public network::protocol_rpc
+ public network::protocol_rpc
{
public:
- using channel_t = node::channel_rpc;
+ using channel_t = node::channel_rpc;
+ using options_t = channel_t::options_t;
protected:
inline protocol_rpc(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: node::protocol(session, channel),
- network::protocol_rpc(session, channel, options)
+ network::protocol_rpc(session, channel, options)
{
}
};
diff --git a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp
index ddc34515..d4cd93ad 100644
--- a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp
+++ b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp
@@ -21,31 +21,34 @@
#include
#include
+#include
#include
namespace libbitcoin {
namespace node {
class BCN_API protocol_stratum_v1
- : public node::protocol_rpc,
+ : public node::protocol_rpc,
protected network::tracker
{
public:
typedef std::shared_ptr ptr;
+ using rpc_interface = interface::stratum_v1;
inline protocol_stratum_v1(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
- : node::protocol_rpc(session, channel, options),
+ : node::protocol_rpc(session, channel, options),
network::tracker(session->log)
{
}
- /// Public start is required.
- inline void start() NOEXCEPT override
- {
- node::protocol_rpc::start();
- }
+ void start() NOEXCEPT override;
+
+protected:
+ /// Handlers.
+ bool handle_mining_extranonce_subscribe(const code& ec,
+ rpc_interface::mining_extranonce_subscribe) NOEXCEPT;
};
} // namespace node
diff --git a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp
index c04a3197..0b3dc254 100644
--- a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp
+++ b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp
@@ -20,37 +20,35 @@
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_STRATUM_V2_HPP
#include
+#include
#include
-#include
+#include
namespace libbitcoin {
namespace node {
class BCN_API protocol_stratum_v2
- : public node::protocol_tcp,
+ : public node::protocol,
+ public network::protocol,
protected network::tracker
{
public:
typedef std::shared_ptr ptr;
+ using channel_t = node::channel_sv2;
inline protocol_stratum_v2(const auto& session,
- const network::channel::ptr& channel,
- const options_t& options) NOEXCEPT
- : node::protocol_tcp(session, channel, options),
- ////options_(options),
+ const network::channel::ptr& channel, const options_t&) NOEXCEPT
+ : node::protocol(session, channel),
+ network::protocol(session, channel),
network::tracker(session->log)
{
}
- /// Public start is required.
+ // TODO: subscribe to and handle messages.
inline void start() NOEXCEPT override
{
- node::protocol_tcp::start();
+ network::protocol::start();
}
-
-private:
- // This is thread safe.
- ////const options_t& options_;
};
} // namespace node
diff --git a/include/bitcoin/node/protocols/protocol_tcp.hpp b/include/bitcoin/node/protocols/protocol_tcp.hpp
deleted file mode 100644
index 53b57798..00000000
--- a/include/bitcoin/node/protocols/protocol_tcp.hpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
- *
- * This file is part of libbitcoin.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-#ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TCP_HPP
-#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_TCP_HPP
-
-#include
-#include
-#include
-#include
-
- // Only session.hpp.
-#include
-
-namespace libbitcoin {
-namespace node {
-
-/// Abstract base for TCP protocols, thread safe.
-class BCN_API protocol_tcp
- : public node::protocol,
- public network::protocol
-{
-public:
- // Replace base class channel_t (network::channel).
- using channel_t = node::channel_tcp;
-
-protected:
- inline protocol_tcp(const auto& session,
- const network::channel::ptr& channel, const options_t&) NOEXCEPT
- : node::protocol(session, channel),
- network::protocol(session, channel),
- channel_(std::static_pointer_cast(channel)),
- session_(session)
- {
- }
-
-private:
- // This derived channel requires stranded calls, base is thread safe.
- const node::channel_tcp::ptr channel_;
-
- // This is thread safe.
- const node::session::ptr session_;
-};
-
-} // namespace node
-} // namespace libbitcoin
-
-#endif
diff --git a/include/bitcoin/node/protocols/protocols.hpp b/include/bitcoin/node/protocols/protocols.hpp
index 2568214a..184ccf44 100644
--- a/include/bitcoin/node/protocols/protocols.hpp
+++ b/include/bitcoin/node/protocols/protocols.hpp
@@ -25,7 +25,6 @@
#include
#include
#include
-#include
/// peer
#include
diff --git a/src/protocols/protocol_bitcoind_rest.cpp b/src/protocols/protocol_bitcoind_rest.cpp
index fae1b514..058c9e90 100644
--- a/src/protocols/protocol_bitcoind_rest.cpp
+++ b/src/protocols/protocol_bitcoind_rest.cpp
@@ -44,8 +44,6 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
void protocol_bitcoind_rest::start() NOEXCEPT
{
- using namespace std::placeholders;
-
BC_ASSERT(stranded());
if (started())
diff --git a/src/protocols/protocol_bitcoind_rpc.cpp b/src/protocols/protocol_bitcoind_rpc.cpp
index 02dabf1c..92049d78 100644
--- a/src/protocols/protocol_bitcoind_rpc.cpp
+++ b/src/protocols/protocol_bitcoind_rpc.cpp
@@ -42,8 +42,6 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
void protocol_bitcoind_rpc::start() NOEXCEPT
{
- using namespace std::placeholders;
-
BC_ASSERT(stranded());
if (started())
diff --git a/src/protocols/protocol_electrum.cpp b/src/protocols/protocol_electrum.cpp
new file mode 100644
index 00000000..66aa789e
--- /dev/null
+++ b/src/protocols/protocol_electrum.cpp
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
+ *
+ * This file is part of libbitcoin.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+#include
+
+namespace libbitcoin {
+namespace node {
+
+#define CLASS protocol_electrum
+#define SUBSCRIBE_RPC(...) SUBSCRIBE_CHANNEL(void, __VA_ARGS__)
+
+using namespace std::placeholders;
+
+BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
+BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
+BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
+
+// Start.
+// ----------------------------------------------------------------------------
+
+void protocol_electrum::start() NOEXCEPT
+{
+ BC_ASSERT(stranded());
+
+ if (started())
+ return;
+
+ SUBSCRIBE_RPC(handle_blockchain_headers_subscribe, _1, _2);
+ SUBSCRIBE_RPC(handle_blockchain_relayfee, _1, _2);
+ node::protocol_rpc::start();
+}
+
+// Handlers.
+// ----------------------------------------------------------------------------
+
+bool protocol_electrum::handle_blockchain_headers_subscribe(const code& ec,
+ rpc_interface::blockchain_headers_subscribe) NOEXCEPT
+{
+ // TODO:
+ return !ec;
+}
+
+bool protocol_electrum::handle_blockchain_relayfee(const code& ec,
+ rpc_interface::blockchain_relayfee) NOEXCEPT
+{
+ // TODO:
+ return !ec;
+}
+
+BC_POP_WARNING()
+BC_POP_WARNING()
+BC_POP_WARNING()
+
+} // namespace node
+} // namespace libbitcoin
diff --git a/src/protocols/protocol_stratum_v1.cpp b/src/protocols/protocol_stratum_v1.cpp
new file mode 100644
index 00000000..833f25a4
--- /dev/null
+++ b/src/protocols/protocol_stratum_v1.cpp
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
+ *
+ * This file is part of libbitcoin.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+#include
+
+namespace libbitcoin {
+namespace node {
+
+#define CLASS protocol_stratum_v1
+#define SUBSCRIBE_RPC(...) SUBSCRIBE_CHANNEL(void, __VA_ARGS__)
+
+using namespace std::placeholders;
+
+BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
+BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
+BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
+
+// Start.
+// ----------------------------------------------------------------------------
+
+void protocol_stratum_v1::start() NOEXCEPT
+{
+ BC_ASSERT(stranded());
+
+ if (started())
+ return;
+
+ SUBSCRIBE_RPC(handle_mining_extranonce_subscribe, _1, _2);
+ node::protocol_rpc::start();
+}
+
+// Handlers.
+// ----------------------------------------------------------------------------
+
+bool protocol_stratum_v1::handle_mining_extranonce_subscribe(const code& ec,
+ rpc_interface::mining_extranonce_subscribe) NOEXCEPT
+{
+ // TODO:
+ return !ec;
+}
+
+BC_POP_WARNING()
+BC_POP_WARNING()
+BC_POP_WARNING()
+
+} // namespace node
+} // namespace libbitcoin