Skip to content

Commit c3a598a

Browse files
committed
Implement block/fees and tx/fee.
1 parent dabd940 commit c3a598a

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

src/protocols/protocol_explore.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,36 @@ bool protocol_explore::handle_get_block_txs(const code& ec,
311311
}
312312

313313
bool protocol_explore::handle_get_block_fees(const code& ec,
314-
interface::block_fees, uint8_t, uint8_t ,
315-
std::optional<hash_cptr> , std::optional<uint32_t> ) NOEXCEPT
314+
interface::block_fees, uint8_t, uint8_t media,
315+
std::optional<hash_cptr> hash, std::optional<uint32_t> height) NOEXCEPT
316316
{
317317
if (stopped(ec))
318318
return false;
319319

320-
// TODO.
320+
if (const auto fees = archive().get_block_fees(to_header(height, hash));
321+
fees != max_uint64)
322+
{
323+
switch (media)
324+
{
325+
case data:
326+
{
327+
send_chunk(to_little_endian_size(fees));
328+
return true;
329+
}
330+
case text:
331+
{
332+
send_text(encode_base16(to_little_endian_size(fees)));
333+
return true;
334+
}
335+
case json:
336+
{
337+
send_json(fees, two * sizeof(fees));
338+
return true;
339+
}
340+
}
341+
}
321342

322-
send_not_implemented();
343+
send_not_found();
323344
return true;
324345
}
325346

@@ -530,14 +551,36 @@ bool protocol_explore::handle_get_tx_block(const code& ec, interface::tx_block,
530551
}
531552

532553
bool protocol_explore::handle_get_tx_fee(const code& ec, interface::tx_fee,
533-
uint8_t, uint8_t , const hash_cptr& ) NOEXCEPT
554+
uint8_t, uint8_t media, const hash_cptr& hash) NOEXCEPT
534555
{
535556
if (stopped(ec))
536557
return false;
537558

538-
// TODO:
559+
const auto& query = archive();
560+
if (const auto fee = query.get_tx_fee(query.to_tx(*hash));
561+
fee != max_uint64)
562+
{
563+
switch (media)
564+
{
565+
case data:
566+
{
567+
send_chunk(to_little_endian_size(fee));
568+
return true;
569+
}
570+
case text:
571+
{
572+
send_text(encode_base16(to_little_endian_size(fee)));
573+
return true;
574+
}
575+
case json:
576+
{
577+
send_json(fee, two * sizeof(fee));
578+
return true;
579+
}
580+
}
581+
}
539582

540-
send_not_implemented();
583+
send_not_found();
541584
return true;
542585
}
543586

@@ -891,10 +934,8 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
891934
switch (media)
892935
{
893936
case data:
894-
{
895937
send_chunk({});
896938
return true;
897-
}
898939
case text:
899940
send_text(encode_base16({}));
900941
return true;

0 commit comments

Comments
 (0)