Skip to content

Commit e728915

Browse files
authored
Merge pull request #926 from evoskuil/master
Derive protocol_bitcoind_rest from _rpc.
2 parents 4702532 + cd73a31 commit e728915

File tree

18 files changed

+344
-139
lines changed

18 files changed

+344
-139
lines changed

Makefile.am

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ src_libbitcoin_node_la_SOURCES = \
5656
src/parse/query.cpp \
5757
src/parse/target.cpp \
5858
src/protocols/protocol.cpp \
59-
src/protocols/protocol_bitcoind.cpp \
59+
src/protocols/protocol_bitcoind_rest.cpp \
60+
src/protocols/protocol_bitcoind_rpc.cpp \
6061
src/protocols/protocol_block_in_106.cpp \
6162
src/protocols/protocol_block_in_31800.cpp \
6263
src/protocols/protocol_block_out_106.cpp \
@@ -202,7 +203,8 @@ include_bitcoin_node_impl_chasers_HEADERS = \
202203

203204
include_bitcoin_node_interfacesdir = ${includedir}/bitcoin/node/interfaces
204205
include_bitcoin_node_interfaces_HEADERS = \
205-
include/bitcoin/node/interfaces/bitcoind.hpp \
206+
include/bitcoin/node/interfaces/bitcoind_rest.hpp \
207+
include/bitcoin/node/interfaces/bitcoind_rpc.hpp \
206208
include/bitcoin/node/interfaces/electrum.hpp \
207209
include/bitcoin/node/interfaces/explore.hpp \
208210
include/bitcoin/node/interfaces/interfaces.hpp \
@@ -219,7 +221,8 @@ include_bitcoin_node_parse_HEADERS = \
219221
include_bitcoin_node_protocolsdir = ${includedir}/bitcoin/node/protocols
220222
include_bitcoin_node_protocols_HEADERS = \
221223
include/bitcoin/node/protocols/protocol.hpp \
222-
include/bitcoin/node/protocols/protocol_bitcoind.hpp \
224+
include/bitcoin/node/protocols/protocol_bitcoind_rest.hpp \
225+
include/bitcoin/node/protocols/protocol_bitcoind_rpc.hpp \
223226
include/bitcoin/node/protocols/protocol_block_in_106.hpp \
224227
include/bitcoin/node/protocols/protocol_block_in_31800.hpp \
225228
include/bitcoin/node/protocols/protocol_block_out_106.hpp \

