Skip to content

Commit 5534ee7

Browse files
committed
Extend and revise explore interface, stub new methods.
1 parent 98499c1 commit 5534ee7

File tree

4 files changed

+438
-379
lines changed

4 files changed

+438
-379
lines changed

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,41 @@ class BCN_API protocol_explore
6363
bool handle_get_block(const code& ec, interface::block,
6464
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
6565
std::optional<uint32_t> height, bool witness) NOEXCEPT;
66-
bool handle_get_header(const code& ec, interface::header,
66+
bool handle_get_block_header(const code& ec, interface::block_header,
6767
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
6868
std::optional<uint32_t> height) NOEXCEPT;
6969
bool handle_get_block_txs(const code& ec, interface::block_txs,
7070
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
7171
std::optional<uint32_t> height) NOEXCEPT;
72+
bool handle_get_block_fees(const code& ec, interface::block_fees,
73+
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
74+
std::optional<uint32_t> height) NOEXCEPT;
75+
bool handle_get_block_filter(const code& ec, interface::block_filter,
76+
uint8_t version, uint8_t media, uint8_t type,
77+
std::optional<system::hash_cptr> hash,
78+
std::optional<uint32_t> height) NOEXCEPT;
79+
bool handle_get_block_filter_hash(const code& ec,
80+
interface::block_filter_hash, uint8_t version, uint8_t media,
81+
uint8_t type, std::optional<system::hash_cptr> hash,
82+
std::optional<uint32_t> height) NOEXCEPT;
83+
bool handle_get_block_filter_header(const code& ec,
84+
interface::block_filter_header, uint8_t version, uint8_t media,
85+
uint8_t type, std::optional<system::hash_cptr> hash,
86+
std::optional<uint32_t> height) NOEXCEPT;
7287
bool handle_get_block_tx(const code& ec, interface::block_tx,
7388
uint8_t version, uint8_t media, uint32_t position,
7489
std::optional<system::hash_cptr> hash,
7590
std::optional<uint32_t> height, bool witness) NOEXCEPT;
76-
bool handle_get_transaction(const code& ec, interface::transaction,
91+
92+
bool handle_get_tx(const code& ec, interface::tx,
7793
uint8_t version, uint8_t media, const system::hash_cptr& hash,
7894
bool witness) NOEXCEPT;
7995
bool handle_get_tx_block(const code& ec, interface::tx_block,
8096
uint8_t version, uint8_t media,
8197
const system::hash_cptr& hash) NOEXCEPT;
98+
bool handle_get_tx_fee(const code& ec, interface::tx_fee,
99+
uint8_t version, uint8_t media,
100+
const system::hash_cptr& hash) NOEXCEPT;
82101

83102
bool handle_get_inputs(const code& ec, interface::inputs,
84103
uint8_t version, uint8_t media, const system::hash_cptr& hash,
@@ -112,19 +131,20 @@ class BCN_API protocol_explore
112131
bool handle_get_address(const code& ec, interface::address,
113132
uint8_t version, uint8_t media,
114133
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;
134+
bool handle_get_address_confirmed(const code& ec,
135+
interface::address_confirmed, uint8_t version, uint8_t media,
136+
const system::hash_cptr& hash) NOEXCEPT;
137+
bool handle_get_address_unconfirmed(const code& ec,
138+
interface::address_unconfirmed, uint8_t version, uint8_t media,
139+
const system::hash_cptr& hash) NOEXCEPT;
140+
bool handle_get_address_balance(const code& ec,
141+
interface::address_balance, uint8_t version, uint8_t media,
142+
const system::hash_cptr& hash) NOEXCEPT;
126143

127144
private:
145+
void inject(boost::json::value& out, std::optional<uint32_t> height,
146+
const database::header_link& link) const NOEXCEPT;
147+
128148
database::header_link to_header(const std::optional<uint32_t>& height,
129149
const std::optional<system::hash_cptr>& hash) NOEXCEPT;
130150

src/parse/target.cpp

Lines changed: 54 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,6 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
9595
method = "address";
9696
params["hash"] = hash;
9797
}
98-
else if (target == "inputs")
99-
{
100-
if (segment == segments.size())
101-
return error::missing_hash;
102-
103-
const auto hash = to_hash(segments[segment++]);
104-
if (!hash) return error::invalid_hash;
105-
106-
method = "inputs";
107-
params["hash"] = hash;
108-
}
109-
else if (target == "outputs")
110-
{
111-
if (segment == segments.size())
112-
return error::missing_hash;
113-
114-
const auto hash = to_hash(segments[segment++]);
115-
if (!hash) return error::invalid_hash;
116-
117-
method = "outputs";
118-
params["hash"] = hash;
119-
}
12098
else if (target == "input")
12199
{
122100
if (segment == segments.size())
@@ -126,28 +104,32 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
126104
if (!hash) return error::invalid_hash;
127105

128106
params["hash"] = hash;
129-
if (segment == segments.size())
130-
return error::missing_component;
131-
132-
const auto component = segments[segment++];
133-
uint32_t index{};
134-
if (!to_number(index, component))
135-
return error::invalid_number;
136-
137-
params["index"] = index;
138107
if (segment == segments.size())
139108
{
140-
method = "input";
109+
method = "inputs";
141110
}
142111
else
143112
{
144-
const auto subcomponent = segments[segment++];
145-
if (subcomponent == "script")
146-
method = "input_script";
147-
else if (subcomponent == "witness")
148-
method = "input_witness";
113+
const auto component = segments[segment++];
114+
uint32_t index{};
115+
if (!to_number(index, component))
116+
return error::invalid_number;
117+
118+
params["index"] = index;
119+
if (segment == segments.size())
120+
{
121+
method = "input";
122+
}
149123
else
150-
return error::invalid_subcomponent;
124+
{
125+
const auto subcomponent = segments[segment++];
126+
if (subcomponent == "script")
127+
method = "input_script";
128+
else if (subcomponent == "witness")
129+
method = "input_witness";
130+
else
131+
return error::invalid_subcomponent;
132+
}
151133
}
152134
}
153135
else if (target == "output")
@@ -159,33 +141,37 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
159141
if (!hash) return error::invalid_hash;
160142

161143
params["hash"] = hash;
162-
if (segment == segments.size())
163-
return error::missing_component;
164-
165-
const auto component = segments[segment++];
166-
uint32_t index{};
167-
if (!to_number(index, component))
168-
return error::invalid_number;
169-
170-
params["index"] = index;
171144
if (segment == segments.size())
172145
{
173-
method = "output";
146+
method = "outputs";
174147
}
175148
else
176149
{
177-
const auto subcomponent = segments[segment++];
178-
if (subcomponent == "script")
179-
method = "output_script";
180-
else if (subcomponent == "spender")
181-
method = "output_spender";
182-
else if (subcomponent == "spenders")
183-
method = "output_spenders";
150+
const auto component = segments[segment++];
151+
uint32_t index{};
152+
if (!to_number(index, component))
153+
return error::invalid_number;
154+
155+
params["index"] = index;
156+
if (segment == segments.size())
157+
{
158+
method = "output";
159+
}
184160
else
185-
return error::invalid_subcomponent;
161+
{
162+
const auto subcomponent = segments[segment++];
163+
if (subcomponent == "script")
164+
method = "output_script";
165+
else if (subcomponent == "spender")
166+
method = "output_spender";
167+
else if (subcomponent == "spenders")
168+
method = "output_spenders";
169+
else
170+
return error::invalid_subcomponent;
171+
}
186172
}
187173
}
188-
else if (target == "transaction")
174+
else if (target == "tx")
189175
{
190176
if (segment == segments.size())
191177
return error::missing_hash;
@@ -196,13 +182,15 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
196182
params["hash"] = hash;
197183
if (segment == segments.size())
198184
{
199-
method = "transaction";
185+
method = "tx";
200186
}
201187
else
202188
{
203189
const auto component = segments[segment++];
204190
if (component == "block")
205191
method = "tx_block";
192+
else if (component == "fee")
193+
method = "tx_fee";
206194
else
207195
return error::invalid_component;
208196
}
@@ -221,8 +209,6 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
221209
const auto hash = to_hash(segments[segment++]);
222210
if (!hash) return error::invalid_hash;
223211

224-
// nullables can be implicit.
225-
////params["height"] = null_t{};
226212
params["hash"] = hash;
227213
}
228214
else if (by == "height")
@@ -234,8 +220,6 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
234220
if (!to_number(height, segments[segment++]))
235221
return error::invalid_number;
236222

237-
// nullables can be implicit.
238-
////params["hash"] = null_t{};
239223
params["height"] = height;
240224
}
241225
else
@@ -250,7 +234,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
250234
else
251235
{
252236
const auto component = segments[segment++];
253-
if (component == "transaction")
237+
if (component == "tx")
254238
{
255239
if (segment == segments.size())
256240
return error::missing_position;
@@ -263,9 +247,11 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
263247
method = "block_tx";
264248
}
265249
else if (component == "header")
266-
method = "header";
267-
else if (component == "transactions")
250+
method = "block_header";
251+
else if (component == "txs")
268252
method = "block_txs";
253+
else if (component == "fees")
254+
method = "block_fees";
269255
else if (component == "filter")
270256
{
271257
if (segment == segments.size())
@@ -278,15 +264,15 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
278264
params["type"] = type;
279265
if (segment == segments.size())
280266
{
281-
method = "filter";
267+
method = "block_filter";
282268
}
283269
else
284270
{
285271
const auto subcomponent = segments[segment++];
286272
if (subcomponent == "hash")
287-
method = "filter_hash";
273+
method = "block_filter_hash";
288274
else if (subcomponent == "header")
289-
method = "filter_header";
275+
method = "block_filter_header";
290276
else
291277
return error::invalid_subcomponent;
292278
}

0 commit comments

Comments
 (0)