Skip to content

Commit d5537bf

Browse files
committed
Add /transaction/[hash] explore query.
1 parent 007c92a commit d5537bf

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class BCN_API protocol_explore
7878
//// std::optional<system::hash_cptr> hash,
7979
//// std::optional<uint32_t> height, bool witness) NOEXCEPT;
8080
////
81-
////bool handle_get_transaction(const code& ec, interface::transaction,
82-
//// uint8_t version, uint8_t media, system::hash_cptr hash,
83-
//// bool witness) NOEXCEPT;
81+
bool handle_get_transaction(const code& ec, interface::transaction,
82+
uint8_t version, uint8_t media, system::hash_cptr hash,
83+
bool witness) NOEXCEPT;
8484
////bool handle_get_address(const code& ec, interface::address,
8585
//// uint8_t version, uint8_t media, system::hash_cptr hash) NOEXCEPT;
8686
////

src/protocols/protocol_explore.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void protocol_explore::start() NOEXCEPT
5555
////SUBSCRIBE_EXPLORE(handle_get_filter, _1, _2, _3, _4, _5, _6);
5656
////SUBSCRIBE_EXPLORE(handle_get_block_txs, _1, _2, _3, _4, _5, _6);
5757
////SUBSCRIBE_EXPLORE(handle_get_block_tx, _1, _2, _3, _4, _5, _6, _7, _8);
58-
////SUBSCRIBE_EXPLORE(handle_get_transaction, _1, _2, _3, _4, _5, _6);
58+
SUBSCRIBE_EXPLORE(handle_get_transaction, _1, _2, _3, _4, _5, _6);
5959
////SUBSCRIBE_EXPLORE(handle_get_address, _1, _2, _3, _4, _5);
6060
////SUBSCRIBE_EXPLORE(handle_get_input, _1, _2, _3, _4, _5, _6, _7);
6161
////SUBSCRIBE_EXPLORE(handle_get_input_script, _1, _2, _3, _4, _5, _6);
@@ -171,6 +171,41 @@ bool protocol_explore::handle_get_header(const code& ec, interface::header,
171171
return true;
172172
}
173173

174+
bool protocol_explore::handle_get_transaction(const code& ec,
175+
interface::transaction, uint8_t, uint8_t media, system::hash_cptr hash,
176+
bool witness) NOEXCEPT
177+
{
178+
BC_ASSERT(stranded());
179+
180+
if (stopped(ec))
181+
return false;
182+
183+
const auto& query = archive();
184+
185+
// TODO: there's no request.
186+
const network::http::request request{};
187+
188+
if (const auto ptr = query.get_transaction(query.to_tx(*hash), witness))
189+
{
190+
switch (media)
191+
{
192+
case to_value(media_type::application_octet_stream):
193+
send_data(request, ptr->to_data(witness));
194+
return true;
195+
case to_value(media_type::text_plain):
196+
send_text(request, encode_base16(ptr->to_data(witness)));
197+
return true;
198+
case to_value(media_type::application_json):
199+
send_json(request, value_from(ptr),
200+
ptr->serialized_size(witness));
201+
return true;
202+
}
203+
}
204+
205+
send_not_found(request);
206+
return true;
207+
}
208+
174209
BC_POP_WARNING()
175210

176211
#undef SUBSCRIBE_EXPLORE

0 commit comments

Comments
 (0)