Skip to content

Commit 23e709f

Browse files
committed
Derive protocol_bitcoind_rest from _rpc.
1 parent d883983 commit 23e709f

File tree

6 files changed

+59
-57
lines changed

6 files changed

+59
-57
lines changed

include/bitcoin/node/protocols/protocol_bitcoind_rest.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323
#include <bitcoin/node/channels/channels.hpp>
2424
#include <bitcoin/node/define.hpp>
2525
#include <bitcoin/node/interfaces/interfaces.hpp>
26-
#include <bitcoin/node/protocols/protocol_http.hpp>
26+
#include <bitcoin/node/protocols/protocol_bitcoind_rpc.hpp>
2727

2828
namespace libbitcoin {
2929
namespace node {
3030

3131
class BCN_API protocol_bitcoind_rest
32-
: public node::protocol_http,
32+
: public node::protocol_bitcoind_rpc,
3333
protected network::tracker<protocol_bitcoind_rest>
3434
{
3535
public:
3636
typedef std::shared_ptr<protocol_bitcoind_rest> ptr;
37-
using interface = interface::bitcoind_rest;
38-
using dispatcher = network::rpc::dispatcher<interface>;
37+
using rest_interface = interface::bitcoind_rest;
38+
using rest_dispatcher = network::rpc::dispatcher<rest_interface>;
3939

4040
inline protocol_bitcoind_rest(const auto& session,
4141
const network::channel::ptr& channel,
4242
const options_t& options) NOEXCEPT
43-
: node::protocol_http(session, channel, options),
43+
: node::protocol_bitcoind_rpc(session, channel, options),
4444
network::tracker<protocol_bitcoind_rest>(session->log)
4545
{
4646
}
@@ -49,17 +49,18 @@ class BCN_API protocol_bitcoind_rest
4949
void start() NOEXCEPT override;
5050

5151
protected:
52+
/// TODO: Dispatch.
53+
/// TODO: Handlers.
54+
55+
private:
5256
template <class Derived, typename Method, typename... Args>
5357
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
5458
{
55-
dispatcher_.subscribe(BIND_SHARED(method, args));
59+
rest_dispatcher_.subscribe(BIND_SHARED(method, args));
5660
}
5761

58-
/// TODO: Handlers.
59-
60-
private:
6162
// This is protected by strand.
62-
dispatcher dispatcher_{};
63+
rest_dispatcher rest_dispatcher_{};
6364
};
6465

6566
} // namespace node

include/bitcoin/node/protocols/protocol_bitcoind_rpc.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class BCN_API protocol_bitcoind_rpc
3434
{
3535
public:
3636
typedef std::shared_ptr<protocol_bitcoind_rpc> ptr;
37-
using interface = interface::bitcoind_rpc;
38-
using dispatcher = network::rpc::dispatcher<interface>;
37+
using rpc_interface = interface::bitcoind_rpc;
38+
using rpc_dispatcher = network::rpc::dispatcher<rpc_interface>;
3939

4040
inline protocol_bitcoind_rpc(const auto& session,
4141
const network::channel::ptr& channel,
@@ -52,12 +52,6 @@ class BCN_API protocol_bitcoind_rpc
5252
using post = network::http::method::post;
5353
using options = network::http::method::options;
5454

55-
template <class Derived, typename Method, typename... Args>
56-
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
57-
{
58-
dispatcher_.subscribe(BIND_SHARED(method, args));
59-
}
60-
6155
/// Dispatch.
6256
void handle_receive_options(const code& ec,
6357
const network::http::method::options::cptr& options) NOEXCEPT override;
@@ -66,44 +60,50 @@ class BCN_API protocol_bitcoind_rpc
6660

6761
/// Handlers.
6862
bool handle_get_best_block_hash(const code& ec,
69-
interface::get_best_block_hash) NOEXCEPT;
63+
rpc_interface::get_best_block_hash) NOEXCEPT;
7064
bool handle_get_block(const code& ec,
71-
interface::get_block, const std::string&, double) NOEXCEPT;
65+
rpc_interface::get_block, const std::string&, double) NOEXCEPT;
7266
bool handle_get_block_chain_info(const code& ec,
73-
interface::get_block_chain_info) NOEXCEPT;
67+
rpc_interface::get_block_chain_info) NOEXCEPT;
7468
bool handle_get_block_count(const code& ec,
75-
interface::get_block_count) NOEXCEPT;
69+
rpc_interface::get_block_count) NOEXCEPT;
7670
bool handle_get_block_filter(const code& ec,
77-
interface::get_block_filter, const std::string&,
71+
rpc_interface::get_block_filter, const std::string&,
7872
const std::string&) NOEXCEPT;
7973
bool handle_get_block_hash(const code& ec,
80-
interface::get_block_hash, double) NOEXCEPT;
74+
rpc_interface::get_block_hash, double) NOEXCEPT;
8175
bool handle_get_block_header(const code& ec,
82-
interface::get_block_header, const std::string&, bool) NOEXCEPT;
76+
rpc_interface::get_block_header, const std::string&, bool) NOEXCEPT;
8377
bool handle_get_block_stats(const code& ec,
84-
interface::get_block_stats, const std::string&,
78+
rpc_interface::get_block_stats, const std::string&,
8579
const network::rpc::array_t&) NOEXCEPT;
8680
bool handle_get_chain_tx_stats(const code& ec,
87-
interface::get_chain_tx_stats, double, const std::string&) NOEXCEPT;
81+
rpc_interface::get_chain_tx_stats, double, const std::string&) NOEXCEPT;
8882
bool handle_get_chain_work(const code& ec,
89-
interface::get_chain_work) NOEXCEPT;
83+
rpc_interface::get_chain_work) NOEXCEPT;
9084
bool handle_get_tx_out(const code& ec,
91-
interface::get_tx_out, const std::string&, double, bool) NOEXCEPT;
85+
rpc_interface::get_tx_out, const std::string&, double, bool) NOEXCEPT;
9286
bool handle_get_tx_out_set_info(const code& ec,
93-
interface::get_tx_out_set_info) NOEXCEPT;
87+
rpc_interface::get_tx_out_set_info) NOEXCEPT;
9488
bool handle_prune_block_chain(const code& ec,
95-
interface::prune_block_chain, double) NOEXCEPT;
89+
rpc_interface::prune_block_chain, double) NOEXCEPT;
9690
bool handle_save_mem_pool(const code& ec,
97-
interface::save_mem_pool) NOEXCEPT;
91+
rpc_interface::save_mem_pool) NOEXCEPT;
9892
bool handle_scan_tx_out_set(const code& ec,
99-
interface::scan_tx_out_set, const std::string&,
93+
rpc_interface::scan_tx_out_set, const std::string&,
10094
const network::rpc::array_t&) NOEXCEPT;
10195
bool handle_verify_chain(const code& ec,
102-
interface::verify_chain, double, double) NOEXCEPT;
96+
rpc_interface::verify_chain, double, double) NOEXCEPT;
10397
bool handle_verify_tx_out_set(const code& ec,
104-
interface::verify_tx_out_set, const std::string&) NOEXCEPT;
98+
rpc_interface::verify_tx_out_set, const std::string&) NOEXCEPT;
10599