builds/cmake/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ add_library( ${CANONICAL_LIB_NAME}
268268
"../../src/parse/query.cpp"
269269
"../../src/parse/target.cpp"
270270
"../../src/protocols/protocol.cpp"
271-
"../../src/protocols/protocol_bitcoind.cpp"
271+
"../../src/protocols/protocol_bitcoind_rest.cpp"
272+
"../../src/protocols/protocol_bitcoind_rpc.cpp"
272273
"../../src/protocols/protocol_block_in_106.cpp"
273274
"../../src/protocols/protocol_block_in_31800.cpp"
274275
"../../src/protocols/protocol_block_out_106.cpp"

builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@
141141
<ClCompile Include="..\..\..\..\src\parse\target.cpp" />
142142
<ClCompile Include="..\..\..\..\src\parser.cpp" />
143143
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp" />
144-
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind.cpp" />
144+
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind_rest.cpp" />
145+
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind_rpc.cpp" />
145146
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_106.cpp" />
146147
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_31800.cpp" />
147148
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_out_106.cpp" />
@@ -192,7 +193,8 @@
192193
<ClInclude Include="..\..\..\..\include\bitcoin\node\error.hpp" />
193194
<ClInclude Include="..\..\..\..\include\bitcoin\node\events.hpp" />
194195
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp" />
195-
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind.hpp" />
196+
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind_rest.hpp" />
197+
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind_rpc.hpp" />
196198
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\electrum.hpp" />
197199
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\explore.hpp" />
198200
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\interfaces.hpp" />
@@ -204,7 +206,8 @@
204206
<ClInclude Include="..\..\..\..\include\bitcoin\node\parse\target.hpp" />
205207
<ClInclude Include="..\..\..\..\include\bitcoin\node\parser.hpp" />
206208
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp" />
207-
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind.hpp" />
209+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind_rest.hpp" />
210+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind_rpc.hpp" />
208211
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_106.hpp" />
209212
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_31800.hpp" />
210213
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_out_106.hpp" />

builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@
123123
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp">
124124
<Filter>src\protocols</Filter>
125125
</ClCompile>
126-
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind.cpp">
126+
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind_rest.cpp">
127+
<Filter>src\protocols</Filter>
128+
</ClCompile>
129+
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind_rpc.cpp">
127130
<Filter>src\protocols</Filter>
128131
</ClCompile>
129132
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_106.cpp">
@@ -272,7 +275,10 @@
272275
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp">
273276
<Filter>include\bitcoin\node</Filter>
274277
</ClInclude>
275-
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind.hpp">
278+
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind_rest.hpp">
279+
<Filter>include\bitcoin\node\interfaces</Filter>
280+
</ClInclude>
281+
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\bitcoind_rpc.hpp">
276282
<Filter>include\bitcoin\node\interfaces</Filter>
277283
</ClInclude>
278284
<ClInclude Include="..\..\..\..\include\bitcoin\node\interfaces\electrum.hpp">
@@ -308,7 +314,10 @@
308314
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp">
309315
<Filter>include\bitcoin\node\protocols</Filter>
310316
</ClInclude>
311-
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind.hpp">
317+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind_rest.hpp">
318+
<Filter>include\bitcoin\node\protocols</Filter>
319+
</ClInclude>
320+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_bitcoind_rpc.hpp">
312321
<Filter>include\bitcoin\node\protocols</Filter>
313322
</ClInclude>
314323
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_106.hpp">

include/bitcoin/node.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
#include <bitcoin/node/chasers/chaser_transaction.hpp>
4646
#include <bitcoin/node/chasers/chaser_validate.hpp>
4747
#include <bitcoin/node/chasers/chasers.hpp>
48-
#include <bitcoin/node/interfaces/bitcoind.hpp>
48+
#include <bitcoin/node/interfaces/bitcoind_rest.hpp>
49+
#include <bitcoin/node/interfaces/bitcoind_rpc.hpp>
4950
#include <bitcoin/node/interfaces/electrum.hpp>
5051
#include <bitcoin/node/interfaces/explore.hpp>
5152
#include <bitcoin/node/interfaces/interfaces.hpp>
@@ -56,7 +57,8 @@
5657
#include <bitcoin/node/parse/query.hpp>
5758
#include <bitcoin/node/parse/target.hpp>
5859
#include <bitcoin/node/protocols/protocol.hpp>
59-
#include <bitcoin/node/protocols/protocol_bitcoind.hpp>
60+
#include <bitcoin/node/protocols/protocol_bitcoind_rest.hpp>
61+
#include <bitcoin/node/protocols/protocol_bitcoind_rpc.hpp>
6062
#include <bitcoin/node/protocols/protocol_block_in_106.hpp>
6163
#include <bitcoin/node/protocols/protocol_block_in_31800.hpp>
6264
#include <bitcoin/node/protocols/protocol_block_out_106.hpp>

include/bitcoin/node/channels/channel_ws.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class BCN_API channel_ws
8383
protected:
8484
/// Dispatch websocket buffer via derived handlers (override to handle).
8585
/// Override to handle dispatch, must invoke read_request() on complete.
86-
inline void dispatch_websocket(const network::http::flat_buffer&,
86+
inline void dispatch_ws(const network::http::flat_buffer&,
8787
size_t) NOEXCEPT override
8888
{
8989
const std::string welcome{ "Websocket libbitcoin/4.0" };
@@ -92,7 +92,7 @@ class BCN_API channel_ws
9292
// handle_send alread stops channel on ec.
9393
// One and only one handler of message must restart read loop.
9494
// In half duplex this happens only after send (ws full duplex).
95-
if (!ec) read_request();
95+
if (!ec) receive();
9696
});
9797
}
9898

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_NODE_INTERFACES_BITCOIND_REST_HPP
20+
#define LIBBITCOIN_NODE_INTERFACES_BITCOIND_REST_HPP
21+
22+
#include <bitcoin/node/define.hpp>
23+
#include <bitcoin/node/interfaces/types.hpp>
24+
25+
namespace libbitcoin {
26+
namespace node {
27+
namespace interface {
28+
29+
struct bitcoind_rest_methods
30+
{
31+
static constexpr std::tuple methods
32+
{
33+
method<"rest1">{},
34+
};
35+
36+
template <typename... Args>
37+
using subscriber = network::unsubscriber<Args...>;
38+
39+
template <size_t Index>
40+
using at = method_at<methods, Index>;
41+
42+
// Derive this from above in c++26 using reflection.
43+
using rest1 = at<0>;
44+
};
45+
46+
} // namespace interface
47+
} // namespace node
48+
} // namespace libbitcoin
49+
50+
#endif

