Skip to content

Commit 8692acc

Browse files
committed
Add explore top query.
1 parent d41eb42 commit 8692acc

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class BCN_API protocol_explore
6060

6161
/// REST interface handlers.
6262

63+
bool handle_get_top(const code& ec, interface::top,
64+
uint8_t version, uint8_t media) NOEXCEPT;
65+
6366
bool handle_get_block(const code& ec, interface::block,
6467
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
6568
std::optional<uint32_t> height, bool witness) NOEXCEPT;

src/parse/target.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
9191
// transaction, address, inputs, and outputs are identical excluding names;
9292
// input and output are identical excluding names; block is unique.
9393
const auto target = segments[segment++];
94-
if (target == "address")
94+
if (target == "top")
95+
{
96+
method = "top";
97+
}
98+
else if (target == "address")
9599
{
96100
if (segment == segments.size())
97101
return error::missing_hash;

src/protocols/protocol_explore.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,30 @@ std::string to_hex_ptr_array(const Collection& collection, size_t size,
207207
return out;
208208
}
209209

210+
bool protocol_explore::handle_get_top(const code& ec, interface::top,
211+
uint8_t, uint8_t media) NOEXCEPT
212+
{
213+
if (stopped(ec))
214+
return false;
215+
216+
const auto height = archive().get_top_confirmed();
217+
switch (media)
218+
{
219+
case data:
220+
send_chunk(to_little_endian_size(height));
221+
return true;
222+
case text:
223+
send_text(encode_base16(to_little_endian_size(height)));
224+
return true;
225+
case json:
226+
send_json(height, two * sizeof(height));
227+
return true;
228+
}
229+
230+
send_not_found();
231+
return true;
232+
}
233+
210234
bool protocol_explore::handle_get_block(const code& ec, interface::block,
211235
uint8_t, uint8_t media, std::optional<hash_cptr> hash,
212236
std::optional<uint32_t> height, bool witness) NOEXCEPT

0 commit comments

Comments
 (0)