106100
private:
101+
template <class Derived, typename Method, typename... Args>
102+
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
103+
{
104+
rpc_dispatcher_.subscribe(BIND_SHARED(method, args));
105+
}
106+
107107
// Send the response.
108108
void send_json(boost::json::value&& model, size_t size_hint) NOEXCEPT;
109109

@@ -115,7 +115,7 @@ class BCN_API protocol_bitcoind_rpc
115115
////const options_t& options_;
116116

117117
// These are protected by strand.
118-
dispatcher dispatcher_{};
118+
rpc_dispatcher rpc_dispatcher_{};
119119
post::cptr post_{};
120120
};
121121

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BCN_API protocol_explore
3636
{
3737
public:
3838
typedef std::shared_ptr<protocol_explore> ptr;
39-
using interface = interface::explore;
39+
using interface = node::interface::explore;
4040
using dispatcher = network::rpc::dispatcher<interface>;
4141

4242
inline protocol_explore(const auto& session,

include/bitcoin/node/sessions/sessions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace node {
3434
/// Alias server sessions, all derived from node::session.
3535
using session_web = session_server<protocol_web>;
3636
using session_explore = session_server<protocol_explore>;
37-
using session_bitcoind = session_server<protocol_bitcoind_rpc, protocol_bitcoind_rest>;
37+
using session_bitcoind = session_server<protocol_bitcoind_rest>;
3838
using session_electrum = session_server<protocol_electrum>;
3939
using session_stratum_v1 = session_server<protocol_stratum_v1>;
4040
using session_stratum_v2 = session_server<protocol_stratum_v2>;

src/protocols/protocol_bitcoind_rest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void protocol_bitcoind_rest::start() NOEXCEPT
3636
if (started())
3737
return;
3838

39-
protocol_http::start();
39+
protocol_bitcoind_rpc::start();
4040
}
4141

4242
} // namespace node

src/protocols/protocol_bitcoind_rpc.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void protocol_bitcoind_rpc::handle_receive_post(const code& ec,
148148
// to formulate response headers, isolating handlers from http semantics.
149149
set_post(post);
150150

151-
if (const auto code = dispatcher_.notify(request))
151+
if (const auto code = rpc_dispatcher_.notify(request))
152152
stop(code);
153153
}
154154

@@ -159,7 +159,7 @@ void protocol_bitcoind_rpc::handle_receive_post(const code& ec,
159159

160160
// {"jsonrpc": "1.0", "id": "curltest", "method": "getbestblockhash", "params": []}
161161
bool protocol_bitcoind_rpc::handle_get_best_block_hash(const code& ec,
162-
interface::get_best_block_hash) NOEXCEPT
162+
rpc_interface::get_best_block_hash) NOEXCEPT
163163
{
164164
if (stopped(ec))
165165
return false;
@@ -175,109 +175,110 @@ bool protocol_bitcoind_rpc::handle_get_best_block_hash(const code& ec,
175175

176176
// method<"getblock", string_t, optional<0_u32>>{ "blockhash", "verbosity" },
177177
bool protocol_bitcoind_rpc::handle_get_block(const code& ec,
178-
interface::get_block, const std::string&, double) NOEXCEPT
178+
rpc_interface::get_block, const std::string&, double) NOEXCEPT
179179
{
180180
return !ec;
181181
}
182182

183183
bool protocol_bitcoind_rpc::handle_get_block_chain_info(const code& ec,
184-
interface::get_block_chain_info) NOEXCEPT
184+
rpc_interface::get_block_chain_info) NOEXCEPT
185185
{
186186
return !ec;
187187
}
188188

189189
bool protocol_bitcoind_rpc::handle_get_block_count(const code& ec,
190-
interface::get_block_count) NOEXCEPT
190+
rpc_interface::get_block_count) NOEXCEPT
191191
{
192192
return !ec;
193193
}
194194

