Skip to content

Commit 7b5d77a

Browse files
authored
Merge pull request #896 from evoskuil/master
Implement explore interface handlers (WIP).
2 parents dc0d60d + caa6a15 commit 7b5d77a

File tree

9 files changed

+1288
-299
lines changed

9 files changed

+1288
-299
lines changed

include/bitcoin/node/error.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ enum error_t : uint8_t
112112
missing_position,
113113
missing_id_type,
114114
invalid_id_type,
115+
missing_type_id,
115116
missing_component,
116117
invalid_component,
117118
invalid_subcomponent,

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,69 @@ class BCN_API protocol_explore
6666
bool handle_get_header(const code& ec, interface::header,
6767
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
6868
std::optional<uint32_t> height) NOEXCEPT;
69-
////bool handle_get_filter(const code& ec, interface::filter,
70-
//// uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
71-
//// std::optional<uint32_t> height) NOEXCEPT;
72-
////bool handle_get_block_txs(const code& ec, interface::block_txs,
73-
//// uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
74-
//// std::optional<uint32_t> height) NOEXCEPT;
75-
76-
////bool handle_get_block_tx(const code& ec, interface::block_tx,
77-
//// uint8_t version, uint8_t media, uint32_t position,
78-
//// std::optional<system::hash_cptr> hash,
79-
//// std::optional<uint32_t> height, bool witness) NOEXCEPT;
80-
69+
bool handle_get_block_txs(const code& ec, interface::block_txs,
70+
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
71+
std::optional<uint32_t> height) NOEXCEPT;
72+
bool handle_get_block_tx(const code& ec, interface::block_tx,
73+
uint8_t version, uint8_t media, uint32_t position,
74+
std::optional<system::hash_cptr> hash,
75+
std::optional<uint32_t> height, bool witness) NOEXCEPT;
8176
bool handle_get_transaction(const code& ec, interface::transaction,
8277
uint8_t version, uint8_t media, const system::hash_cptr& hash,
8378
bool witness) NOEXCEPT;
84-
////bool handle_get_address(const code& ec, interface::address,
85-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash) NOEXCEPT;
86-
87-
////bool handle_get_input(const code& ec, interface::input,
88-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
89-
//// std::optional<uint32_t> index) NOEXCEPT;
90-
////bool handle_get_input_script(const code& ec, interface::input_script,
91-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
92-
//// std::optional<uint32_t> index) NOEXCEPT;
93-
////bool handle_get_input_witness(const code& ec, interface::input_witness,
94-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
95-
//// std::optional<uint32_t> index) NOEXCEPT;
96-
97-
////bool handle_get_output(const code& ec, interface::output,
98-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
99-
//// std::optional<uint32_t> index) NOEXCEPT;
100-
////bool handle_get_output_script(const code& ec, interface::output_script,
101-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
102-
//// std::optional<uint32_t> index) NOEXCEPT;
103-
////bool handle_get_output_spender(const code& ec, interface::output_spender,
104-
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
105-
//// std::optional<uint32_t> index) NOEXCEPT;
79+
bool handle_get_tx_block(const code& ec, interface::tx_block,
80+
uint8_t version, uint8_t media,
81+
const system::hash_cptr& hash) NOEXCEPT;
82+
83+
bool handle_get_inputs(const code& ec, interface::inputs,
84+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
85+
bool witness) NOEXCEPT;
86+
bool handle_get_input(const code& ec, interface::input,
87+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
88+
uint32_t index, bool witness) NOEXCEPT;
89+
bool handle_get_input_script(const code& ec, interface::input_script,
90+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
91+
uint32_t index) NOEXCEPT;
92+
bool handle_get_input_witness(const code& ec, interface::input_witness,
93+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
94+
uint32_t index) NOEXCEPT;
95+
96+
bool handle_get_outputs(const code& ec, interface::outputs,
97+
uint8_t version, uint8_t media,
98+
const system::hash_cptr& hash) NOEXCEPT;
99+
bool handle_get_output(const code& ec, interface::output,
100+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
101+
uint32_t index) NOEXCEPT;
102+
bool handle_get_output_script(const code& ec, interface::output_script,
103+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
104+
uint32_t index) NOEXCEPT;
105+
bool handle_get_output_spender(const code& ec, interface::output_spender,
106+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
107+
uint32_t index) NOEXCEPT;
108+
bool handle_get_output_spenders(const code& ec, interface::output_spender,
109+
uint8_t version, uint8_t media, const system::hash_cptr& hash,
110+
uint32_t index) NOEXCEPT;
111+
112+
bool handle_get_address(const code& ec, interface::address,
113+
uint8_t version, uint8_t media,
114+
const system::hash_cptr& hash) NOEXCEPT;
115+
bool handle_get_filter(const code& ec, interface::filter, uint8_t version,
116+
uint8_t media, uint8_t type, std::optional<system::hash_cptr> hash,
117+
std::optional<uint32_t> height) NOEXCEPT;
118+
bool handle_get_filter_hash(const code& ec, interface::filter_hash,
119+
uint8_t version, uint8_t media, uint8_t type,
120+
std::optional<system::hash_cptr> hash,
121+
std::optional<uint32_t> height) NOEXCEPT;
122+
bool handle_get_filter_header(const code& ec, interface::filter_header,
123+
uint8_t version, uint8_t media, uint8_t type,
124+
std::optional<system::hash_cptr> hash,
125+
std::optional<uint32_t> height) NOEXCEPT;
106126

