From a3dfe5277552891e9a814e115735ae466258f3b5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 21 Dec 2025 00:12:06 -0500 Subject: [PATCH 1/3] Stub in channel_rpc, protocol_rpc/electrum/stratum_v1. --- Makefile.am | 2 + .../libbitcoin-node/libbitcoin-node.vcxproj | 2 + .../libbitcoin-node.vcxproj.filters | 6 +++ include/bitcoin/node.hpp | 2 + include/bitcoin/node/channels/channel_rpc.hpp | 52 ++++++++++++++++++ include/bitcoin/node/channels/channel_tcp.hpp | 2 +- include/bitcoin/node/channels/channels.hpp | 3 +- .../node/protocols/protocol_electrum.hpp | 12 ++--- .../bitcoin/node/protocols/protocol_rpc.hpp | 54 +++++++++++++++++++ .../node/protocols/protocol_stratum_v1.hpp | 13 ++--- include/bitcoin/node/protocols/protocols.hpp | 1 + 11 files changed, 130 insertions(+), 19 deletions(-) create mode 100644 include/bitcoin/node/channels/channel_rpc.hpp create mode 100644 include/bitcoin/node/protocols/protocol_rpc.hpp diff --git a/Makefile.am b/Makefile.am index 368fa4ae6..cea8151d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -183,6 +183,7 @@ include_bitcoin_node_channels_HEADERS = \ include/bitcoin/node/channels/channel.hpp \ 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_ws.hpp \ include/bitcoin/node/channels/channels.hpp @@ -246,6 +247,7 @@ include_bitcoin_node_protocols_HEADERS = \ include/bitcoin/node/protocols/protocol_observer.hpp \ include/bitcoin/node/protocols/protocol_peer.hpp \ include/bitcoin/node/protocols/protocol_performer.hpp \ + 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 \ diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index 0db943d70..f4662b041 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -175,6 +175,7 @@ + @@ -229,6 +230,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index 44319bdec..4a167287d 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -221,6 +221,9 @@ include\bitcoin\node\channels + + include\bitcoin\node\channels + include\bitcoin\node\channels @@ -383,6 +386,9 @@ 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 8a3be6d49..517b56874 100644 --- a/include/bitcoin/node.hpp +++ b/include/bitcoin/node.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -77,6 +78,7 @@ #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 new file mode 100644 index 000000000..f2827385a --- /dev/null +++ b/include/bitcoin/node/channels/channel_rpc.hpp @@ -0,0 +1,52 @@ +/** + * 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_CHANNELS_CHANNEL_RPC_HPP +#define LIBBITCOIN_NODE_CHANNELS_CHANNEL_RPC_HPP + +#include +#include +#include +#include + +namespace libbitcoin { +namespace node { + +/// Channel for electrum and stratum v1 channels (non-http json-rpc). +class BCN_API channel_rpc + : public node::channel, + public network::channel_rpc, + protected network::tracker +{ +public: + typedef std::shared_ptr ptr; + + 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::tracker(log) + { + } +}; + +} // namespace node +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/node/channels/channel_tcp.hpp b/include/bitcoin/node/channels/channel_tcp.hpp index 100f9a45b..8871cc06a 100644 --- a/include/bitcoin/node/channels/channel_tcp.hpp +++ b/include/bitcoin/node/channels/channel_tcp.hpp @@ -28,7 +28,7 @@ namespace libbitcoin { namespace node { /// Abstract base TCP channel state for the node. -/// This is a placeholder for electrum, bitcoind, and stratum v1/v2 channels. +/// This is a placeholder for stratum v2 (any unimplemented). class BCN_API channel_tcp : public node::channel, public network::channel, diff --git a/include/bitcoin/node/channels/channels.hpp b/include/bitcoin/node/channels/channels.hpp index 061168c0f..01b0a5b96 100644 --- a/include/bitcoin/node/channels/channels.hpp +++ b/include/bitcoin/node/channels/channels.hpp @@ -20,9 +20,10 @@ #define LIBBITCOIN_NODE_CHANNELS_CHANNELS_HPP #include +#include #include +#include #include -#include #include #endif diff --git a/include/bitcoin/node/protocols/protocol_electrum.hpp b/include/bitcoin/node/protocols/protocol_electrum.hpp index 7a26e5198..a262f95a7 100644 --- a/include/bitcoin/node/protocols/protocol_electrum.hpp +++ b/include/bitcoin/node/protocols/protocol_electrum.hpp @@ -22,13 +22,13 @@ #include #include #include -#include +#include namespace libbitcoin { namespace node { class BCN_API protocol_electrum - : public node::protocol_tcp, + : public node::protocol_rpc, protected network::tracker { public: @@ -37,7 +37,7 @@ class BCN_API protocol_electrum inline protocol_electrum(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT - : node::protocol_tcp(session, channel, options), + : node::protocol_rpc(session, channel, options), network::tracker(session->log) { } @@ -45,12 +45,8 @@ class BCN_API protocol_electrum /// Public start is required. inline void start() NOEXCEPT override { - node::protocol_tcp::start(); + node::protocol_rpc::start(); } - -private: - // This is thread safe. - ////const options_t& options_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocol_rpc.hpp b/include/bitcoin/node/protocols/protocol_rpc.hpp new file mode 100644 index 000000000..92f22dd5f --- /dev/null +++ b/include/bitcoin/node/protocols/protocol_rpc.hpp @@ -0,0 +1,54 @@ +/** + * 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_RPC_HPP +#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_RPC_HPP + +#include +#include +#include +#include + + // Only session.hpp. +#include + +namespace libbitcoin { +namespace node { + +/// Abstract base for RPC protocols, thread safe. +class BCN_API protocol_rpc + : public node::protocol, + public network::protocol_rpc +{ +public: + using channel_t = node::channel_rpc; + +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) + { + } +}; + +} // namespace node +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp index 3f3cff5d5..1eee4353f 100644 --- a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp +++ b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp @@ -21,13 +21,13 @@ #include #include -#include +#include namespace libbitcoin { namespace node { class BCN_API protocol_stratum_v1 - : public node::protocol_tcp, + : public node::protocol_rpc, protected network::tracker { public: @@ -36,8 +36,7 @@ class BCN_API protocol_stratum_v1 protocol_stratum_v1(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT - : node::protocol_tcp(session, channel, options), - ////options_(options), + : node::protocol_rpc(session, channel, options), network::tracker(session->log) { } @@ -45,12 +44,8 @@ class BCN_API protocol_stratum_v1 /// Public start is required. void start() NOEXCEPT override { - node::protocol_tcp::start(); + node::protocol_rpc::start(); } - -private: - // This is thread safe. - ////const options_t& options_; }; } // namespace node diff --git a/include/bitcoin/node/protocols/protocols.hpp b/include/bitcoin/node/protocols/protocols.hpp index da7815c87..2568214af 100644 --- a/include/bitcoin/node/protocols/protocols.hpp +++ b/include/bitcoin/node/protocols/protocols.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include /// peer From a7d8cd0be1ff8e6be3f71ef3606967eb3817fe14 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 21 Dec 2025 00:20:12 -0500 Subject: [PATCH 2/3] Ensure json-rpc interfaces expect double for optional<>. --- include/bitcoin/node/interfaces/electrum.hpp | 4 ++-- include/bitcoin/node/interfaces/stratum_v1.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/bitcoin/node/interfaces/electrum.hpp b/include/bitcoin/node/interfaces/electrum.hpp index 4b8b3254c..696e61566 100644 --- a/include/bitcoin/node/interfaces/electrum.hpp +++ b/include/bitcoin/node/interfaces/electrum.hpp @@ -31,8 +31,8 @@ struct electrum_methods static constexpr std::tuple methods { /// Blockchain methods. - method<"blockchain.block.header", number_t, optional<0>>{ "height", "cp_height" }, - method<"blockchain.block.headers", number_t, number_t, optional<0>>{ "start_height", "count", "cp_height" }, + method<"blockchain.block.header", number_t, optional<0.0>>{ "height", "cp_height" }, + method<"blockchain.block.headers", number_t, number_t, optional<0.0>>{ "start_height", "count", "cp_height" }, method<"blockchain.estimatefee", number_t>{ "number" }, method<"blockchain.headers.subscribe">{}, method<"blockchain.relayfee">{}, diff --git a/include/bitcoin/node/interfaces/stratum_v1.hpp b/include/bitcoin/node/interfaces/stratum_v1.hpp index 0c052b355..d76e405ee 100644 --- a/include/bitcoin/node/interfaces/stratum_v1.hpp +++ b/include/bitcoin/node/interfaces/stratum_v1.hpp @@ -31,7 +31,7 @@ struct stratum_v1_methods static constexpr std::tuple methods { /// Client requests. - method<"mining.subscribe", optional<""_t>, optional<0>>{ "user_agent", "extranonce1_size" }, + method<"mining.subscribe", optional<""_t>, optional<0.0>>{ "user_agent", "extranonce1_size" }, method<"mining.authorize", string_t, string_t>{ "username", "password" }, method<"mining.submit", string_t, string_t, string_t, number_t, string_t>{ "worker_name", "job_id", "extranonce2", "ntime", "nonce" }, method<"mining.extranonce.subscribe">{}, From 98dac891164cc751025fbe76662bfbc36f284973 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 21 Dec 2025 01:02:18 -0500 Subject: [PATCH 3/3] Use inline for header implementations. --- include/bitcoin/node/protocols/protocol.hpp | 2 +- include/bitcoin/node/protocols/protocol_stratum_v1.hpp | 2 +- include/bitcoin/node/protocols/protocol_stratum_v2.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/bitcoin/node/protocols/protocol.hpp b/include/bitcoin/node/protocols/protocol.hpp index 9b820302a..9ad86a2fd 100644 --- a/include/bitcoin/node/protocols/protocol.hpp +++ b/include/bitcoin/node/protocols/protocol.hpp @@ -40,7 +40,7 @@ class BCN_API protocol /// ----------------------------------------------------------------------- // reinterpret_pointer_cast because channel is abstract. - protocol(const auto& session, + inline protocol(const auto& session, const network::channel::ptr& channel) NOEXCEPT : channel_(std::reinterpret_pointer_cast(channel)), session_(session) diff --git a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp index 1eee4353f..3d73ad1d9 100644 --- a/include/bitcoin/node/protocols/protocol_stratum_v1.hpp +++ b/include/bitcoin/node/protocols/protocol_stratum_v1.hpp @@ -33,7 +33,7 @@ class BCN_API protocol_stratum_v1 public: typedef std::shared_ptr ptr; - protocol_stratum_v1(const auto& session, + inline protocol_stratum_v1(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT : node::protocol_rpc(session, channel, options), diff --git a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp index fdc71358f..ac601c08a 100644 --- a/include/bitcoin/node/protocols/protocol_stratum_v2.hpp +++ b/include/bitcoin/node/protocols/protocol_stratum_v2.hpp @@ -33,7 +33,7 @@ class BCN_API protocol_stratum_v2 public: typedef std::shared_ptr ptr; - protocol_stratum_v2(const auto& session, + inline protocol_stratum_v2(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT : node::protocol_tcp(session, channel, options),