195195
// method<"getblockfilter", string_t, optional<"basic"_t>>{ "blockhash", "filtertype" },
196196
bool protocol_bitcoind_rpc::handle_get_block_filter(const code& ec,
197-
interface::get_block_filter, const std::string&, const std::string&) NOEXCEPT
197+
rpc_interface::get_block_filter, const std::string&,
198+
const std::string&) NOEXCEPT
198199
{
199200
return !ec;
200201
}
201202

202203
// method<"getblockhash", number_t>{ "height" },
203204
bool protocol_bitcoind_rpc::handle_get_block_hash(const code& ec,
204-
interface::get_block_hash, network::rpc::number_t) NOEXCEPT
205+
rpc_interface::get_block_hash, network::rpc::number_t) NOEXCEPT
205206
{
206207
return !ec;
207208
}
208209

209210
// method<"getblockheader", string_t, optional<true>>{ "blockhash", "verbose" },
210211
bool protocol_bitcoind_rpc::handle_get_block_header(const code& ec,
211-
interface::get_block_header, const std::string&, bool) NOEXCEPT
212+
rpc_interface::get_block_header, const std::string&, bool) NOEXCEPT
212213
{
213214
return !ec;
214215
}
215216

216217
// method<"getblockstats", string_t, optional<empty::array>>{ "hash_or_height", "stats" },
217218
bool protocol_bitcoind_rpc::handle_get_block_stats(const code& ec,
218-
interface::get_block_stats, const std::string&,
219+
rpc_interface::get_block_stats, const std::string&,
219220
const network::rpc::array_t&) NOEXCEPT
220221
{
221222
return !ec;
222223
}
223224