include/bitcoin/node/interfaces/bitcoind.hpp renamed to include/bitcoin/node/interfaces/bitcoind_rpc.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
#ifndef LIBBITCOIN_NODE_INTERFACES_BITCOIND_HPP
20-
#define LIBBITCOIN_NODE_INTERFACES_BITCOIND_HPP
19+
#ifndef LIBBITCOIN_NODE_INTERFACES_BITCOIND_RPC_HPP
20+
#define LIBBITCOIN_NODE_INTERFACES_BITCOIND_RPC_HPP
2121

2222
#include <bitcoin/node/define.hpp>
2323
#include <bitcoin/node/interfaces/types.hpp>
@@ -26,7 +26,7 @@ namespace libbitcoin {
2626
namespace node {
2727
namespace interface {
2828

29-
struct bitcoind_methods
29+
struct bitcoind_rpc_methods
3030
{
3131
static constexpr std::tuple methods
3232
{

include/bitcoin/node/interfaces/interfaces.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#ifndef LIBBITCOIN_NODE_INTERFACES_HPP
2020
#define LIBBITCOIN_NODE_INTERFACES_HPP
2121

22-
#include <bitcoin/node/interfaces/bitcoind.hpp>
22+
#include <bitcoin/node/interfaces/bitcoind_rest.hpp>
23+
#include <bitcoin/node/interfaces/bitcoind_rpc.hpp>
2324
#include <bitcoin/node/interfaces/electrum.hpp>
2425
#include <bitcoin/node/interfaces/explore.hpp>
2526
#include <bitcoin/node/interfaces/stratum_v1.hpp>
@@ -30,11 +31,12 @@ namespace libbitcoin {
3031
namespace node {
3132
namespace interface {
3233

33-
using bitcoind = publish<bitcoind_methods>;
34-
using electrum = publish<electrum_methods>;
35-
using explore = publish<explore_methods>;
36-
using stratum_v1 = publish<stratum_v1_methods>;
37-
using stratum_v2 = publish<stratum_v2_methods>;
34+
using bitcoind_rest = publish<bitcoind_rest_methods>;
35+
using bitcoind_rpc = publish<bitcoind_rpc_methods>;
36+
using electrum = publish<electrum_methods>;
37+
using explore = publish<explore_methods>;
38+
using stratum_v1 = publish<stratum_v1_methods>;
39+
using stratum_v2 = publish<stratum_v2_methods>;
3840

3941
} // namespace interface
4042
} // namespace node
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BITCOIND_REST_HPP
20+
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_BITCOIND_REST_HPP
21+
22+
#include <memory>
23+
#include <bitcoin/node/channels/channels.hpp>
24+
#include <bitcoin/node/define.hpp>
25+
#include <bitcoin/node/interfaces/interfaces.hpp>
26+
#include <bitcoin/node/protocols/protocol_bitcoind_rpc.hpp>
27+
28+
namespace libbitcoin {
29+
namespace node {
30+
31+
class BCN_API protocol_bitcoind_rest
32+
: public node::protocol_bitcoind_rpc,
33+
protected network::tracker<protocol_bitcoind_rest>
34+
{
35+
public:
36+
typedef std::shared_ptr<protocol_bitcoind_rest> ptr;
37+
using rest_interface = interface::bitcoind_rest;
38+
using rest_dispatcher = network::rpc::dispatcher<rest_interface>;
39+
40+
inline protocol_bitcoind_rest(const auto& session,
41+
const network::channel::ptr& channel,
42+
const options_t& options) NOEXCEPT
43+
: node::protocol_bitcoind_rpc(session, channel, options),
44+
network::tracker<protocol_bitcoind_rest>(session->log)
45+
{
46+
}
47+
48+
/// Public start is required.
49+
void start() NOEXCEPT override;
50+
51+
protected:
52+
/// TODO: Dispatch.
53+
/// TODO: Handlers.
54+
55+
private:
56+
template <class Derived, typename Method, typename... Args>
57+
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
58+
{
59+
rest_dispatcher_.subscribe(BIND_SHARED(method, args));
60+
}
61+
62+
// This is protected by strand.
63+
rest_dispatcher rest_dispatcher_{};
64+
};
65+
66+
} // namespace node
67+
} // namespace libbitcoin
68+
69+
#endif

0 commit comments

Comments
 (0)