107127
private:
128+
void send_wire(uint8_t media, system::data_chunk&& data) NOEXCEPT;
129+
database::header_link to_header(const std::optional<uint32_t>& height,
130+
const std::optional<system::hash_cptr>& hash) NOEXCEPT;
131+
108132
dispatcher dispatcher_{};
109133
};
110134

include/bitcoin/node/protocols/protocol_html.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class BCN_API protocol_html
6464
boost::json::value&& model, size_t size_hint) NOEXCEPT;
6565
virtual void send_text(const network::http::request& request,
6666
std::string&& hexidecimal) NOEXCEPT;
67-
virtual void send_data(const network::http::request& request,
67+
virtual void send_chunk(const network::http::request& request,
6868
system::data_chunk&& bytes) NOEXCEPT;
6969
virtual void send_file(const network::http::request& request,
7070
network::http::file&& file, network::http::media_type type) NOEXCEPT;

src/error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
102102
{ missing_position, "missing_position" },
103103
{ missing_id_type, "missing_id_type" },
104104
{ invalid_id_type, "invalid_id_type" },
105+
{ missing_type_id, "missing_type_id" },
105106
{ missing_component, "missing_component" },
106107
{ invalid_component, "invalid_component" },
107108
{ invalid_subcomponent, "invalid_subcomponent" },

src/parse/target.cpp

Lines changed: 81 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
8484
// transaction, address, inputs, and outputs are identical excluding names;
8585
// input and output are identical excluding names; block is unique.
8686
const auto target = segments[segment++];
87-
if (target == "transaction")
88-
{
89-
if (segment == segments.size())
90-
return error::missing_hash;
91-
92-
const auto hash = to_hash(segments[segment++]);
93-
if (!hash) return error::invalid_hash;
94-
95-
method = "transaction";
96-
params["hash"] = hash;
97-
}
98-
else if (target == "address")
87+
if (target == "address")
9988
{
10089
if (segment == segments.size())
10190
return error::missing_hash;
@@ -114,7 +103,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
114103
const auto hash = to_hash(segments[segment++]);
115104
if (!hash) return error::invalid_hash;
116105

117-
method = "input";
106+
method = "inputs";
118107
params["hash"] = hash;
119108
}
120109
else if (target == "outputs")
@@ -125,7 +114,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
125114
const auto hash = to_hash(segments[segment++]);
126115
if (!hash) return error::invalid_hash;
127116

128-
method = "output";
117+
method = "outputs";
129118
params["hash"] = hash;
130119
}
131120
else if (target == "input")
@@ -141,36 +130,36 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
141130
return error::missing_component;
142131