224225
// method<"getchaintxstats", optional<-1_i32>, optional<""_t>>{ "nblocks", "blockhash" },
225226
bool protocol_bitcoind_rpc::handle_get_chain_tx_stats(const code& ec,
226-
interface::get_chain_tx_stats, double, const std::string&) NOEXCEPT
227+
rpc_interface::get_chain_tx_stats, double, const std::string&) NOEXCEPT
227228
{
228229
return !ec;
229230
}
230231

231232
bool protocol_bitcoind_rpc::handle_get_chain_work(const code& ec,
232-
interface::get_chain_work) NOEXCEPT
233+
rpc_interface::get_chain_work) NOEXCEPT
233234
{
234235
return !ec;
235236
}
236237

237238
// method<"gettxout", string_t, number_t, optional<true>>{ "txid", "n", "include_mempool" },
238239
bool protocol_bitcoind_rpc::handle_get_tx_out(const code& ec,
239-
interface::get_tx_out, const std::string&, double, bool) NOEXCEPT
240+
rpc_interface::get_tx_out, const std::string&, double, bool) NOEXCEPT
240241
{
241242
return !ec;
242243
}
243244

244245
bool protocol_bitcoind_rpc::handle_get_tx_out_set_info(const code& ec,
245-
interface::get_tx_out_set_info) NOEXCEPT
246+
rpc_interface::get_tx_out_set_info) NOEXCEPT
246247
{
247248
return !ec;
248249
}
249250

250251
// method<"pruneblockchain", number_t>{ "height" },
251252
bool protocol_bitcoind_rpc::handle_prune_block_chain(const code& ec,
252-
interface::prune_block_chain, double) NOEXCEPT
253+
rpc_interface::prune_block_chain, double) NOEXCEPT
253254
{
254255
return !ec;
255256
}
256257

257258
bool protocol_bitcoind_rpc::handle_save_mem_pool(const code& ec,
258-
interface::save_mem_pool) NOEXCEPT
259+
rpc_interface::save_mem_pool) NOEXCEPT
259260
{
260261
return !ec;
261262
}
262263

263264
// method<"scantxoutset", string_t, optional<empty::array>>{ "action", "scanobjects" },
264265
bool protocol_bitcoind_rpc::handle_scan_tx_out_set(const code& ec,
265-
interface::scan_tx_out_set, const std::string&,
266+
rpc_interface::scan_tx_out_set, const std::string&,
266267
const network::rpc::array_t&) NOEXCEPT
267268
{
268269
return !ec;
269270
}
270271

271272
// method<"verifychain", optional<4_u32>, optional<288_u32>>{ "checklevel", "nblocks" },
272273
bool protocol_bitcoind_rpc::handle_verify_chain(const code& ec,
273-
interface::verify_chain, double, double) NOEXCEPT
274+
rpc_interface::verify_chain, double, double) NOEXCEPT
274275
{
275276
return !ec;
276277
}
277278

278279
// method<"verifytxoutset", string_t>{ "input_verify_flag" },
279280
bool protocol_bitcoind_rpc::handle_verify_tx_out_set(const code& ec,
280-
interface::verify_tx_out_set, const std::string&) NOEXCEPT
281+
rpc_interface::verify_tx_out_set, const std::string&) NOEXCEPT
281282
{
282283
return !ec;
283284
}

0 commit comments

Comments
 (0)