Skip to content

Commit 1986b75

Browse files
authored
Merge pull request #937 from evoskuil/master
Add utils for bitcoind_rpc, impl first part of handle_get_block.
2 parents 9b9f545 + af099cd commit 1986b75

File tree

7 files changed

+251
-66
lines changed

7 files changed

+251
-66
lines changed

console/executor_dumps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ void executor::dump_progress() const
152152
logger(format(BN_MEASURE_PROGRESS) %
153153
query_.get_fork() %
154154
query_.get_top_confirmed() %
155-
encode_hash(query_.get_header_key(query_.to_confirmed(query_.get_top_confirmed()))) %
155+
encode_hash(query_.get_top_confirmed_hash()) %
156156
query_.get_top_candidate() %
157-
encode_hash(query_.get_header_key(query_.to_candidate(query_.get_top_candidate()))) %
157+
encode_hash(query_.get_top_candidate_hash()) %
158158
query_.get_top_associated() %
159159
(query_.get_top_candidate() - query_.get_unassociated_count()) %
160160
query_.get_confirmed_size() %

include/bitcoin/node/error.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ enum error_t : uint8_t
118118
invalid_subcomponent,
119119
extra_segment,
120120

121-
/// server (json-rpc parse codes)
122-
unexpected_parse
121+
/// server (rpc response codes)
122+
not_found,
123+
invalid_argument,
124+
not_implemented
123125
};
124126

125127
// No current need for error_code equivalence mapping.

include/bitcoin/node/interfaces/bitcoind_rpc.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ struct bitcoind_rpc_methods
3232
{
3333
/// Blockchain methods.
3434
method<"getbestblockhash">{},
35-
method<"getblock", string_t, optional<1>>{ "blockhash", "verbosity" },
35+
method<"getblock", string_t, optional<1.0>>{ "blockhash", "verbosity" },
3636
method<"getblockchaininfo">{},
3737
method<"getblockcount">{},
3838
method<"getblockfilter", string_t, optional<"basic"_t>>{ "blockhash", "filtertype" },
3939
method<"getblockhash", number_t>{ "height" },
4040
method<"getblockheader", string_t, optional<true>>{ "blockhash", "verbose" },
4141
method<"getblockstats", string_t, optional<empty::array>>{ "hash_or_height", "stats" },
42-
method<"getchaintxstats", optional<-1>, optional<""_t>>{ "nblocks", "blockhash" },
42+
method<"getchaintxstats", optional<-1.0>, optional<""_t>>{ "nblocks", "blockhash" },
4343
method<"getchainwork">{},
4444
method<"gettxout", string_t, number_t, optional<true>>{ "txid", "n", "include_mempool" },
4545
method<"gettxoutsetinfo">{},
4646
method<"pruneblockchain", number_t>{ "height" },
4747
method<"savemempool">{},
4848
method<"scantxoutset", string_t, optional<empty::array>>{ "action", "scanobjects" },
49-
method<"verifychain", optional<4>, optional<288>>{ "checklevel", "nblocks" },
49+
method<"verifychain", optional<4.0>, optional<288.0>>{ "checklevel", "nblocks" },
5050
method<"verifytxoutset", string_t>{ "input_verify_flag" },
5151

5252
/////// Control methods.

include/bitcoin/node/protocols/protocol_bitcoind_rpc.hpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class BCN_API protocol_bitcoind_rpc
6868
bool handle_get_best_block_hash(const code& ec,
6969
rpc_interface::get_best_block_hash) NOEXCEPT;
7070
bool handle_get_block(const code& ec,
71-
rpc_interface::get_block, const std::string&, double) NOEXCEPT;
71+
rpc_interface::get_block, const std::string&,
72+
double verbosity) NOEXCEPT;
7273
bool handle_get_block_chain_info(const code& ec,
7374
rpc_interface::get_block_chain_info) NOEXCEPT;
7475
bool handle_get_block_count(const code& ec,
@@ -104,18 +105,38 @@ class BCN_API protocol_bitcoind_rpc
104105
bool handle_verify_tx_out_set(const code& ec,
105106
rpc_interface::verify_tx_out_set, const std::string&) NOEXCEPT;
106107

108+
/// Senders.
109+
void send_error(const code& ec) NOEXCEPT;
110+
void send_error(const code& ec, size_t size_hint) NOEXCEPT;
111+
void send_error(const code& ec, network::rpc::value_option&& error,
112+
size_t size_hint) NOEXCEPT;
113+
void send_text(std::string&& hexidecimal) NOEXCEPT;
114+
void send_result(network::rpc::value_option&& result,
115+
size_t size_hint) NOEXCEPT;
116+
107117
private:
108118
template <class Derived, typename Method, typename... Args>
109119
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
110120
{
111121
rpc_dispatcher_.subscribe(BIND_SHARED(method, args));
112122
}
113123

114-
// Send the response.
115-
void send_json(boost::json::value&& model, size_t size_hint) NOEXCEPT;
124+
// Senders.
125+
void send_rpc(network::rpc::response_t&& model,
126+
size_t size_hint) NOEXCEPT;
127+
128+
// Cache request for serialization (requires strand).
129+
void set_rpc_request(network::rpc::version version,
130+
const network::rpc::id_option& id,
131+
const network::http::request_cptr& request) NOEXCEPT;
132+
133+
// Obtain cached request and clear cache (requires strand).
134+
network::http::request_cptr reset_rpc_request() NOEXCEPT;
116135

117-
// This is protected by strand.
136+
// These are protected by strand.
118137
rpc_dispatcher rpc_dispatcher_{};
138+
network::rpc::version version_{};
139+
network::rpc::id_option id_{};
119140
};
120141

121142
} // namespace node

src/error.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
4949
{ duplicate_block, "duplicate block" },
5050
{ duplicate_header, "duplicate header" },
5151

52-
/// faults
52+
// faults
5353
{ protocol1, "protocol1" },
5454
{ protocol2, "protocol2" },
5555
{ header1, "header1" },
@@ -90,7 +90,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
9090
{ confirm12, "confirm12" },
9191
{ confirm13, "confirm13" },
9292

93-
/// server (url parse codes)
93+
// server (url parse codes)
9494
{ empty_path, "empty_path" },
9595
{ invalid_number, "invalid_number" },
9696
{ invalid_hash, "invalid_hash" },
@@ -107,7 +107,11 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
107107
{ invalid_component, "invalid_component" },
108108
{ invalid_subcomponent, "invalid_subcomponent" },
109109
{ extra_segment, "extra_segment" },
110-
{ unexpected_parse, "unexpected_parse" }
110+
111+
// server (rpc response codes)
112+
{ not_found, "not_found" },
113+
{ invalid_argument, "invalid_argument" },
114+
{ not_implemented, "not_implemented" }
111115
};
112116

113117
DEFINE_ERROR_T_CATEGORY(error, "node", "node code")

0 commit comments

Comments
 (0)