143132
const auto component = segments[segment++];
144-
if (component == "scripts")
145-
{
146-
method = "input_script";
147-
}
148-
else if (component == "witnesses")
133+
////if (component == "scripts")
134+
////{
135+
//// method = "input_scripts";
136+
////}
137+
////else if (component == "witnesses")
138+
////{
139+
//// method = "input_witnesses";
140+
////}
141+
////else
142+
////{
143+
uint32_t index{};
144+
if (!to_number(index, component))
145+
return error::invalid_number;
146+
147+
params["index"] = index;
148+
if (segment == segments.size())
149149
{
150-
method = "input_witness";
150+
method = "input";
151151
}
152152
else
153153
{
154-
uint32_t index{};
155-
if (!to_number(index, component))
156-
return error::invalid_number;
157-
158-
params["index"] = index;
159-
if (segment == segments.size())
160-
{
161-
method = "input";
162-
}
154+
auto subcomponent = segments[segment++];
155+
if (subcomponent == "script")
156+
method = "input_script";
157+
else if (subcomponent == "witness")
158+
method = "input_witness";
163159
else
164-
{
165-
auto subcomponent = segments[segment++];
166-
if (subcomponent == "script")
167-
method = "input_script";
168-
else if (subcomponent == "witness")
169-
method = "input_witness";
170-
else
171-
return error::invalid_subcomponent;
172-
}
160+
return error::invalid_subcomponent;
173161
}
162+
////}
174163
}
175164
else if (target == "output")
176165
{
@@ -185,13 +174,14 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
185174
return error::missing_component;
186175

187176
const auto component = segments[segment++];
188-
if (component == "scripts")
189-
{
190-
method = "output_script";
191-
}
192-
else if (component == "spenders")
177+
////if (component == "scripts")
178+
////{
179+
//// method = "output_scripts";
180+
////}
181+
////else
182+
if (component == "spenders")
193183
{
194-
method = "output_spender";
184+
method = "output_spenders";
195185
}
196186
else
197187
{
@@ -216,6 +206,28 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
216206
}
217207
}
218208
}
209+
else if (target == "transaction")
210+
{
211+
if (segment == segments.size())
212+
return error::missing_hash;
213+
214+
const auto hash = to_hash(segments[segment++]);
215+
if (!hash) return error::invalid_hash;
216+
217+
params["hash"] = hash;
218+
if (segment == segments.size())
219+
{
220+
method = "transaction";
221+
}
222+
else
223+
{
224+
const auto component = segments[segment++];
225+
if (component == "block")
226+
method = "tx_block";
227+
else
228+
return error::invalid_component;
229+
}
230+
}
219231
else if (target == "block")
220232
{
221233
if (segment == segments.size())
@@ -273,10 +285,33 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
273285
}
274286
else if (component == "header")
275287
method = "header";
276-
else if (component == "filter")
277-
method = "filter";
278288
else if (component == "transactions")
279289
method = "block_txs";
290+
else if (component == "filter")
291+
{
292+
if (segment == segments.size())
293+
return error::missing_type_id;
294+
295+
uint8_t type{};
296+
if (!to_number(type, segments[segment++]))
297+
return error::invalid_number;
298+
299+
params["type"] = type;
300+
if (segment == segments.size())
301+
{
302+
method = "filter";
303+
}
304+
else
305+
{
306+
const auto subcomponent = segments[segment++];
307+
if (subcomponent == "hash")
308+
method = "filter_hash";
309+
else if (subcomponent == "header")
310+
method = "filter_header";
311+
else
312+
return error::invalid_subcomponent;
313+
}
314+
}
280315
else
281316
return error::invalid_component;
282317
}

0 commit comments

Comments
 (0)