Skip to content

Commit 33ad338

Browse files
authored
Merge pull request #942 from evoskuil/master
Adapt to network changes.
2 parents fd4be21 + bc3075a commit 33ad338

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

src/protocols/protocol_bitcoind_rpc.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ namespace node {
2929
subscribe<CLASS>(&CLASS::method, __VA_ARGS__)
3030

3131
using namespace system;
32-
using namespace network::rpc;
33-
using namespace network::http;
32+
using namespace network;
3433
using namespace network::json;
3534
using namespace std::placeholders;
3635

@@ -130,7 +129,7 @@ void protocol_bitcoind_rpc::handle_receive_post(const code& ec,
130129
}
131130

132131
// Endpoint accepts only json-rpc posts.
133-
if (!post->body().contains<in_value>())
132+
if (!post->body().contains<rpc::request>())
134133
{
135134
send_bad_request(*post);
136135
return;
@@ -139,14 +138,14 @@ void protocol_bitcoind_rpc::handle_receive_post(const code& ec,
139138
// Get the parsed json-rpc request object.
140139
// v1 or v2 both supported, batch not yet supported.
141140
// v1 null id and v2 missing id implies notification and no response.
142-
const auto& request = post->body().get<in_value>().message;
141+
const auto& message = post->body().get<rpc::request>().message;
143142

144143
// The post is saved off during asynchonous handling and used in send_json
145144
// to formulate response headers, isolating handlers from http semantics.
146-
set_rpc_request(request.jsonrpc, request.id, post);
145+
set_rpc_request(message.jsonrpc, message.id, post);
147146

148147
// Dispatch the request to subscribers.
149-
if (const auto code = rpc_dispatcher_.notify(request))
148+
if (const auto code = rpc_dispatcher_.notify(message))
150149
stop(code);
151150
}
152151

@@ -361,15 +360,15 @@ void protocol_bitcoind_rpc::send_error(const code& ec,
361360
send_error(ec, {}, size_hint);
362361
}
363362

364-
void protocol_bitcoind_rpc::send_error(const code& ec, value_option&& error,
365-
size_t size_hint) NOEXCEPT
363+
void protocol_bitcoind_rpc::send_error(const code& ec,
364+
rpc::value_option&& error, size_t size_hint) NOEXCEPT
366365
{
367366
BC_ASSERT(stranded());
368367
send_rpc(
369368
{
370369
.jsonrpc = version_,
371370
.id = id_,
372-
.error = result_t
371+
.error = rpc::result_t
373372
{
374373
.code = ec.value(),
375374
.message = ec.message(),
@@ -384,7 +383,7 @@ void protocol_bitcoind_rpc::send_text(std::string&& hexidecimal) NOEXCEPT
384383
send_result(hexidecimal, hexidecimal.size());
385384
}
386385

387-
void protocol_bitcoind_rpc::send_result(value_option&& result,
386+
void protocol_bitcoind_rpc::send_result(rpc::value_option&& result,
388387
size_t size_hint) NOEXCEPT
389388
{
390389
BC_ASSERT(stranded());
@@ -397,27 +396,28 @@ void protocol_bitcoind_rpc::send_result(value_option&& result,
397396
}
398397

399398
// private
400-
void protocol_bitcoind_rpc::send_rpc(response_t&& model,
399+
void protocol_bitcoind_rpc::send_rpc(rpc::response_t&& model,
401400
size_t size_hint) NOEXCEPT
402401
{
403402
BC_ASSERT(stranded());
403+
using namespace http;
404404
static const auto json = from_media_type(media_type::application_json);
405405
const auto request = reset_rpc_request();
406-
response response{ status::ok, request->version() };
407-
add_common_headers(response, *request);
408-
add_access_control_headers(response, *request);
409-
response.set(field::content_type, json);
410-
response.body() = out_value
406+
http::response message{ status::ok, request->version() };
407+
add_common_headers(message, *request);
408+
add_access_control_headers(message, *request);
409+
message.set(field::content_type, json);
410+
message.body() = rpc::response
411411
{
412412
{ .size_hint = size_hint }, std::move(model),
413413
};
414-
response.prepare_payload();
415-
SEND(std::move(response), handle_complete, _1, error::success);
414+
message.prepare_payload();
415+
SEND(std::move(message), handle_complete, _1, error::success);
416416
}
417417

418418
// private
419-
void protocol_bitcoind_rpc::set_rpc_request(version version,
420-
const id_option& id, const request_cptr& request) NOEXCEPT
419+
void protocol_bitcoind_rpc::set_rpc_request(rpc::version version,
420+
const rpc::id_option& id, const http::request_cptr& request) NOEXCEPT
421421
{
422422
BC_ASSERT(stranded());
423423
id_ = id;
@@ -426,11 +426,11 @@ void protocol_bitcoind_rpc::set_rpc_request(version version,
426426
}
427427

428428
// private
429-
request_cptr protocol_bitcoind_rpc::reset_rpc_request() NOEXCEPT
429+
http::request_cptr protocol_bitcoind_rpc::reset_rpc_request() NOEXCEPT
430430
{
431431
BC_ASSERT(stranded());
432432
id_.reset();
433-
version_ = version::undefined;
433+
version_ = rpc::version::undefined;
434434
return reset_request();
435435
}
436436

src/protocols/protocol_explore.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ namespace node {
3333
subscribe<CLASS>(&CLASS::method, __VA_ARGS__)
3434

3535
using namespace system;
36-
using namespace network::rpc;
37-
using namespace network::http;
36+
using namespace network;
3837
using namespace network::messages::peer;
3938
using namespace std::placeholders;
4039
using namespace boost::json;
@@ -125,11 +124,11 @@ void protocol_explore::stopping(const code& ec) NOEXCEPT
125124
// Dispatch.
126125
// ----------------------------------------------------------------------------
127126

128-
bool protocol_explore::try_dispatch_object(const request& request) NOEXCEPT
127+
bool protocol_explore::try_dispatch_object(const http::request& request) NOEXCEPT
129128
{
130129
BC_ASSERT(stranded());
131130

132-
request_t model{};
131+
rpc::request_t model{};
133132
if (LOG_ONLY(const auto ec =) explore_target(model, request.target()))
134133
{
135134
LOGA("Request parse [" << request.target() << "] " << ec.message());
@@ -151,9 +150,9 @@ bool protocol_explore::try_dispatch_object(const request& request) NOEXCEPT
151150
// Handlers.
152151
// ----------------------------------------------------------------------------
153152

154-
constexpr auto data = to_value(media_type::application_octet_stream);
155-
constexpr auto json = to_value(media_type::application_json);
156-
constexpr auto text = to_value(media_type::text_plain);
153+
constexpr auto data = to_value(http::media_type::application_octet_stream);
154+
constexpr auto json = to_value(http::media_type::application_json);
155+
constexpr auto text = to_value(http::media_type::text_plain);
157156

158157
template <typename Object, typename ...Args>
159158
data_chunk to_bin(const Object& object, size_t size, Args&&... args) NOEXCEPT

0 commit comments

Comments
 (0)