Skip to content

Commit 2a6aef4

Browse files
committed
Finish handle_get_block_txs().
1 parent d79c2aa commit 2a6aef4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/protocols/protocol_explore.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919
#include <bitcoin/node/protocols/protocol_explore.hpp>
2020

21+
#include <algorithm>
2122
#include <optional>
23+
#include <ranges>
2224
#include <utility>
2325
#include <bitcoin/node/define.hpp>
2426
#include <bitcoin/node/parse/parse.hpp>
@@ -36,6 +38,7 @@ using namespace network::rpc;
3638
using namespace network::http;
3739
using namespace network::messages::peer;
3840
using namespace std::placeholders;
41+
using namespace boost::json;
3942

4043
// Avoiding namespace conflict.
4144
using object_type = network::rpc::object_t;
@@ -179,24 +182,27 @@ bool protocol_explore::handle_get_block_txs(const code& ec,
179182
if (stopped(ec))
180183
return false;
181184

182-
// TODO: iterate, naturally sorted by position.
183185
const auto& query = archive();
184186
if (const auto hashes = query.get_tx_keys(to_header(height, hash));
185187
!hashes.empty())
186188
{
189+
const auto size = hashes.size() * hash_size;
190+
187191
switch (media)
188192
{
189193
case data:
190194
case text:
191195
{
192-
const auto size = hashes.size() * hash_size;
193196
const auto data = pointer_cast<const uint8_t>(hashes.data());
194197
send_wire(media, { data, std::next(data, size) });
195198
return true;
196199
}
197200
case json:
198201
{
199-
// TODO: json array of base16 hashes.
202+
array out(hashes.size());
203+
std::ranges::transform(hashes, out.begin(),
204+
[](const auto& hash) { return encode_base16(hash); });
205+
send_json({}, out, size);
200206
return true;
201207
}
202208
}

0 commit comments

Comments
 (0)